Spaces:
Sleeping
Sleeping
File size: 2,536 Bytes
352ebdd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# ui/db_management_tab.py
import gradio as gr
from app.document_handling import create_database, modify_database, delete_database, list_databases
def create_db_management_tab(update_dropdowns):
"""Crea il tab 'Gestione Database' dell'interfaccia Gradio."""
def update_dropdowns_callback():
"""Aggiorna tutti i dropdown con la lista aggiornata dei database."""
databases = list_databases()
return [gr.update(choices=databases) for _ in range(6)]
# Ottieni la lista iniziale dei database
databases = list_databases()
with gr.Tab("Gestione Database"):
gr.Markdown("## Operazioni sui Database")
with gr.Row():
with gr.Column():
gr.Markdown("### Crea Database")
db_name_input = gr.Textbox(label="Nome Nuovo Database")
create_db_button = gr.Button("Crea Database")
create_output = gr.Textbox(label="Stato Creazione")
with gr.Column():
gr.Markdown("### Rinomina Database")
modify_db_old_name = gr.Dropdown(choices=databases, label="Database da Rinominare")
modify_db_new_name = gr.Textbox(label="Nuovo Nome")
modify_db_button = gr.Button("Rinomina Database")
modify_output = gr.Textbox(label="Stato Modifica")
with gr.Column():
gr.Markdown("### Elimina Database")
delete_db_dropdown = gr.Dropdown(choices=databases, label="Database da Eliminare")
delete_db_button = gr.Button("Elimina Database")
delete_output = gr.Textbox(label="Stato Eliminazione")
# Eventi per i bottoni di gestione DB
create_db_button.click(
create_database,
inputs=db_name_input,
outputs=create_output
).then(
update_dropdowns,
outputs=[modify_db_old_name, delete_db_dropdown]
)
modify_db_button.click(
modify_database,
inputs=[modify_db_old_name, modify_db_new_name],
outputs=modify_output
).then(
update_dropdowns,
outputs=[modify_db_old_name, delete_db_dropdown]
)
delete_db_button.click(
delete_database,
inputs=delete_db_dropdown,
outputs=delete_output
).then(
update_dropdowns,
outputs=[modify_db_old_name, delete_db_dropdown]
)
return
|