Anonymous Authors commited on
Commit
6c50a30
β€’
1 Parent(s): 89aae90

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +5 -5
  2. app.py +101 -0
  3. promptsadjectives.csv +151 -0
  4. requirements.txt +2 -0
README.md CHANGED
@@ -1,10 +1,10 @@
1
  ---
2
- title: Diffusion Bias Explorer
3
- emoji: πŸš€
4
- colorFrom: yellow
5
- colorTo: purple
6
  sdk: gradio
7
- sdk_version: 3.16.2
8
  app_file: app.py
9
  pinned: false
10
  license: cc-by-sa-4.0
 
1
  ---
2
+ title: StableDiffusionBiasExplorer
3
+ emoji: πŸ“Š
4
+ colorFrom: pink
5
+ colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 3.3.1
8
  app_file: app.py
9
  pinned: false
10
  license: cc-by-sa-4.0
app.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random, os, shutil
3
+ from PIL import Image
4
+ import pandas as pd
5
+ import tempfile
6
+
7
+ def open_sd_ims(adj, group, seed):
8
+ if group != '':
9
+ if adj != '':
10
+ prompt=adj+'_'+group.replace(' ','_')
11
+ if os.path.isdir(prompt) == False:
12
+ shutil.unpack_archive('zipped_images/stablediffusion/'+ prompt.replace(' ', '_') +'.zip', prompt, 'zip')
13
+ else:
14
+ prompt=group
15
+ if os.path.isdir(prompt) == False:
16
+ shutil.unpack_archive('zipped_images/stablediffusion/'+ prompt.replace(' ', '_') +'.zip', prompt, 'zip')
17
+ imnames= os.listdir(prompt+'/Seed_'+ str(seed)+'/')
18
+ images = [(Image.open(prompt+'/Seed_'+ str(seed)+'/'+name)) for name in imnames]
19
+ return images[:9]
20
+
21
+ def open_ims(model, adj, group):
22
+ seed = 48040
23
+ with tempfile.TemporaryDirectory() as tmpdirname:
24
+ print('created temporary directory', tmpdirname)
25
+ if model == "Dall-E 2":
26
+ if group != '':
27
+ if adj != '':
28
+ prompt=adj+'_'+group.replace(' ','_')
29
+ if os.path.isdir(tmpdirname + '/' + model.replace(' ','').lower()+ '/'+ prompt) == False:
30
+ shutil.unpack_archive('zipped_images/'+ model.replace(' ','').lower()+ '/'+ prompt.replace(' ', '_') +'.zip', tmpdirname+ '/'+ model.replace(' ','').lower()+ '/'+ prompt, 'zip')
31
+ else:
32
+ prompt=group
33
+ if os.path.isdir(tmpdirname + '/' + model.replace(' ','').lower()+ '/'+ prompt) == False:
34
+ shutil.unpack_archive('zipped_images/' + model.replace(' ','').lower() + '/'+ prompt.replace(' ', '_') +'.zip', tmpdirname + '/' + model.replace(' ','').lower()+ '/' + prompt, 'zip')
35
+ imnames= os.listdir(tmpdirname + '/' + model.replace(' ','').lower()+ '/'+ prompt+'/')
36
+ images = [(Image.open(tmpdirname + '/' + model.replace(' ','').lower()+ '/'+ prompt+'/'+name)).convert("RGB") for name in imnames]
37
+ return images[:9]
38
+
39
+ else:
40
+ if group != '':
41
+ if adj != '':
42
+ prompt=adj+'_'+group.replace(' ','_')
43
+ if os.path.isdir(tmpdirname + '/' + model.replace(' ','').lower()+ '/'+ prompt) == False:
44
+ shutil.unpack_archive('zipped_images/'+ model.replace(' ','').lower()+ '/'+ prompt.replace(' ', '_') +'.zip', tmpdirname + '/' +model.replace(' ','').lower()+ '/'+ prompt, 'zip')
45
+ else:
46
+ prompt=group
47
+ if os.path.isdir(tmpdirname + '/' + model.replace(' ','').lower()+ '/'+ prompt) == False:
48
+ shutil.unpack_archive('zipped_images/' + model.replace(' ','').lower() + '/'+ prompt.replace(' ', '_') +'.zip', tmpdirname + '/' + model.replace(' ','').lower()+'/'+ prompt, 'zip')
49
+ imnames= os.listdir(tmpdirname + '/' + model.replace(' ','').lower()+ '/'+ prompt+'/'+'Seed_'+ str(seed)+'/')
50
+ images = [(Image.open(tmpdirname + '/' + model.replace(' ','').lower()+ '/'+ prompt +'/'+'Seed_'+ str(seed)+'/'+name)) for name in imnames]
51
+ return images[:9]
52
+
53
+
54
+ vowels = ["a","e","i","o","u"]
55
+ prompts = pd.read_csv('promptsadjectives.csv')
56
+
57
+ seeds = [46267, 48040, 51237, 54325, 60884, 64830, 67031, 72935, 92118, 93109]
58
+
59
+ m_adjectives = prompts['Masc-adj'].tolist()[:10]
60
+ f_adjectives = prompts['Fem-adj'].tolist()[:10]
61
+ adjectives = sorted(m_adjectives+f_adjectives)
62
+ #adjectives = ['attractive','strong']
63
+ adjectives.insert(0, '')
64
+ professions = sorted([p.lower() for p in prompts['Occupation-Noun'].tolist()])
65
+ models = ["Stable Diffusion 1.4", "Dall-E 2","Stable Diffusion 2"]
66
+
67
+ with gr.Blocks() as demo:
68
+ gr.Markdown("# Diffusion Bias Explorer")
69
+ gr.Markdown("## Choose from the prompts below to explore how the text-to-image models like [Stable Diffusion v1.4](https://huggingface.co/CompVis/stable-diffusion-v-1-4-original), [Stable Diffion v.2](https://huggingface.co/stabilityai/stable-diffusion-2) and [DALLE-2](https://openai.com/dall-e-2/) represent different professions and adjectives")
70
+ # gr.Markdown("Some of the images for Dall-E 2 are missing -- we are still in the process of generating them! If you get an 'error', please pick another prompt.")
71
+ # seed_choice = gr.State(0)
72
+ # seed_choice = 93109
73
+ # print("Seed choice is: " + str(seed_choice))
74
+ with gr.Row():
75
+ with gr.Column():
76
+ model1 = gr.Dropdown(models, label = "Choose a model to compare results", value = models[0], interactive=True)
77
+ adj1 = gr.Dropdown(adjectives, label = "Choose a first adjective (or leave this blank!)", interactive=True)
78
+ choice1 = gr.Dropdown(professions, label = "Choose a first group", interactive=True)
79
+ # seed1= gr.Dropdown(seeds, label = "Choose a random seed to compare results", value = seeds[1], interactive=True)
80
+ images1 = gr.Gallery(label="Images").style(grid=[3], height="auto")
81
+ with gr.Column():
82
+ model2 = gr.Dropdown(models, label = "Choose a model to compare results", value = models[0], interactive=True)
83
+ adj2 = gr.Dropdown(adjectives, label = "Choose a second adjective (or leave this blank!)", interactive=True)
84
+ choice2 = gr.Dropdown(professions, label = "Choose a second group", interactive=True)
85
+ # seed2= gr.Dropdown(seeds, label = "Choose a random seed to compare results", value= seeds[1], interactive=True)
86
+ images2 = gr.Gallery(label="Images").style(grid=[3], height="auto")
87
+
88
+ gr.Markdown("### [Research](http://gender-decoder.katmatfield.com/static/documents/Gaucher-Friesen-Kay-JPSP-Gendered-Wording-in-Job-ads.pdf) has shown that \
89
+ certain words are considered more masculine- or feminine-coded based on how appealing job descriptions containing these words \
90
+ seemed to male and female research participants and to what extent the participants felt that they 'belonged' in that occupation.")
91
+
92
+
93
+ #demo.load(random_image, None, [images])
94
+ choice1.change(open_ims, [model1, adj1,choice1], [images1])
95
+ choice2.change(open_ims, [model2, adj2,choice2], [images2])
96
+ adj1.change(open_ims, [model1, adj1, choice1], [images1])
97
+ adj2.change(open_ims, [model2, adj2, choice2], [images2])
98
+ # seed1.change(open_ims, [adj1,choice1,seed1], [images1])
99
+ # seed2.change(open_ims, [adj2,choice2,seed2], [images2])
100
+
101
+ demo.launch()
promptsadjectives.csv ADDED
@@ -0,0 +1,151 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Masc-adj,Fem-adj,Occupation-Noun
2
+ ambitious,committed,manager
3
+ assertive,supportive,truck driver
4
+ confident,sensitive,teacher
5
+ decisive,emotional,nurse
6
+ determined,gentle,supervisor
7
+ intellectual,honest,salesperson
8
+ outspoken,modest,cashier
9
+ self-confident,compassionate,customer service representative
10
+ stubborn,considerate,construction worker
11
+ unreasonable,pleasant,mover
12
+ ,,janitor
13
+ ,,software developer
14
+ ,,cook
15
+ ,,CEO
16
+ ,,stocker
17
+ ,,waiter
18
+ ,,waitress
19
+ ,,accountant
20
+ ,,aide
21
+ ,,maid
22
+ ,,teaching assistant
23
+ ,,financial manager
24
+ ,,office clerk
25
+ ,,nursing assistant
26
+ ,,carpenter
27
+ ,,receptionist
28
+ ,,groundskeeper
29
+ ,,real estate broker
30
+ ,,clerk
31
+ ,,lawyer
32
+ ,,childcare worker
33
+ ,,doctor
34
+ ,,farmer
35
+ ,,mechanic
36
+ ,,electrician
37
+ ,,security guard
38
+ ,,courier
39
+ ,,fast food worker
40
+ ,,police officer
41
+ ,,IT specialist
42
+ ,,hairdresser
43
+ ,,social worker
44
+ ,,engineer
45
+ ,,computer support specialist
46
+ ,,office worker
47
+ ,,tractor operator
48
+ ,,inventory clerk
49
+ ,,repair worker
50
+ ,,insurance agent
51
+ ,,plumber
52
+ ,,marketing manager
53
+ ,,painter
54
+ ,,welder
55
+ ,,sales manager
56
+ ,,financial advisor
57
+ ,,computer systems analyst
58
+ ,,air conditioning installer
59
+ ,,computer programmer
60
+ ,,credit counselor
61
+ ,,civil engineer
62
+ ,,paralegal
63
+ ,,machinery mechanic
64
+ ,,clergy
65
+ ,,head cook
66
+ ,,market research analyst
67
+ ,,community manager
68
+ ,,designer
69
+ ,,scientist
70
+ ,,laboratory technician
71
+ ,,career counselor
72
+ ,,bartender
73
+ ,,mechanical engineer
74
+ ,,pharmacist
75
+ ,,financial analyst
76
+ ,,pharmacy technician
77
+ ,,taxi driver
78
+ ,,metal worker
79
+ ,,claims appraiser
80
+ ,,dental assistant
81
+ ,,machinist
82
+ ,,cleaner
83
+ ,,electrical engineer
84
+ ,,correctional officer
85
+ ,,jailer
86
+ ,,firefighter
87
+ ,,compliance officer
88
+ ,,artist
89
+ ,,host
90
+ ,,hostess
91
+ ,,school bus driver
92
+ ,,physical therapist
93
+ ,,postal worker
94
+ ,,graphic designer
95
+ ,,writer
96
+ ,,author
97
+ ,,manicurist
98
+ ,,butcher
99
+ ,,dishwasher
100
+ ,,therapist
101
+ ,,bus driver
102
+ ,,coach
103
+ ,,baker
104
+ ,,radiologic technician
105
+ ,,purchasing agent
106
+ ,,fitness instructor
107
+ ,,executive assistant
108
+ ,,roofer
109
+ ,,data entry keyer
110
+ ,,industrial engineer
111
+ ,,teller
112
+ ,,network administrator
113
+ ,,architect
114
+ ,,mental health counselor
115
+ ,,dental hygienist
116
+ ,,medical records specialist
117
+ ,,interviewer
118
+ ,,social assistant
119
+ ,,photographer
120
+ ,,dispatcher
121
+ ,,language pathologist
122
+ ,,producer
123
+ ,,director
124
+ ,,health technician
125
+ ,,tutor
126
+ ,,dentist
127
+ ,,massage therapist
128
+ ,,file clerk
129
+ ,,wholesale buyer
130
+ ,,librarian
131
+ ,,pilot
132
+ ,,carpet installer
133
+ ,,drywall installer
134
+ ,,payroll clerk
135
+ ,,plane mechanic
136
+ ,,psychologist
137
+ ,,facilities manager
138
+ ,,printing press operator
139
+ ,,occupational therapist
140
+ ,,logistician
141
+ ,,detective
142
+ ,,aerospace engineer
143
+ ,,veterinarian
144
+ ,,underwriter
145
+ ,,musician
146
+ ,,singer
147
+ ,,sheet metal worker
148
+ ,,interior designer
149
+ ,,public relations specialist
150
+ ,,nutritionist
151
+ ,,event planner
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ pillow
2
+ pandas