Update app.py
Browse files
app.py
CHANGED
|
@@ -68,15 +68,14 @@ def process_data(file):
|
|
| 68 |
labels={'Range': 'Rank Range', 'Keyword Count': 'Number of Keywords'}
|
| 69 |
)
|
| 70 |
|
| 71 |
-
fig.update_layout(clickmode='event+select')
|
| 72 |
-
|
| 73 |
return final_df, fig, final_df
|
| 74 |
|
| 75 |
-
def filter_table(
|
| 76 |
-
#
|
| 77 |
-
#
|
| 78 |
-
clicked_range =
|
| 79 |
-
|
|
|
|
| 80 |
|
| 81 |
target_col = f"{clicked_month}_Rank Range"
|
| 82 |
|
|
@@ -88,11 +87,12 @@ def filter_table(evt: gr.SelectData, full_data):
|
|
| 88 |
def reset_table(full_data):
|
| 89 |
return full_data
|
| 90 |
|
| 91 |
-
|
|
|
|
| 92 |
full_data_state = gr.State()
|
| 93 |
|
| 94 |
gr.Markdown("# 🚀 SEO Market Intelligence Dashboard")
|
| 95 |
-
gr.Markdown("###
|
| 96 |
|
| 97 |
with gr.Row():
|
| 98 |
file_input = gr.File(label="Upload SEO Excel", file_types=[".xlsx"])
|
|
@@ -111,9 +111,10 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 111 |
outputs=[table_output, plot_output, full_data_state]
|
| 112 |
)
|
| 113 |
|
|
|
|
| 114 |
plot_output.select(
|
| 115 |
fn=filter_table,
|
| 116 |
-
inputs=full_data_state,
|
| 117 |
outputs=table_output
|
| 118 |
)
|
| 119 |
|
|
@@ -124,4 +125,5 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 124 |
)
|
| 125 |
|
| 126 |
if __name__ == "__main__":
|
| 127 |
-
|
|
|
|
|
|
| 68 |
labels={'Range': 'Rank Range', 'Keyword Count': 'Number of Keywords'}
|
| 69 |
)
|
| 70 |
|
|
|
|
|
|
|
| 71 |
return final_df, fig, final_df
|
| 72 |
|
| 73 |
+
def filter_table(full_data, selection_data: gr.SelectData):
|
| 74 |
+
# In Gradio, for Plotly charts, selection_data.value contains info about the point
|
| 75 |
+
# We extract the Rank Range (x) and the Month (from the legend/color)
|
| 76 |
+
clicked_range = selection_data.value
|
| 77 |
+
# SelectData for Plotly provides a dictionary in .extra for legend details
|
| 78 |
+
clicked_month = selection_data.extra.get('label')
|
| 79 |
|
| 80 |
target_col = f"{clicked_month}_Rank Range"
|
| 81 |
|
|
|
|
| 87 |
def reset_table(full_data):
|
| 88 |
return full_data
|
| 89 |
|
| 90 |
+
# FIX 1: Removed theme from Blocks constructor
|
| 91 |
+
with gr.Blocks() as demo:
|
| 92 |
full_data_state = gr.State()
|
| 93 |
|
| 94 |
gr.Markdown("# 🚀 SEO Market Intelligence Dashboard")
|
| 95 |
+
gr.Markdown("### Click a bar in the chart to filter the keyword list for that month and range.")
|
| 96 |
|
| 97 |
with gr.Row():
|
| 98 |
file_input = gr.File(label="Upload SEO Excel", file_types=[".xlsx"])
|
|
|
|
| 111 |
outputs=[table_output, plot_output, full_data_state]
|
| 112 |
)
|
| 113 |
|
| 114 |
+
# FIX 2: Used the correct selection logic for gr.Plot
|
| 115 |
plot_output.select(
|
| 116 |
fn=filter_table,
|
| 117 |
+
inputs=[full_data_state],
|
| 118 |
outputs=table_output
|
| 119 |
)
|
| 120 |
|
|
|
|
| 125 |
)
|
| 126 |
|
| 127 |
if __name__ == "__main__":
|
| 128 |
+
# FIX 3: Moved theme to launch()
|
| 129 |
+
demo.launch(theme=gr.themes.Soft())
|