Anonymous Authors commited on
Commit
508db10
·
1 Parent(s): 54c31ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -18,9 +18,13 @@ 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:
@@ -34,6 +38,6 @@ with gr.Blocks() as demo:
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()
 
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:9])
22
  neighbor_images = neighbors["image"]
23
  neighbor_captions = [caption.split("/")[-1] for caption in neighbors["image_path"]]
24
+ Photo_portrait_of_a_Pacific_Islander_person_at_work_6.jpg
25
+ neighbor_captions = [' '.join(caption.split("_")[4:-3]) for caption in neighbor_captions]
26
+ neighbor_models = neighbors["model"]
27
+ neighbor_captions = [f"{a} {b}" for a,b in zip(neighbor_captions,neighbor_models)]
28
  return image, list(zip(neighbor_images, neighbor_captions))
29
 
30
  with gr.Blocks() as demo:
 
38
  button = gr.Button(value="Get nearest neighbors")
39
  with gr.Row():
40
  image = gr.Image()
41
+ gallery = gr.Gallery().style(grid=4)
42
  button.click(get_nearest_64, inputs=[gender, ethnicity, model, no], outputs=[image, gallery])
43
  demo.launch()