sasha HF staff commited on
Commit
f53a084
1 Parent(s): d621d24

initial commit

Browse files
Files changed (3) hide show
  1. app.py +56 -0
  2. promptsadjectives.csv +151 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from PIL import Image
2
+ import os,csv
3
+ import pandas as pd
4
+ import numpy as np
5
+ import gradio as gr
6
+
7
+ prompts=pd.read_csv('promptsadjectives.csv')
8
+ masc = prompts['Masc-adj'][:10].tolist()
9
+ fem = prompts['Fem-adj'][:10].tolist()
10
+ adjectives = sorted(masc+fem)
11
+ adjectives.insert(0, '')
12
+ occupations = prompts['Occupation-Noun'][:150].tolist()
13
+
14
+
15
+ def get_averages(adj, profession):
16
+ if adj != "":
17
+ prompt = (adj + ' ' + profession).replace(' ','_')
18
+ else:
19
+ prompt = profession.replace(' ','_')
20
+ #TODO: fix upper/lowercase error
21
+ sd14_average = 'facer_faces/SDv14/'+prompt+'.png'
22
+ if os.path.isfile(sd14_average) == False:
23
+ sd14_average = 'facer_faces/blank.png'
24
+ sdv2_average = 'facer_faces/SDv2/'+prompt+'.png'
25
+ if os.path.isfile(sdv2_average) == False:
26
+ sdv2_average = 'facer_faces/blank.png'
27
+ dalle_average = 'facer_faces/dalle2/'+prompt.lower()+'.png'
28
+ if os.path.isfile(dalle_average) == False:
29
+ dalle_average = 'facer_faces/blank.png'
30
+
31
+ return((Image.open(sd14_average), "Stable Diffusion v 1.4"), (Image.open(sdv2_average), "Stable Diffusion v 2"), (Image.open(dalle_average), "Dall-E 2"))
32
+
33
+
34
+ with gr.Blocks() as demo:
35
+
36
+ gr.Markdown("# Text-to-Image Diffusion Model Average Faces")
37
+ gr.Markdown("### We ran 150 professions through 3 diffusion models to examine what they generate.")
38
+ gr.Markdown("#### Choose one of the professions and adjectives and see the average face generated by each model.")
39
+ with gr.Row():
40
+
41
+ with gr.Column():
42
+ adj = gr.Dropdown(sorted(adjectives, key=str.casefold), value = '',label = "Choose an adjective", interactive= True)
43
+ prof = gr.Dropdown(sorted(occupations, key=str.casefold), value = '', label = "Choose a profession", interactive= True)
44
+ btn = gr.Button("Get average faces!")
45
+ with gr.Column():
46
+ gallery = gr.Gallery(
47
+ label="Average images", show_label=False, elem_id="gallery"
48
+ ).style(grid=[0,3], height="auto")
49
+ gr.Markdown("The three models are: Stable Diffusion v.1.4, Stable Diffusion v.2, and Dall-E 2.")
50
+ gr.Markdown("If you see a black square above, we weren't able to compute an average face for this profession, sorry!")
51
+
52
+
53
+ btn.click(fn=get_averages, inputs=[adj,prof], outputs=gallery)
54
+
55
+ demo.launch(share=True)
56
+
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,4 @@
 
 
 
 
 
1
+ PIL
2
+ pandas
3
+ numpy
4
+ gradio