Anonymous Authors commited on
Commit
54c31ba
β€’
1 Parent(s): 0256f9d

Upload 4 files

Browse files
Files changed (4) hide show
  1. README.md +4 -3
  2. app.py +39 -0
  3. indexes/knn_10752_65.npy +3 -0
  4. requirements.txt +3 -0
README.md CHANGED
@@ -1,12 +1,13 @@
1
  ---
2
  title: Identities Knn
3
- emoji: πŸ”₯
4
  colorFrom: green
5
- colorTo: gray
6
  sdk: gradio
7
- sdk_version: 3.17.0
8
  app_file: app.py
9
  pinned: false
 
10
  ---
11
 
12
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
  title: Identities Knn
3
+ emoji: πŸ“‰
4
  colorFrom: green
5
+ colorTo: red
6
  sdk: gradio
7
+ sdk_version: 3.16.2
8
  app_file: app.py
9
  pinned: false
10
+ license: apache-2.0
11
  ---
12
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from datasets import load_dataset
3
+ import numpy as np
4
+
5
+
6
+ gender_labels = ['man', 'non-binary', 'woman', 'no_gender_specified', ]
7
+
8
+ ethnicity_labels = ['African-American', 'American_Indian', 'Black', 'Caucasian', 'East_Asian',
9
+ 'First_Nations', 'Hispanic', 'Indigenous_American', 'Latino', 'Latinx',
10
+ 'Multiracial', 'Native_American', 'Pacific_Islander', 'South_Asian',
11
+ 'Southeast_Asian', 'White', 'no_ethnicity_specified']
12
+ models = ['DallE', 'SD_14', 'SD_2']
13
+ nos = [1,2,3,4,5,6,7,8,9,10]
14
+ index = np.load("indexes/knn_10752_65.npy")
15
+ ds = load_dataset("tti-bias/identities", split="train")
16
+
17
+ def get_nearest_64(gender, ethnicity, model, no):
18
+ df = ds.remove_columns(["image","image_path"]).to_pandas()
19
+ ix = df.loc[(df['ethnicity'] == ethnicity) & (df['gender'] == gender) & (df['no'] == no) & (df['model'] == model)].index[0]
20
+ image = ds.select([index[ix][0]])["image"][0]
21
+ neighbors = ds.select(index[ix][1:])
22
+ neighbor_images = neighbors["image"]
23
+ neighbor_captions = [caption.split("/")[-1] for caption in neighbors["image_path"]]
24
+ return image, list(zip(neighbor_images, neighbor_captions))
25
+
26
+ with gr.Blocks() as demo:
27
+ with gr.Row():
28
+ with gr.Column():
29
+ gender = gr.Radio(gender_labels, label="Gender label")
30
+ model = gr.Radio(models, label="Model")
31
+ no = gr.Radio(nos, label="Image number")
32
+ with gr.Column():
33
+ ethnicity = gr.Radio(ethnicity_labels, label="Ethnicity label")
34
+ button = gr.Button(value="Get nearest neighbors")
35
+ with gr.Row():
36
+ image = gr.Image()
37
+ gallery = gr.Gallery().style(grid=8)
38
+ button.click(get_nearest_64, inputs=[gender, ethnicity, model, no], outputs=[image, gallery])
39
+ demo.launch()
indexes/knn_10752_65.npy ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:47eb9dbb1b403c0533e09336bd592125a0db83f2c122ca267bbc05fc877d05c1
3
+ size 530528
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ datasets[vision]
2
+ numpy
3
+ imutils