meg-huggingface commited on
Commit
cbc358c
·
1 Parent(s): 9e9abb9

Fleshing out descriptions

Browse files
Files changed (1) hide show
  1. app.py +21 -8
app.py CHANGED
@@ -17,15 +17,26 @@ clusters_by_size = {
17
  48: clusters_48,
18
  }
19
 
 
 
 
 
 
 
 
 
 
20
  def describe_cluster(cl_dict, block="label"):
21
  labels_values = sorted(cl_dict.items(), key=operator.itemgetter(1))
22
  labels_values.reverse()
23
  total = float(sum(cl_dict.values()))
24
  lv_prcnt = list((item[0], round(item[1] * 100/total, 0)) for item in labels_values)
25
- description_string = "The most represented %s is %s, making up about %d%% of the cluster.\n" % (block, lv_prcnt[0][0], lv_prcnt[0][1])
26
- description_string += "This is followed by: "
27
- for label_value_tuple in lv_prcnt[1:]:
28
- description_string += "\n%s: %d%%" % label_value_tuple
 
 
29
  return description_string
30
 
31
  def show_cluster(cl_id, num_clusters):
@@ -60,9 +71,11 @@ def show_cluster(cl_id, num_clusters):
60
 
61
  with gr.Blocks(title=TITLE) as demo:
62
  gr.Markdown(f"# {TITLE}")
63
- gr.Markdown("## This Space lets you explore the clusters based on the data generated from [DiffusionBiasExplorer](https://huggingface.co/spaces/society-ethics/DiffusionBiasExplorer).")
 
 
64
  gr.HTML("""<span style="color:red" font-size:smaller>⚠️ DISCLAIMER: the images displayed by this tool were generated by text-to-image models and may depict offensive stereotypes or contain explicit content.</span>""")
65
- num_clusters = gr.Radio([12,24,48], value=12, labels="How many clusters do you want to make from the data?")
66
 
67
 
68
  with gr.Row():
@@ -74,10 +87,10 @@ with gr.Blocks(title=TITLE) as demo:
74
  with gr.Row():
75
  with gr.Column(scale=1):
76
  c = gr.Plot(label="How many images from each model?")
77
- c_desc = gr.Text(label="")
78
  with gr.Column(scale=1):
79
  b = gr.Plot(label="How many genders are represented?")
80
- b_desc = gr.Text(label="")
81
  with gr.Column(scale=2):
82
  d = gr.Plot(label="Which ethnicities are present?")
83
 
 
17
  48: clusters_48,
18
  }
19
 
20
+ def to_string(label):
21
+ if label == "SD_2":
22
+ label = "Stable Diffusion 2"
23
+ elif label == "SD_14":
24
+ label = "Stable Diffusion 14"
25
+ elif label == "DallE":
26
+ label = "Dall-E 2"
27
+ return label
28
+
29
  def describe_cluster(cl_dict, block="label"):
30
  labels_values = sorted(cl_dict.items(), key=operator.itemgetter(1))
31
  labels_values.reverse()
32
  total = float(sum(cl_dict.values()))
33
  lv_prcnt = list((item[0], round(item[1] * 100/total, 0)) for item in labels_values)
34
+ top_label = lv_prcnt[0][0]
35
+ description_string = "<span>The most represented %s is <b>%s</b>, making up about %d%% of the cluster.</span>" % (block, to_string(lv_prcnt[0][0]), lv_prcnt[0][1])
36
+ description_string += "<p>This is followed by: "
37
+ for lv in lv_prcnt[1:]:
38
+ description_string += "<BR/><b>%s:</b> %d%%" % (to_string(lv[0]), lv[1])
39
+ description_string += "</p>"
40
  return description_string
41
 
42
  def show_cluster(cl_id, num_clusters):
 
71
 
72
  with gr.Blocks(title=TITLE) as demo:
73
  gr.Markdown(f"# {TITLE}")
74
+ gr.Markdown("## Explore the data generated from [DiffusionBiasExplorer](https://huggingface.co/spaces/society-ethics/DiffusionBiasExplorer)!")
75
+ gr.Markdown("### This demo showcases patterns in the images generated from different prompts input to Stable Diffusion and Dalle-2 diffusion models.")
76
+ gr.Markdown("### Below, see results on how the images from different prompts cluster together.")
77
  gr.HTML("""<span style="color:red" font-size:smaller>⚠️ DISCLAIMER: the images displayed by this tool were generated by text-to-image models and may depict offensive stereotypes or contain explicit content.</span>""")
78
+ num_clusters = gr.Radio([12,24,48], value=12, label="How many clusters do you want to make from the data?")
79
 
80
 
81
  with gr.Row():
 
87
  with gr.Row():
88
  with gr.Column(scale=1):
89
  c = gr.Plot(label="How many images from each model?")
90
+ c_desc = gr.HTML(label="")
91
  with gr.Column(scale=1):
92
  b = gr.Plot(label="How many genders are represented?")
93
+ b_desc = gr.HTML(label="")
94
  with gr.Column(scale=2):
95
  d = gr.Plot(label="Which ethnicities are present?")
96