Spaces:
Runtime error
Runtime error
fix UX
Browse files
app.py
CHANGED
|
@@ -224,6 +224,17 @@ def on_card_click_animated(selected_index, books_state_list, max_results):
|
|
| 224 |
except Exception as e:
|
| 225 |
yield gr.update(visible=False), f"Errore Backend: {e}"
|
| 226 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
|
| 228 |
# --- INTERFACCIA ---
|
| 229 |
with gr.Blocks(theme=gr.themes.Ocean(), css=GLOBAL_CSS, js=JS_FORCE_DARK) as demo:
|
|
@@ -234,15 +245,16 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=GLOBAL_CSS, js=JS_FORCE_DARK) as dem
|
|
| 234 |
with gr.Row():
|
| 235 |
num_results = gr.Slider(1, 10, value=5, step=1, label="Quanti consigli vuoi?")
|
| 236 |
|
| 237 |
-
with gr.Tabs():
|
|
|
|
| 238 |
# TAB 1: Ricerca Libera
|
| 239 |
-
with gr.Tab("🔎 Ricerca per Trama"):
|
| 240 |
with gr.Row():
|
| 241 |
txt_input = gr.Textbox(placeholder="Descrivi la trama, l'atmosfera o le emozioni che cerchi...", show_label=False, scale=4)
|
| 242 |
btn_search = gr.Button("Cerca", variant="primary", scale=1)
|
| 243 |
|
| 244 |
# TAB 2: Ricerca per Libro
|
| 245 |
-
with gr.Tab("📖 Mi è piaciuto..."):
|
| 246 |
with gr.Row():
|
| 247 |
txt_title = gr.Textbox(placeholder="Scrivi il titolo, anche parziale", show_label=False, scale=4)
|
| 248 |
btn_find = gr.Button("Trova", scale=1)
|
|
@@ -263,7 +275,7 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=GLOBAL_CSS, js=JS_FORCE_DARK) as dem
|
|
| 263 |
loader_results = gr.HTML(value=LOADING_HTML, visible=False)
|
| 264 |
out_results = gr.HTML(label="Consigli", visible=True)
|
| 265 |
|
| 266 |
-
# EVENTI
|
| 267 |
btn_search.click(fn=search_free_text_animated, inputs=[txt_input, num_results], outputs=[loader_results, out_results])
|
| 268 |
txt_input.submit(fn=search_free_text_animated, inputs=[txt_input, num_results], outputs=[loader_results, out_results])
|
| 269 |
|
|
@@ -276,5 +288,19 @@ with gr.Blocks(theme=gr.themes.Ocean(), css=GLOBAL_CSS, js=JS_FORCE_DARK) as dem
|
|
| 276 |
outputs=[loader_results, out_results]
|
| 277 |
)
|
| 278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
print("Avvio Gradio...")
|
| 280 |
demo.launch(share=True, debug=True)
|
|
|
|
| 224 |
except Exception as e:
|
| 225 |
yield gr.update(visible=False), f"Errore Backend: {e}"
|
| 226 |
|
| 227 |
+
def clear_search_tab():
|
| 228 |
+
"""Pulisce il Tab Ricerca per Trama quando si passa all'altro."""
|
| 229 |
+
return gr.update(value=""), gr.update(value="", visible=False)
|
| 230 |
+
|
| 231 |
+
def clear_find_tab():
|
| 232 |
+
"""Pulisce il Tab Mi è piaciuto quando si passa all'altro."""
|
| 233 |
+
return (
|
| 234 |
+
gr.update(value=""), # txt_title
|
| 235 |
+
gr.update(visible=False), # cards_view (Dataset)
|
| 236 |
+
gr.update(value="", visible=False) # out_results
|
| 237 |
+
)
|
| 238 |
|
| 239 |
# --- INTERFACCIA ---
|
| 240 |
with gr.Blocks(theme=gr.themes.Ocean(), css=GLOBAL_CSS, js=JS_FORCE_DARK) as demo:
|
|
|
|
| 245 |
with gr.Row():
|
| 246 |
num_results = gr.Slider(1, 10, value=5, step=1, label="Quanti consigli vuoi?")
|
| 247 |
|
| 248 |
+
with gr.Tabs() as tabs:
|
| 249 |
+
|
| 250 |
# TAB 1: Ricerca Libera
|
| 251 |
+
with gr.Tab("🔎 Ricerca per Trama") as tab_trama: # Assegna variabile
|
| 252 |
with gr.Row():
|
| 253 |
txt_input = gr.Textbox(placeholder="Descrivi la trama, l'atmosfera o le emozioni che cerchi...", show_label=False, scale=4)
|
| 254 |
btn_search = gr.Button("Cerca", variant="primary", scale=1)
|
| 255 |
|
| 256 |
# TAB 2: Ricerca per Libro
|
| 257 |
+
with gr.Tab("📖 Mi è piaciuto...") as tab_libro: # Assegna variabile
|
| 258 |
with gr.Row():
|
| 259 |
txt_title = gr.Textbox(placeholder="Scrivi il titolo, anche parziale", show_label=False, scale=4)
|
| 260 |
btn_find = gr.Button("Trova", scale=1)
|
|
|
|
| 275 |
loader_results = gr.HTML(value=LOADING_HTML, visible=False)
|
| 276 |
out_results = gr.HTML(label="Consigli", visible=True)
|
| 277 |
|
| 278 |
+
# --- EVENTI DI RICERCA (UGUALI A PRIMA) ---
|
| 279 |
btn_search.click(fn=search_free_text_animated, inputs=[txt_input, num_results], outputs=[loader_results, out_results])
|
| 280 |
txt_input.submit(fn=search_free_text_animated, inputs=[txt_input, num_results], outputs=[loader_results, out_results])
|
| 281 |
|
|
|
|
| 288 |
outputs=[loader_results, out_results]
|
| 289 |
)
|
| 290 |
|
| 291 |
+
# Quando clicco su "Ricerca per Trama", pulisco il Tab "Mi è piaciuto"
|
| 292 |
+
tab_trama.select(
|
| 293 |
+
fn=clear_find_tab,
|
| 294 |
+
inputs=None,
|
| 295 |
+
outputs=[txt_title, cards_view, out_results]
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
# Quando clicco su "Mi è piaciuto", pulisco il Tab "Ricerca per Trama" e i risultati globali
|
| 299 |
+
tab_libro.select(
|
| 300 |
+
fn=clear_search_tab,
|
| 301 |
+
inputs=None,
|
| 302 |
+
outputs=[txt_input, out_results]
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
print("Avvio Gradio...")
|
| 306 |
demo.launch(share=True, debug=True)
|