Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -306,7 +306,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
306 |
"I dettagli sulla formula/metodologia appariranno qui.", visible=False
|
307 |
)
|
308 |
|
309 |
-
async def handle_panel_action(
|
310 |
plot_id_clicked: str,
|
311 |
action_type: str,
|
312 |
current_active_action_from_state: dict,
|
@@ -318,11 +318,10 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
318 |
clicked_plot_config = next((p for p in plot_configs if p["id"] == plot_id_clicked), None)
|
319 |
if not clicked_plot_config:
|
320 |
logging.error(f"Configurazione non trovata per plot_id {plot_id_clicked}")
|
321 |
-
# Ensure we return the correct number of updates even on error
|
322 |
num_button_updates = 2 * len(plot_configs)
|
323 |
-
error_updates = [gr.update(visible=False)] * 10
|
324 |
-
error_updates.extend([current_active_action_from_state, current_chat_plot_id, current_chat_histories])
|
325 |
-
error_updates.extend([gr.update()] * num_button_updates)
|
326 |
return error_updates
|
327 |
|
328 |
clicked_plot_label = clicked_plot_config["label"]
|
@@ -416,7 +415,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
416 |
updated_chat_histories
|
417 |
] + all_button_icon_updates
|
418 |
|
419 |
-
return final_updates
|
420 |
|
421 |
async def handle_chat_message_submission(
|
422 |
user_message: str,
|
@@ -541,21 +540,29 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
|
541 |
]
|
542 |
explore_click_inputs = [explored_plot_id_state]
|
543 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
544 |
for config_item in plot_configs:
|
545 |
plot_id = config_item["id"]
|
546 |
-
plot_label = config_item["label"]
|
547 |
if plot_id in plot_ui_objects:
|
548 |
ui_obj = plot_ui_objects[plot_id]
|
549 |
-
|
|
|
550 |
ui_obj["bomb_button"].click(
|
551 |
-
fn=
|
552 |
inputs=action_click_inputs,
|
553 |
outputs=action_panel_outputs_list,
|
554 |
api_name=f"action_insights_{plot_id}"
|
555 |
)
|
556 |
-
# FIX: Make lambda async and await the call to handle_panel_action
|
557 |
ui_obj["formula_button"].click(
|
558 |
-
fn=
|
559 |
inputs=action_click_inputs,
|
560 |
outputs=action_panel_outputs_list,
|
561 |
api_name=f"action_formula_{plot_id}"
|
|
|
306 |
"I dettagli sulla formula/metodologia appariranno qui.", visible=False
|
307 |
)
|
308 |
|
309 |
+
async def handle_panel_action(
|
310 |
plot_id_clicked: str,
|
311 |
action_type: str,
|
312 |
current_active_action_from_state: dict,
|
|
|
318 |
clicked_plot_config = next((p for p in plot_configs if p["id"] == plot_id_clicked), None)
|
319 |
if not clicked_plot_config:
|
320 |
logging.error(f"Configurazione non trovata per plot_id {plot_id_clicked}")
|
|
|
321 |
num_button_updates = 2 * len(plot_configs)
|
322 |
+
error_updates = [gr.update(visible=False)] * 10
|
323 |
+
error_updates.extend([current_active_action_from_state, current_chat_plot_id, current_chat_histories])
|
324 |
+
error_updates.extend([gr.update()] * num_button_updates)
|
325 |
return error_updates
|
326 |
|
327 |
clicked_plot_label = clicked_plot_config["label"]
|
|
|
415 |
updated_chat_histories
|
416 |
] + all_button_icon_updates
|
417 |
|
418 |
+
return final_updates
|
419 |
|
420 |
async def handle_chat_message_submission(
|
421 |
user_message: str,
|
|
|
540 |
]
|
541 |
explore_click_inputs = [explored_plot_id_state]
|
542 |
|
543 |
+
# --- Define async wrapper functions for click handlers ---
|
544 |
+
async def insights_click_wrapper(current_active_val, current_chats_val, current_chat_pid, p_id):
|
545 |
+
return await handle_panel_action(p_id, "insights", current_active_val, current_chats_val, current_chat_pid)
|
546 |
+
|
547 |
+
async def formula_click_wrapper(current_active_val, current_chats_val, current_chat_pid, p_id):
|
548 |
+
return await handle_panel_action(p_id, "formula", current_active_val, current_chats_val, current_chat_pid)
|
549 |
+
# --- End async wrapper functions ---
|
550 |
+
|
551 |
for config_item in plot_configs:
|
552 |
plot_id = config_item["id"]
|
553 |
+
# plot_label = config_item["label"] # Not needed here anymore
|
554 |
if plot_id in plot_ui_objects:
|
555 |
ui_obj = plot_ui_objects[plot_id]
|
556 |
+
|
557 |
+
# Use a standard lambda to call the async wrapper, capturing p_id
|
558 |
ui_obj["bomb_button"].click(
|
559 |
+
fn=lambda cav, ccv, ccpid, p=plot_id: insights_click_wrapper(cav, ccv, ccpid, p),
|
560 |
inputs=action_click_inputs,
|
561 |
outputs=action_panel_outputs_list,
|
562 |
api_name=f"action_insights_{plot_id}"
|
563 |
)
|
|
|
564 |
ui_obj["formula_button"].click(
|
565 |
+
fn=lambda cav, ccv, ccpid, p=plot_id: formula_click_wrapper(cav, ccv, ccpid, p),
|
566 |
inputs=action_click_inputs,
|
567 |
outputs=action_panel_outputs_list,
|
568 |
api_name=f"action_formula_{plot_id}"
|