Spaces:
Runtime error
Runtime error
Anonymous Authors
commited on
Commit
•
9b94184
1
Parent(s):
c4e717c
Update app.py
Browse files
app.py
CHANGED
@@ -1,23 +1,39 @@
|
|
1 |
import gradio as gr
|
2 |
-
from datasets import
|
3 |
import numpy as np
|
4 |
|
5 |
|
6 |
-
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
models = ['DallE', 'SD_14', 'SD_2']
|
13 |
nos = [1,2,3,4,5,6,7,8,9,10]
|
14 |
-
indexes = [768, 1536, 10752]
|
15 |
-
ds = load_dataset("tti-bias/identities", split="train")
|
16 |
|
17 |
-
|
|
|
|
|
|
|
18 |
df = ds.remove_columns(["image","image_path"]).to_pandas()
|
19 |
index = np.load(f"indexes/knn_{index}_65.npy")
|
20 |
-
ix = df.loc[(df['
|
21 |
image = ds.select([index[ix][0]])["image"][0]
|
22 |
neighbors = ds.select(index[ix][1:25])
|
23 |
neighbor_images = neighbors["image"]
|
@@ -34,14 +50,12 @@ with gr.Blocks() as demo:
|
|
34 |
with gr.Row():
|
35 |
with gr.Column():
|
36 |
model = gr.Radio(models, label="Model")
|
37 |
-
|
38 |
-
gender = gr.Radio(gender_labels, label="Gender label")
|
39 |
with gr.Column():
|
40 |
-
|
41 |
-
no = gr.Radio(nos, label="Image number")
|
42 |
button = gr.Button(value="Get nearest neighbors")
|
43 |
with gr.Row():
|
44 |
image = gr.Image()
|
45 |
gallery = gr.Gallery().style(grid=4)
|
46 |
-
button.click(
|
47 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from datasets import load_from_disk
|
3 |
import numpy as np
|
4 |
|
5 |
|
6 |
+
adjectives = ['ambitious', 'assertive', 'committed', 'compassionate', 'confident', 'considerate', 'decisive', 'determined', 'emotional', 'gentle',
|
7 |
+
'honest', 'intellectual', 'modest', 'no_adjective', 'outspoken', 'pleasant', 'self-confident', 'sensitive', 'stubborn', 'supportive', 'unreasonable']
|
8 |
|
9 |
+
professions = ['CEO', 'IT_specialist', 'accountant', 'aerospace_engineer', 'aide', 'air_conditioning_installer', 'architect', 'artist', 'author',
|
10 |
+
'baker', 'bartender', 'bus_driver', 'butcher', 'career_counselor', 'carpenter', 'carpet_installer', 'cashier', 'childcare_worker',
|
11 |
+
'civil_engineer', 'claims_appraiser', 'cleaner', 'clergy', 'clerk', 'coach', 'community_manager', 'compliance_officer', 'computer_programmer',
|
12 |
+
'computer_support_specialist', 'computer_systems_analyst', 'construction_worker', 'cook', 'correctional_officer', 'courier', 'credit_counselor',
|
13 |
+
'customer_service_representative', 'data_entry_keyer', 'dental_assistant', 'dental_hygienist', 'dentist', 'designer', 'detective', 'director',
|
14 |
+
'dishwasher', 'dispatcher', 'doctor', 'drywall_installer', 'electrical_engineer', 'electrician', 'engineer', 'event_planner', 'executive_assistant',
|
15 |
+
'facilities_manager', 'farmer', 'fast_food_worker', 'file_clerk', 'financial_advisor', 'financial_analyst', 'financial_manager', 'firefighter',
|
16 |
+
'fitness_instructor', 'graphic_designer', 'groundskeeper', 'hairdresser', 'head_cook', 'health_technician', 'host', 'hostess', 'industrial_engineer',
|
17 |
+
'insurance_agent', 'interior_designer', 'interviewer', 'inventory_clerk', 'jailer', 'janitor', 'laboratory_technician', 'language_pathologist',
|
18 |
+
'lawyer', 'librarian', 'logistician', 'machinery_mechanic', 'machinist', 'maid', 'manager', 'manicurist', 'market_research_analyst',
|
19 |
+
'marketing_manager', 'massage_therapist', 'mechanic', 'mechanical_engineer', 'medical_records_specialist', 'mental_health_counselor',
|
20 |
+
'metal_worker', 'mover', 'musician', 'network_administrator', 'nurse', 'nursing_assistant', 'nutritionist', 'occupational_therapist',
|
21 |
+
'office_clerk', 'office_worker', 'painter', 'paralegal', 'payroll_clerk', 'pharmacist', 'pharmacy_technician', 'photographer',
|
22 |
+
'physical_therapist', 'pilot', 'plane_mechanic', 'plumber', 'police_officer', 'postal_worker', 'printing_press_operator', 'producer',
|
23 |
+
'psychologist', 'public_relations_specialist', 'purchasing_agent', 'radiologic_technician', 'real_estate_broker', 'receptionist',
|
24 |
+
'repair_worker', 'roofer', 'sales_manager', 'salesperson', 'school_bus_driver', 'scientist', 'security_guard', 'sheet_metal_worker', 'singer',
|
25 |
+
'social_assistant', 'social_worker', 'software_developer', 'stocker', 'supervisor', 'taxi_driver', 'teacher', 'teaching_assistant', 'teller',
|
26 |
+
'therapist', 'tractor_operator', 'truck_driver', 'tutor', 'underwriter', 'veterinarian', 'waiter', 'waitress', 'welder', 'wholesale_buyer', 'writer']
|
27 |
models = ['DallE', 'SD_14', 'SD_2']
|
28 |
nos = [1,2,3,4,5,6,7,8,9,10]
|
|
|
|
|
29 |
|
30 |
+
ds = load_from_disk("jobs")
|
31 |
+
|
32 |
+
def get_nearest(adjective, profession, model, no):
|
33 |
+
index=768
|
34 |
df = ds.remove_columns(["image","image_path"]).to_pandas()
|
35 |
index = np.load(f"indexes/knn_{index}_65.npy")
|
36 |
+
ix = df.loc[(df['adjective'] == adjective) & (df['profession'] == profession) & (df['no'] == no) & (df['model'] == model)].index[0]
|
37 |
image = ds.select([index[ix][0]])["image"][0]
|
38 |
neighbors = ds.select(index[ix][1:25])
|
39 |
neighbor_images = neighbors["image"]
|
|
|
50 |
with gr.Row():
|
51 |
with gr.Column():
|
52 |
model = gr.Radio(models, label="Model")
|
53 |
+
adjective = gr.Radio(adjectives, label="Adjective")
|
|
|
54 |
with gr.Column():
|
55 |
+
profession = gr.Dropdown(professions, label="Profession")
|
|
|
56 |
button = gr.Button(value="Get nearest neighbors")
|
57 |
with gr.Row():
|
58 |
image = gr.Image()
|
59 |
gallery = gr.Gallery().style(grid=4)
|
60 |
+
button.click(get_nearest, inputs=[adjective, profession, model, no], outputs=[image, gallery])
|
61 |
demo.launch()
|