sashavor commited on
Commit
28a66b8
·
1 Parent(s): 17f86fd

having a hard time filtering the data'

Browse files
Files changed (1) hide show
  1. app.py +21 -36
app.py CHANGED
@@ -29,6 +29,12 @@ models = {
29
  "DallE": "Dall-E 2",
30
  }
31
 
 
 
 
 
 
 
32
 
33
  def make_profession_plot(num_clusters, prof_name):
34
  pre_pandas = dict(
@@ -59,33 +65,12 @@ def make_profession_plot(num_clusters, prof_name):
59
  prof_plot = df.plot(kind="bar", barmode="group")
60
  return prof_plot
61
 
62
- def make_profession_table(num_clusters, prof_name):
63
- pre_pandas = dict(
64
- [
65
- (
66
- models[mod_name],
67
- dict(
68
- (
69
- f"Cluster {k}",
70
- clusters_by_size[num_clusters][mod_name][prof_name][
71
- "cluster_proportions"
72
- ][k],
73
- )
74
- for k, v in sorted(
75
- clusters_by_size[num_clusters]["All"][prof_name][
76
- "cluster_proportions"
77
- ].items(),
78
- key=lambda x: x[1],
79
- reverse=True,
80
- )
81
- if v > 0
82
- ),
83
- )
84
- for mod_name in models
85
- ]
86
- )
87
- df = pd.DataFrame.from_dict(pre_pandas)
88
- return df
89
 
90
 
91
  with gr.Blocks() as demo:
@@ -101,7 +86,7 @@ with gr.Blocks() as demo:
101
  value=12,
102
  label="How many clusters do you want to use to represent identities?",
103
  )
104
- model_choices = gr.Dropdown(list(models.values()), value='All Models', label="Which models do you want to compare?", multiselect=True, interactive= True)
105
  profession_choices_1 = gr.Dropdown(professions, value=["CEO", "social worker"], label= "Which professions do you want to compare?", multiselect=True, interactive=True)
106
  with gr.Column(scale=3):
107
  gr.Markdown("")
@@ -114,9 +99,9 @@ with gr.Blocks() as demo:
114
  table = gr.DataFrame(
115
  label="Profession assignment per cluster"
116
  )
117
- profession_choices_1.change(
118
  make_profession_table,
119
- [num_clusters, profession_choices_1],
120
  table,
121
  queue=False,
122
  )
@@ -139,12 +124,12 @@ with gr.Blocks() as demo:
139
  plot = gr.Plot(
140
  label=f"Makeup of the cluster assignments for profession {profession_choice}"
141
  )
142
- profession_choice.change(
143
- make_profession_plot,
144
- [num_clusters, profession_choice],
145
- plot,
146
- queue=False,
147
- )
148
  with gr.Row():
149
  gr.Markdown("TODO: show examplars for cluster")
150
 
 
29
  "DallE": "Dall-E 2",
30
  }
31
 
32
+ df_models = {
33
+ "All Models": "All",
34
+ "Stable Diffusion 1.4" : "SD_14",
35
+ "Stable Diffusion 2": "SD_2",
36
+ "Dall-E 2": "DallE",
37
+ }
38
 
39
  def make_profession_plot(num_clusters, prof_name):
40
  pre_pandas = dict(
 
65
  prof_plot = df.plot(kind="bar", barmode="group")
66
  return prof_plot
67
 
68
+ def make_profession_table(num_clusters, prof_names, mod_names):
69
+ cl_dct = clusters_by_size[num_clusters]
70
+ cl_df = pd.DataFrame.from_dict(cl_dct)
71
+ print(mod_names)
72
+ mod_df = pd.DataFrame(cl_df[df_models[mod_names]])
73
+ return mod_df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
 
76
  with gr.Blocks() as demo:
 
86
  value=12,
87
  label="How many clusters do you want to use to represent identities?",
88
  )
89
+ model_choices = gr.Dropdown(["All Models", "Stable Diffusion 1.4", "Stable Diffusion 2", "Dall-E 2"], value="All Models", label="Which models do you want to compare?", interactive= True)
90
  profession_choices_1 = gr.Dropdown(professions, value=["CEO", "social worker"], label= "Which professions do you want to compare?", multiselect=True, interactive=True)
91
  with gr.Column(scale=3):
92
  gr.Markdown("")
 
99
  table = gr.DataFrame(
100
  label="Profession assignment per cluster"
101
  )
102
+ num_clusters.change(
103
  make_profession_table,
104
+ [num_clusters, profession_choices_1,model_choices],
105
  table,
106
  queue=False,
107
  )
 
124
  plot = gr.Plot(
125
  label=f"Makeup of the cluster assignments for profession {profession_choice}"
126
  )
127
+ #profession_choice.change(
128
+ # make_profession_plot,
129
+ # [num_clusters, profession_choice],
130
+ # plot,
131
+ # queue=False,
132
+ # )
133
  with gr.Row():
134
  gr.Markdown("TODO: show examplars for cluster")
135