sashavor commited on
Commit
71da98f
1 Parent(s): bc1b23e

updating instructions

Browse files
Files changed (1) hide show
  1. app.py +27 -15
app.py CHANGED
@@ -1,39 +1,51 @@
1
  import gradio as gr
2
  import random, os
3
  from PIL import Image
 
4
 
5
- def open_ims(choice):
6
- dirname='images/'+choice.replace(' ','_')+'/Seed_'+ str(seed_choice)+'/'
 
 
 
 
 
 
 
 
 
7
  imnames= os.listdir(dirname)
8
  images = [(Image.open(dirname+name)) for name in imnames]
9
  return images[:9]
10
 
11
- def random_image():
12
- cat = random.choice(categories)
13
- dirname = 'images/'+cat.replace(' ','_')+'/Seed_'+str(seed_choice)+'/'
14
- imnames = os.listdir(dirname)
15
- images = [(Image.open(dirname+name)) for name in imnames]
16
- return images[:9]
17
 
18
- categories=os.listdir('images/')
19
- categories = [c.replace('_',' ') for c in categories]
 
20
  seeds = [46267, 48040, 51237, 54325, 60884, 64830, 67031, 72935, 92118, 93109]
21
 
 
 
 
 
 
22
  with gr.Blocks() as demo:
23
  gr.Markdown("# Stable Diffusion Explorer")
24
- gr.Markdown("## Choose from the prompts below to explore the way in which the Stable Diffusion model encodes societal biases")
25
  seed_choice = gr.State(0)
26
  seed_choice = random.choice(seeds)
27
  print("Seed choice is: " + str(seed_choice))
28
  with gr.Row():
29
  with gr.Column():
30
- choice1 = gr.Dropdown(categories, label = "Choose a first category", interactive=True)
 
31
  images1 = gr.Gallery(label="Images").style(grid=[3], height="auto")
32
  with gr.Column():
33
- choice2 = gr.Dropdown(categories, label = "Choose a second category", interactive=True)
 
34
  images2 = gr.Gallery(label="Images").style(grid=[3], height="auto")
35
 
36
  #demo.load(random_image, None, [images])
37
- choice1.change(open_ims, [choice1], [images1])
38
- choice2.change(open_ims, [choice2], [images2])
39
  demo.launch()
 
1
  import gradio as gr
2
  import random, os
3
  from PIL import Image
4
+ import pandas as pd
5
 
6
+ def open_ims(adj, group):
7
+ if adj != '':
8
+ if adj[0] in vowels:
9
+ dirname='images/'+'Photo_portrait_of_an_'+ adj+'_'+ group.replace(' ','_')+'/Seed_'+ str(seed_choice)+'/'
10
+ else:
11
+ dirname='images/'+'Photo_portrait_of_a_'+ adj+ '_'+ group.replace(' ','_')+'/Seed_'+ str(seed_choice)+'/'
12
+ else:
13
+ if group[0] in vowels:
14
+ dirname='images/'+'Photo_portrait_of_an_'+ group.replace(' ','_')+'/Seed_'+ str(seed_choice)+'/'
15
+ else:
16
+ dirname='images/'+'Photo_portrait_of_a_'+ group.replace(' ','_')+'/Seed_'+ str(seed_choice)+'/'
17
  imnames= os.listdir(dirname)
18
  images = [(Image.open(dirname+name)) for name in imnames]
19
  return images[:9]
20
 
 
 
 
 
 
 
21
 
22
+ vowels = ["a","e","i","o","u"]
23
+ prompts = pd.read_csv('shortprompts.csv')
24
+
25
  seeds = [46267, 48040, 51237, 54325, 60884, 64830, 67031, 72935, 92118, 93109]
26
 
27
+ #adjectives = prompts['Descriptive-Adj'].tolist()[:10]
28
+ adjectives = ['attractive','strong']
29
+ adjectives.append('')
30
+ professions = [p.lower() for p in prompts['Occupation-Noun'].tolist()]
31
+
32
  with gr.Blocks() as demo:
33
  gr.Markdown("# Stable Diffusion Explorer")
34
+ gr.Markdown("## Choose from the prompts below to explore how the Stable Diffusion model represents different professions")
35
  seed_choice = gr.State(0)
36
  seed_choice = random.choice(seeds)
37
  print("Seed choice is: " + str(seed_choice))
38
  with gr.Row():
39
  with gr.Column():
40
+ adj1 = gr.Dropdown(adjectives, label = "Choose a first adjective (or leave this blank!)", interactive=True)
41
+ choice1 = gr.Dropdown(professions, label = "Choose a first group", interactive=True)
42
  images1 = gr.Gallery(label="Images").style(grid=[3], height="auto")
43
  with gr.Column():
44
+ adj2 = gr.Dropdown(adjectives, label = "Choose a second adjective (or leave this blank!)", interactive=True)
45
+ choice2 = gr.Dropdown(professions, label = "Choose a second group", interactive=True)
46
  images2 = gr.Gallery(label="Images").style(grid=[3], height="auto")
47
 
48
  #demo.load(random_image, None, [images])
49
+ choice1.change(open_ims, [adj1,choice1], [images1])
50
+ choice2.change(open_ims, [adj2,choice2], [images2])
51
  demo.launch()