Spaces:
Runtime error
Runtime error
sashavor
commited on
Commit
·
427730e
1
Parent(s):
277f906
adding Meg's function
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
import json
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
|
|
5 |
|
6 |
pd.options.plotting.backend = "plotly"
|
7 |
|
@@ -30,6 +31,21 @@ df_models = {
|
|
30 |
}
|
31 |
|
32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
def make_profession_plot(num_clusters, prof_name):
|
34 |
print("-------------")
|
35 |
print(num_clusters, prof_name)
|
@@ -163,6 +179,7 @@ with gr.Blocks() as demo:
|
|
163 |
queue=False,
|
164 |
)
|
165 |
|
|
|
166 |
# with gr.Accordion("Tag Frequencies", open=False):
|
167 |
|
168 |
with gr.Tab("Profession Focus"):
|
|
|
2 |
import json
|
3 |
import numpy as np
|
4 |
import pandas as pd
|
5 |
+
import operator
|
6 |
|
7 |
pd.options.plotting.backend = "plotly"
|
8 |
|
|
|
31 |
}
|
32 |
|
33 |
|
34 |
+
def describe_cluster(cl_dict, block="label"):
|
35 |
+
labels_values = sorted(cl_dict.items(), key=operator.itemgetter(1))
|
36 |
+
labels_values.reverse()
|
37 |
+
total = float(sum(cl_dict.values()))
|
38 |
+
lv_prcnt = list(
|
39 |
+
(item[0], round(item[1] * 100 / total, 0)) for item in labels_values)
|
40 |
+
top_label = lv_prcnt[0][0]
|
41 |
+
description_string = "<span>The most represented %s is <b>%s</b>, making up about <b>%d%%</b> of the cluster.</span>" % (
|
42 |
+
to_string(block), to_string(top_label), lv_prcnt[0][1])
|
43 |
+
description_string += "<p>This is followed by: "
|
44 |
+
for lv in lv_prcnt[1:]:
|
45 |
+
description_string += "<BR/><b>%s:</b> %d%%" % (to_string(lv[0]), lv[1])
|
46 |
+
description_string += "</p>"
|
47 |
+
return description_string
|
48 |
+
|
49 |
def make_profession_plot(num_clusters, prof_name):
|
50 |
print("-------------")
|
51 |
print(num_clusters, prof_name)
|
|
|
179 |
queue=False,
|
180 |
)
|
181 |
|
182 |
+
|
183 |
# with gr.Accordion("Tag Frequencies", open=False):
|
184 |
|
185 |
with gr.Tab("Profession Focus"):
|