Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -184,7 +184,7 @@ def main(file, num_clusters_to_display):
|
|
| 184 |
filtered_df = filtered_df.sort_values(by='Category')
|
| 185 |
|
| 186 |
wordcloud_img = generate_wordcloud(filtered_df)
|
| 187 |
-
bar_chart_img = generate_bar_chart(
|
| 188 |
|
| 189 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as tmpfile:
|
| 190 |
filtered_df.to_csv(tmpfile.name, index=False)
|
|
@@ -211,72 +211,3 @@ interface = gr.Interface(
|
|
| 211 |
)
|
| 212 |
|
| 213 |
interface.launch(share=True)
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------β--------
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
def main(file, bot_name, num_clusters_to_display):
|
| 226 |
-
try:
|
| 227 |
-
global categories_keywords
|
| 228 |
-
if bot_name == "Teach For India":
|
| 229 |
-
categories_keywords = categories_keywords_tfi
|
| 230 |
-
else:
|
| 231 |
-
categories_keywords = categories_keywords_firki
|
| 232 |
-
|
| 233 |
-
df = pd.read_csv(file.name)
|
| 234 |
-
|
| 235 |
-
df = df[df['Answer'] == 'Fallback Message shown']
|
| 236 |
-
|
| 237 |
-
df = preprocess_data(df, categories_keywords)
|
| 238 |
-
|
| 239 |
-
category_sizes = df['Category'].value_counts().reset_index()
|
| 240 |
-
category_sizes.columns = ['Category', 'Count']
|
| 241 |
-
sorted_categories = category_sizes.sort_values(by='Count', ascending=True)['Category'].tolist()
|
| 242 |
-
|
| 243 |
-
largest_categories = sorted_categories[:num_clusters_to_display]
|
| 244 |
-
|
| 245 |
-
filtered_df = df[df['Category'].isin(largest_categories)]
|
| 246 |
-
|
| 247 |
-
filtered_df = filtered_df.sort_values(by='Category')
|
| 248 |
-
|
| 249 |
-
wordcloud_img = generate_wordcloud(filtered_df)
|
| 250 |
-
bar_chart_img = generate_bar_chart(df, num_clusters_to_display)
|
| 251 |
-
|
| 252 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as tmpfile:
|
| 253 |
-
filtered_df.to_csv(tmpfile.name, index=False)
|
| 254 |
-
csv_file_path = tmpfile.name
|
| 255 |
-
|
| 256 |
-
return csv_file_path, wordcloud_img, bar_chart_img
|
| 257 |
-
except Exception as e:
|
| 258 |
-
print(f"Error: {e}")
|
| 259 |
-
return str(e), None, None
|
| 260 |
-
|
| 261 |
-
def categorize_unanswered_queries(bot_name, file, num_clusters_to_display):
|
| 262 |
-
return main(file, bot_name, num_clusters_to_display)
|
| 263 |
-
|
| 264 |
-
interface = gr.Interface(
|
| 265 |
-
fn=categorize_unanswered_queries,
|
| 266 |
-
inputs=[
|
| 267 |
-
gr.Radio(["Teach For India", "Firki"], label="Select ChatBot"),
|
| 268 |
-
gr.File(label="Upload CSV File (.csv)"),
|
| 269 |
-
gr.Slider(label="Number of Categories to Display", minimum=1, maximum=10, step=1, value=5)
|
| 270 |
-
],
|
| 271 |
-
outputs=[
|
| 272 |
-
gr.File(label="Categorized Data CSV"),
|
| 273 |
-
gr.Image(label="Word Cloud"),
|
| 274 |
-
gr.Image(label="Bar Chart")
|
| 275 |
-
],
|
| 276 |
-
title="Unanswered User Queries Categorization",
|
| 277 |
-
description="Select the bot, upload the CSV file, and specify the number of categories to display to categorize unanswered user queries."
|
| 278 |
-
)
|
| 279 |
-
|
| 280 |
-
interface.launch()
|
| 281 |
-
|
| 282 |
-
|
|
|
|
| 184 |
filtered_df = filtered_df.sort_values(by='Category')
|
| 185 |
|
| 186 |
wordcloud_img = generate_wordcloud(filtered_df)
|
| 187 |
+
bar_chart_img = generate_bar_chart(df, num_clusters_to_display)
|
| 188 |
|
| 189 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".csv") as tmpfile:
|
| 190 |
filtered_df.to_csv(tmpfile.name, index=False)
|
|
|
|
| 211 |
)
|
| 212 |
|
| 213 |
interface.launch(share=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|