sashavor commited on
Commit
17f86fd
β€’
1 Parent(s): fd5092c

trying to make things work

Browse files
Files changed (1) hide show
  1. app.py +45 -11
app.py CHANGED
@@ -30,7 +30,7 @@ models = {
30
  }
31
 
32
 
33
- def make_profession_table(num_clusters, prof_name):
34
  pre_pandas = dict(
35
  [
36
  (
@@ -59,10 +59,34 @@ def make_profession_table(num_clusters, prof_name):
59
  prof_plot = df.plot(kind="bar", barmode="group")
60
  return prof_plot
61
 
62
- def gen_df(num_clusters,model,profs):
63
- if num_clusters == 12:
64
- print(clusters_12.head())
65
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  with gr.Blocks() as demo:
68
  gr.Markdown("# πŸ€— Diffusion Cluster Explorer")
@@ -70,22 +94,32 @@ with gr.Blocks() as demo:
70
  with gr.Tab("Professions Overview"):
71
  gr.Markdown("TODO")
72
  with gr.Row():
73
- with gr.Column():
74
- gr.Markdown("Select your settings below:")
75
  num_clusters = gr.Radio(
76
  [12, 24, 48],
77
  value=12,
78
  label="How many clusters do you want to use to represent identities?",
79
  )
80
- with gr.Column():
 
 
81
  gr.Markdown("")
82
  order = gr.Dropdown(
83
  ["entropy", "cluster/sum of clusters"],
84
- value="entryopy",
85
  label="Order rows by:",
86
  interactive=True,
87
  )
88
- # with gr.Row():
 
 
 
 
 
 
 
 
89
 
90
  # with gr.Accordion("Tag Frequencies", open=False):
91
 
@@ -106,7 +140,7 @@ with gr.Blocks() as demo:
106
  label=f"Makeup of the cluster assignments for profession {profession_choice}"
107
  )
108
  profession_choice.change(
109
- make_profession_table,
110
  [num_clusters, profession_choice],
111
  plot,
112
  queue=False,
 
30
  }
31
 
32
 
33
+ def make_profession_plot(num_clusters, prof_name):
34
  pre_pandas = dict(
35
  [
36
  (
 
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:
92
  gr.Markdown("# πŸ€— Diffusion Cluster Explorer")
 
94
  with gr.Tab("Professions Overview"):
95
  gr.Markdown("TODO")
96
  with gr.Row():
97
+ with gr.Column(scale=1):
98
+ gr.Markdown("Select the parameters here:")
99
  num_clusters = gr.Radio(
100
  [12, 24, 48],
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("")
108
  order = gr.Dropdown(
109
  ["entropy", "cluster/sum of clusters"],
110
+ value="entropy",
111
  label="Order rows by:",
112
  interactive=True,
113
  )
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
+ )
123
 
124
  # with gr.Accordion("Tag Frequencies", open=False):
125
 
 
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,