Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -110,7 +110,7 @@ df_cate = pd.DataFrame(categories)
|
|
110 |
# def update_label(label1):
|
111 |
# return gr.update(choices=list(df.columns))
|
112 |
|
113 |
-
|
114 |
|
115 |
def functionCall(fi_input, dropdown, choice):
|
116 |
if choice == "Intelligent split":
|
@@ -128,7 +128,33 @@ def change_textbox(dropdown,radio):
|
|
128 |
|
129 |
### Split files end
|
130 |
|
|
|
131 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
def reset_cate(df_categories):
|
133 |
if df_categories.equals(df_cate):
|
134 |
df_categories = pd.DataFrame([['', '', '']], columns=['topic', 'description', 'expert'])
|
@@ -220,10 +246,19 @@ with gr.Blocks() as demo:
|
|
220 |
dd_source_class = gr.Dropdown(label="Source Column", multiselect=False, scale=7)
|
221 |
sl_treshold = gr.Slider(minimum=0, maximum=1, value=0.45, step=0.05, label='Similarity Treshold')
|
222 |
gr.Markdown("### The predefined categories can be modified at any time")
|
|
|
|
|
|
|
|
|
|
|
223 |
df_category = gr.DataFrame(label='categories', value=df_cate, interactive=True)
|
|
|
|
|
224 |
with gr.Row():
|
225 |
-
btn_reset_df = gr.Button("Reset
|
226 |
btn_classif = gr.Button("Categorize")
|
|
|
|
|
227 |
|
228 |
with gr.Tab(" Personalised Charts Generation"):
|
229 |
gr.Markdown("### This section will create a chart using two columns of your choice")
|
@@ -297,7 +332,9 @@ with gr.Blocks() as demo:
|
|
297 |
#classification
|
298 |
btn_classif.click(classification, inputs=[dd_source_class, fi_excel, df_category, sl_treshold], outputs=[fi_excel, df_output])
|
299 |
btn_reset_df.click(reset_cate, inputs=df_category, outputs=df_category)
|
300 |
-
|
|
|
|
|
301 |
#charts
|
302 |
btn_chart.click(create_bar_plot, inputs=[fi_excel, dd_label1, dd_label2], outputs=[plt_figure])
|
303 |
|
|
|
110 |
# def update_label(label1):
|
111 |
# return gr.update(choices=list(df.columns))
|
112 |
|
113 |
+
### Functions needed for Split Files
|
114 |
|
115 |
def functionCall(fi_input, dropdown, choice):
|
116 |
if choice == "Intelligent split":
|
|
|
128 |
|
129 |
### Split files end
|
130 |
|
131 |
+
### Functions needed for Classfication
|
132 |
|
133 |
+
def addCategories(df,df_all):
|
134 |
+
categories = df.to_dict("records")
|
135 |
+
categories_all = df_all.to_dict("list")
|
136 |
+
for cat in categories:
|
137 |
+
if cat['topic'] not in categories_all['topic']:
|
138 |
+
categories_all['topic'].append(cat['topic'])
|
139 |
+
categories_all['description'].append(cat['description'])
|
140 |
+
categories_all['experts'].append(cat['experts'])
|
141 |
+
print(f"AFTER ADDINGS Those are the categories_all : {categories_all}")
|
142 |
+
|
143 |
+
return gr.update(choices=categories_all['topic']),pd.DataFrame.from_dict(categories_all)
|
144 |
+
|
145 |
+
df_cat_filter = df_cate.to_dict("list")["topic"]
|
146 |
+
|
147 |
+
def filterByTopics(filters, categories):
|
148 |
+
value_filtered = []
|
149 |
+
categories = categories.to_dict("records")
|
150 |
+
for cat in categories:
|
151 |
+
if cat['topic'] in filters:
|
152 |
+
value_filtered.append(cat)
|
153 |
+
|
154 |
+
return gr.DataFrame(label='categories', value=pd.DataFrame(value_filtered), interactive=True)
|
155 |
+
|
156 |
+
### End
|
157 |
+
|
158 |
def reset_cate(df_categories):
|
159 |
if df_categories.equals(df_cate):
|
160 |
df_categories = pd.DataFrame([['', '', '']], columns=['topic', 'description', 'expert'])
|
|
|
246 |
dd_source_class = gr.Dropdown(label="Source Column", multiselect=False, scale=7)
|
247 |
sl_treshold = gr.Slider(minimum=0, maximum=1, value=0.45, step=0.05, label='Similarity Treshold')
|
248 |
gr.Markdown("### The predefined categories can be modified at any time")
|
249 |
+
|
250 |
+
dd_filter = gr.Dropdown(choices=df_cat_filter, label = "Choose your filters here", multiselect=True, allow_custom_value=True)
|
251 |
+
|
252 |
+
btn_filter = gr.Button("Filter")
|
253 |
+
|
254 |
df_category = gr.DataFrame(label='categories', value=df_cate, interactive=True)
|
255 |
+
df_category_hidden = gr.DataFrame(value=df_cate, visible=False)
|
256 |
+
|
257 |
with gr.Row():
|
258 |
+
btn_reset_df = gr.Button("Reset categories")
|
259 |
btn_classif = gr.Button("Categorize")
|
260 |
+
btn_add_categories = gr.Button("Add categories")
|
261 |
+
|
262 |
|
263 |
with gr.Tab(" Personalised Charts Generation"):
|
264 |
gr.Markdown("### This section will create a chart using two columns of your choice")
|
|
|
332 |
#classification
|
333 |
btn_classif.click(classification, inputs=[dd_source_class, fi_excel, df_category, sl_treshold], outputs=[fi_excel, df_output])
|
334 |
btn_reset_df.click(reset_cate, inputs=df_category, outputs=df_category)
|
335 |
+
btn_filter.click(filterByTopics, inputs=[dd_filter, df_category_hidden], outputs=df_category)
|
336 |
+
btn_add_categories.click(addCategories, inputs=[df_category, df_category_hidden],outputs=[dd_filter,df_category_hidden])
|
337 |
+
|
338 |
#charts
|
339 |
btn_chart.click(create_bar_plot, inputs=[fi_excel, dd_label1, dd_label2], outputs=[plt_figure])
|
340 |
|