meg-huggingface commited on
Commit
8010f37
·
2 Parent(s): 03394af 5ba8c8e
Files changed (2) hide show
  1. app.py +22 -7
  2. requirements.txt +1 -0
app.py CHANGED
@@ -2,6 +2,8 @@ import json
2
  import gradio as gr
3
  import os
4
  from PIL import Image
 
 
5
 
6
  TITLE = "Diffusion Faces Cluster Explorer"
7
  clusters_12 = json.load(open("clusters/id_all_blip_clusters_12.json"))
@@ -23,11 +25,23 @@ def show_cluster(cl_id, num_clusters):
23
  images = []
24
  for i in range(6):
25
  img_path = "/".join([st.replace("/", "") for st in cl_dct['img_path_list'][i].split("//")][3:])
26
- images.append((Image.open(os.path.join("identities-images", img_path)), "_".join([img_path.split("/")[0], img_path.split("/")[-1]])))
 
 
 
 
 
 
 
 
 
 
 
 
27
  return (len(cl_dct['img_path_list']),
28
- dict(cl_dct["labels_gender"]),
29
- dict(cl_dct["labels_model"]),
30
- dict(cl_dct["labels_ethnicity"]),
31
  images)
32
 
33
  with gr.Blocks(title=TITLE) as demo:
@@ -42,9 +56,10 @@ with gr.Blocks(title=TITLE) as demo:
42
  with gr.Column():
43
  cluster_id = gr.Slider(minimum=0, maximum=num_clusters.value-1, step=1, value=0, label="Click to move between clusters")
44
  a = gr.Text(label="Number of images")
45
- c = gr.Text(label="Model makeup of cluster")
46
- b = gr.Text(label="Gender label makeup of cluster")
47
- d = gr.Text(label="Ethnicity label makeup of cluster")
 
48
  demo.load(fn=show_cluster, inputs=[cluster_id, num_clusters], outputs=[a,b,c,d, gallery])
49
  num_clusters.change(fn=show_cluster, inputs=[cluster_id, num_clusters], outputs=[a,b,c,d, gallery])
50
  cluster_id.change(fn=show_cluster, inputs=[cluster_id, num_clusters], outputs=[a,b,c,d, gallery])
 
2
  import gradio as gr
3
  import os
4
  from PIL import Image
5
+ import plotly.graph_objects as go
6
+ import plotly.express as px
7
 
8
  TITLE = "Diffusion Faces Cluster Explorer"
9
  clusters_12 = json.load(open("clusters/id_all_blip_clusters_12.json"))
 
25
  images = []
26
  for i in range(6):
27
  img_path = "/".join([st.replace("/", "") for st in cl_dct['img_path_list'][i].split("//")][3:])
28
+ images.append((Image.open(os.path.join("identities-images", img_path)), "_".join([img_path.split("/")[0], img_path.split("/")[-1]]).replace('Photo_portrait_of_an_','').replace('Photo_portrait_of_a_','').replace('SD_v2_random_seeds_identity_','(SD v.2) ').replace('dataset-identities-dalle2_','(Dall-E 2) ').replace('SD_v1.4_random_seeds_identity_','(SD v.1.4) ').replace('_',' ')))
29
+ model_fig = go.Figure()
30
+ model_fig.add_trace(go.Bar(x=list(dict(cl_dct["labels_model"]).keys()),
31
+ y=list(dict(cl_dct["labels_model"]).values()),
32
+ marker_color=px.colors.qualitative.G10))
33
+ gender_fig = go.Figure()
34
+ gender_fig.add_trace(go.Bar(x=list(dict(cl_dct["labels_gender"]).keys()),
35
+ y=list(dict(cl_dct["labels_gender"]).values()),
36
+ marker_color=px.colors.qualitative.G10))
37
+ ethnicity_fig = go.Figure()
38
+ ethnicity_fig.add_trace(go.Bar(x=list(dict(cl_dct["labels_ethnicity"]).keys()),
39
+ y=list(dict(cl_dct["labels_ethnicity"]).values()),
40
+ marker_color=px.colors.qualitative.G10))
41
  return (len(cl_dct['img_path_list']),
42
+ gender_fig,
43
+ model_fig,
44
+ ethnicity_fig,
45
  images)
46
 
47
  with gr.Blocks(title=TITLE) as demo:
 
56
  with gr.Column():
57
  cluster_id = gr.Slider(minimum=0, maximum=num_clusters.value-1, step=1, value=0, label="Click to move between clusters")
58
  a = gr.Text(label="Number of images")
59
+ with gr.Row():
60
+ c = gr.Plot(label="Model makeup of cluster")
61
+ b = gr.Plot(label="Gender label makeup of cluster")
62
+ d = gr.Plot(label="Ethnicity label makeup of cluster")
63
  demo.load(fn=show_cluster, inputs=[cluster_id, num_clusters], outputs=[a,b,c,d, gallery])
64
  num_clusters.change(fn=show_cluster, inputs=[cluster_id, num_clusters], outputs=[a,b,c,d, gallery])
65
  cluster_id.change(fn=show_cluster, inputs=[cluster_id, num_clusters], outputs=[a,b,c,d, gallery])
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  datasets[vision]
2
  gradio
 
 
1
  datasets[vision]
2
  gradio
3
+ plotly