Update app.py
Browse files
app.py
CHANGED
|
@@ -16,8 +16,9 @@ def categorize_rank(r):
|
|
| 16 |
else: return "100+"
|
| 17 |
|
| 18 |
def process_data(file):
|
|
|
|
| 19 |
if file is None:
|
| 20 |
-
return None, None, None, gr.
|
| 21 |
|
| 22 |
excel = pd.ExcelFile(file.name)
|
| 23 |
first_sheet = excel.sheet_names[0]
|
|
@@ -59,13 +60,13 @@ def process_data(file):
|
|
| 59 |
|
| 60 |
full_viz_df = pd.concat(viz_data) if viz_data else pd.DataFrame()
|
| 61 |
|
| 62 |
-
# 4. FIX SORTING
|
| 63 |
correct_order = [
|
| 64 |
"01–03", "04–10", "11–20", "21–30", "31–40",
|
| 65 |
"41–50", "51–100", "100+", "Not Talking (Intent Not Correct)"
|
| 66 |
]
|
| 67 |
|
| 68 |
-
# 5. Create Chart
|
| 69 |
if not full_viz_df.empty:
|
| 70 |
fig = px.bar(
|
| 71 |
full_viz_df,
|
|
@@ -80,14 +81,16 @@ def process_data(file):
|
|
| 80 |
else:
|
| 81 |
fig = None
|
| 82 |
|
| 83 |
-
#
|
| 84 |
unique_months = list(full_viz_df['Month'].unique()) if not full_viz_df.empty else []
|
|
|
|
|
|
|
| 85 |
return (
|
| 86 |
final_df,
|
| 87 |
fig,
|
| 88 |
final_df,
|
| 89 |
-
gr.Dropdown
|
| 90 |
-
gr.Dropdown
|
| 91 |
)
|
| 92 |
|
| 93 |
def filter_table(full_data, selected_month, selected_range):
|
|
@@ -134,7 +137,7 @@ with gr.Blocks() as demo:
|
|
| 134 |
outputs=[table_output, plot_output, full_data_state, month_dropdown, range_dropdown]
|
| 135 |
)
|
| 136 |
|
| 137 |
-
# 2. Filter Table
|
| 138 |
filter_btn.click(
|
| 139 |
fn=filter_table,
|
| 140 |
inputs=[full_data_state, month_dropdown, range_dropdown],
|
|
|
|
| 16 |
else: return "100+"
|
| 17 |
|
| 18 |
def process_data(file):
|
| 19 |
+
# Returns empty updates if no file is uploaded
|
| 20 |
if file is None:
|
| 21 |
+
return None, None, None, gr.Dropdown(choices=[]), gr.Dropdown(choices=[])
|
| 22 |
|
| 23 |
excel = pd.ExcelFile(file.name)
|
| 24 |
first_sheet = excel.sheet_names[0]
|
|
|
|
| 60 |
|
| 61 |
full_viz_df = pd.concat(viz_data) if viz_data else pd.DataFrame()
|
| 62 |
|
| 63 |
+
# 4. FIX SORTING
|
| 64 |
correct_order = [
|
| 65 |
"01–03", "04–10", "11–20", "21–30", "31–40",
|
| 66 |
"41–50", "51–100", "100+", "Not Talking (Intent Not Correct)"
|
| 67 |
]
|
| 68 |
|
| 69 |
+
# 5. Create Chart
|
| 70 |
if not full_viz_df.empty:
|
| 71 |
fig = px.bar(
|
| 72 |
full_viz_df,
|
|
|
|
| 81 |
else:
|
| 82 |
fig = None
|
| 83 |
|
| 84 |
+
# Prepare Dropdown Data
|
| 85 |
unique_months = list(full_viz_df['Month'].unique()) if not full_viz_df.empty else []
|
| 86 |
+
|
| 87 |
+
# FIX: Return new component instances instead of .update()
|
| 88 |
return (
|
| 89 |
final_df,
|
| 90 |
fig,
|
| 91 |
final_df,
|
| 92 |
+
gr.Dropdown(choices=unique_months, value=unique_months[0] if unique_months else None),
|
| 93 |
+
gr.Dropdown(choices=correct_order, value=correct_order[0])
|
| 94 |
)
|
| 95 |
|
| 96 |
def filter_table(full_data, selected_month, selected_range):
|
|
|
|
| 137 |
outputs=[table_output, plot_output, full_data_state, month_dropdown, range_dropdown]
|
| 138 |
)
|
| 139 |
|
| 140 |
+
# 2. Filter Table
|
| 141 |
filter_btn.click(
|
| 142 |
fn=filter_table,
|
| 143 |
inputs=[full_data_state, month_dropdown, range_dropdown],
|