Spaces:
Sleeping
Sleeping
update dropdowns
Browse files- app.py +18 -26
- ui/chatbot_tab.py +3 -2
- ui/db_management_tab.py +31 -14
- ui/document_management_tab.py +13 -23
- ui/management_tabs.py +163 -0
app.py
CHANGED
@@ -2,9 +2,8 @@
|
|
2 |
|
3 |
import gradio as gr
|
4 |
import logging
|
5 |
-
from watchdog.observers import Observer
|
6 |
from app.logging_config import configure_logging
|
7 |
-
from app.functions.database_handling import list_databases
|
8 |
from ui.chatbot_tab import create_chatbot_tab
|
9 |
from ui.db_management_tab import create_db_management_tab
|
10 |
from ui.document_management_tab import create_document_management_tab
|
@@ -13,41 +12,34 @@ from ui.new_features_tab import create_new_features_tab
|
|
13 |
# Configura il logging
|
14 |
configure_logging()
|
15 |
|
16 |
-
def update_all_dropdowns():
|
17 |
-
"""
|
18 |
-
Aggiorna tutti i dropdown in tutte le tab.
|
19 |
-
"""
|
20 |
-
databases = list_databases()
|
21 |
-
logging.info(f"Aggiornamento dropdown con databases: {databases}")
|
22 |
-
return [gr.update(choices=databases, value=databases[0] if databases else None) for _ in range(6)]
|
23 |
-
|
24 |
def main():
|
25 |
"""Funzione principale che crea e lancia l'app Gradio."""
|
26 |
logging.info("Avvio applicazione")
|
27 |
try:
|
28 |
with gr.Blocks() as rag_chatbot:
|
29 |
-
# Configura l'observer per la cartella db
|
30 |
-
observer = setup_db_observer(update_all_dropdowns)
|
31 |
-
|
32 |
gr.Markdown("# Chatbot basato su RAG")
|
33 |
logging.info("Interfaccia Gradio inizializzata")
|
34 |
|
35 |
-
#
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
-
# Avvia l'app
|
43 |
rag_chatbot.launch()
|
|
|
44 |
except Exception as e:
|
45 |
logging.error(f"Errore durante l'avvio: {str(e)}")
|
46 |
-
finally:
|
47 |
-
# Assicurati che l'observer venga fermato
|
48 |
-
if 'observer' in locals():
|
49 |
-
observer.stop()
|
50 |
-
observer.join()
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
-
main()
|
|
|
2 |
|
3 |
import gradio as gr
|
4 |
import logging
|
|
|
5 |
from app.logging_config import configure_logging
|
6 |
+
from app.functions.database_handling import list_databases
|
7 |
from ui.chatbot_tab import create_chatbot_tab
|
8 |
from ui.db_management_tab import create_db_management_tab
|
9 |
from ui.document_management_tab import create_document_management_tab
|
|
|
12 |
# Configura il logging
|
13 |
configure_logging()
|
14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
def main():
|
16 |
"""Funzione principale che crea e lancia l'app Gradio."""
|
17 |
logging.info("Avvio applicazione")
|
18 |
try:
|
19 |
with gr.Blocks() as rag_chatbot:
|
|
|
|
|
|
|
20 |
gr.Markdown("# Chatbot basato su RAG")
|
21 |
logging.info("Interfaccia Gradio inizializzata")
|
22 |
|
23 |
+
# Prima ottiene tutti i riferimenti
|
24 |
+
doc_refs = create_document_management_tab()
|
25 |
+
chat_refs = create_chatbot_tab()
|
26 |
+
|
27 |
+
# Crea dizionario completo dei riferimenti
|
28 |
+
dropdowns = {
|
29 |
+
"document": doc_refs,
|
30 |
+
"chat": chat_refs
|
31 |
+
}
|
32 |
+
|
33 |
+
# Crea i tab nell'ordine corretto
|
34 |
+
create_db_management_tab(dropdowns) # Tab 1: DB Management
|
35 |
+
doc_refs # Tab 2: Document Management
|
36 |
+
create_new_features_tab() # Tab 3: Features
|
37 |
+
chat_refs # Tab 4: Chatbot (ultima tab)
|
38 |
|
|
|
39 |
rag_chatbot.launch()
|
40 |
+
|
41 |
except Exception as e:
|
42 |
logging.error(f"Errore durante l'avvio: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
43 |
|
44 |
if __name__ == "__main__":
|
45 |
+
main()
|
ui/chatbot_tab.py
CHANGED
@@ -42,7 +42,7 @@ def create_chatbot_tab():
|
|
42 |
with gr.Tab("Chatbot"):
|
43 |
with gr.Row():
|
44 |
with gr.Column(scale=2):
|
45 |
-
#
|
46 |
db_name_chat = gr.Dropdown(
|
47 |
choices=databases,
|
48 |
label="Seleziona Database",
|
@@ -96,4 +96,5 @@ def create_chatbot_tab():
|
|
96 |
outputs=[chatbot, chat_state]
|
97 |
)
|
98 |
|
99 |
-
|
|
|
|
42 |
with gr.Tab("Chatbot"):
|
43 |
with gr.Row():
|
44 |
with gr.Column(scale=2):
|
45 |
+
# Singolo dropdown per il database
|
46 |
db_name_chat = gr.Dropdown(
|
47 |
choices=databases,
|
48 |
label="Seleziona Database",
|
|
|
96 |
outputs=[chatbot, chat_state]
|
97 |
)
|
98 |
|
99 |
+
# Ritorna il riferimento al dropdown corretto
|
100 |
+
return {"db_selector": db_name_chat}
|
ui/db_management_tab.py
CHANGED
@@ -1,12 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
from app.functions.database_handling import create_database, modify_database, delete_database, list_databases
|
3 |
|
4 |
-
def create_db_management_tab(
|
5 |
-
"""Crea il tab 'Gestione Database' dell'interfaccia Gradio."""
|
6 |
-
|
7 |
-
# Ottieni la lista iniziale dei database
|
8 |
databases = list_databases()
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
with gr.Tab("Gestione Database"):
|
11 |
gr.Markdown("## Operazioni sui Database")
|
12 |
|
@@ -42,9 +44,14 @@ def create_db_management_tab(update_all_dropdowns=None):
|
|
42 |
inputs=db_name_input,
|
43 |
outputs=create_output
|
44 |
).then(
|
45 |
-
fn=
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
48 |
)
|
49 |
|
50 |
modify_db_button.click(
|
@@ -52,9 +59,14 @@ def create_db_management_tab(update_all_dropdowns=None):
|
|
52 |
inputs=[modify_db_old_name, modify_db_new_name],
|
53 |
outputs=modify_output
|
54 |
).then(
|
55 |
-
fn=
|
56 |
-
|
57 |
-
|
|
|
|
|
|
|
|
|
|
|
58 |
)
|
59 |
|
60 |
delete_db_button.click(
|
@@ -62,9 +74,14 @@ def create_db_management_tab(update_all_dropdowns=None):
|
|
62 |
inputs=delete_db_dropdown,
|
63 |
outputs=delete_output
|
64 |
).then(
|
65 |
-
fn=
|
66 |
-
|
67 |
-
|
|
|
|
|
|
|
|
|
|
|
68 |
)
|
69 |
|
70 |
# Ritorna i componenti che vogliamo poter aggiornare/agganciare
|
|
|
1 |
import gradio as gr
|
2 |
from app.functions.database_handling import create_database, modify_database, delete_database, list_databases
|
3 |
|
4 |
+
def create_db_management_tab(dropdowns):
|
|
|
|
|
|
|
5 |
databases = list_databases()
|
6 |
+
|
7 |
+
def update_dropdowns():
|
8 |
+
updated_dbs = list_databases()
|
9 |
+
# Aggiorna tutti i dropdown dell'applicazione (5 invece di 4)
|
10 |
+
return [gr.update(choices=updated_dbs) for _ in range(5)]
|
11 |
+
|
12 |
with gr.Tab("Gestione Database"):
|
13 |
gr.Markdown("## Operazioni sui Database")
|
14 |
|
|
|
44 |
inputs=db_name_input,
|
45 |
outputs=create_output
|
46 |
).then(
|
47 |
+
fn=update_dropdowns,
|
48 |
+
outputs=[
|
49 |
+
modify_db_old_name, # db_management_tab
|
50 |
+
delete_db_dropdown, # db_management_tab
|
51 |
+
dropdowns["document"]["upload"], # document_management_tab
|
52 |
+
dropdowns["document"]["list"], # document_management_tab
|
53 |
+
dropdowns["chat"]["db_selector"] # chatbot_tab
|
54 |
+
]
|
55 |
)
|
56 |
|
57 |
modify_db_button.click(
|
|
|
59 |
inputs=[modify_db_old_name, modify_db_new_name],
|
60 |
outputs=modify_output
|
61 |
).then(
|
62 |
+
fn=update_dropdowns,
|
63 |
+
outputs=[
|
64 |
+
modify_db_old_name, # db_management_tab
|
65 |
+
delete_db_dropdown, # db_management_tab
|
66 |
+
dropdowns["document"]["upload"], # document_management_tab
|
67 |
+
dropdowns["document"]["list"], # document_management_tab
|
68 |
+
dropdowns["chat"]["db_selector"] # chatbot_tab
|
69 |
+
]
|
70 |
)
|
71 |
|
72 |
delete_db_button.click(
|
|
|
74 |
inputs=delete_db_dropdown,
|
75 |
outputs=delete_output
|
76 |
).then(
|
77 |
+
fn=update_dropdowns,
|
78 |
+
outputs=[
|
79 |
+
modify_db_old_name, # db_management_tab
|
80 |
+
delete_db_dropdown, # db_management_tab
|
81 |
+
dropdowns["document"]["upload"], # document_management_tab
|
82 |
+
dropdowns["document"]["list"], # document_management_tab
|
83 |
+
dropdowns["chat"]["db_selector"] # chatbot_tab
|
84 |
+
]
|
85 |
)
|
86 |
|
87 |
# Ritorna i componenti che vogliamo poter aggiornare/agganciare
|
ui/document_management_tab.py
CHANGED
@@ -3,25 +3,24 @@ import logging
|
|
3 |
from app.document_handling import upload_and_index, list_indexed_files, delete_file_from_database
|
4 |
from app.functions.database_handling import list_databases
|
5 |
|
6 |
-
def create_document_management_tab(
|
7 |
"""Crea il tab 'Gestione Documenti' dell'interfaccia Gradio."""
|
8 |
|
9 |
-
def
|
10 |
"""Aggiorna localmente i dropdown con la lista aggiornata dei database."""
|
11 |
-
|
12 |
-
logging.info(f"Aggiornamento dropdown con databases: {
|
13 |
-
|
14 |
-
gr.update(choices=
|
15 |
-
gr.update(choices=
|
16 |
]
|
17 |
-
return updates
|
18 |
|
19 |
def upload_and_index_callback(files, title, author, db_name):
|
20 |
"""Carica e indicizza i documenti, quindi aggiorna la lista dei file."""
|
21 |
try:
|
22 |
status = upload_and_index(files, title, author, db_name)
|
23 |
logging.info(f"Upload completato: {status}")
|
24 |
-
return status
|
25 |
except Exception as e:
|
26 |
logging.error(f"Errore durante l'upload: {str(e)}")
|
27 |
return f"Errore: {str(e)}"
|
@@ -50,8 +49,7 @@ def create_document_management_tab(update_all_dropdowns):
|
|
50 |
)
|
51 |
db_name_upload = gr.Dropdown(
|
52 |
choices=databases,
|
53 |
-
label="Seleziona Database"
|
54 |
-
value="default_db"
|
55 |
)
|
56 |
|
57 |
with gr.Row():
|
@@ -65,8 +63,7 @@ def create_document_management_tab(update_all_dropdowns):
|
|
65 |
with gr.Row():
|
66 |
db_name_list = gr.Dropdown(
|
67 |
choices=databases,
|
68 |
-
label="Database"
|
69 |
-
value="default_db"
|
70 |
)
|
71 |
list_button = gr.Button("Lista File")
|
72 |
list_output = gr.Textbox(label="File nel Database")
|
@@ -80,14 +77,7 @@ def create_document_management_tab(update_all_dropdowns):
|
|
80 |
upload_button.click(
|
81 |
fn=upload_and_index_callback,
|
82 |
inputs=[file_input, title_input, author_input, db_name_upload],
|
83 |
-
outputs=upload_output
|
84 |
-
).then(
|
85 |
-
fn=update_all_dropdowns, # Usa la funzione globale
|
86 |
-
outputs=[db_name_upload, db_name_list]
|
87 |
-
).then(
|
88 |
-
fn=list_files_callback,
|
89 |
-
inputs=[db_name_list],
|
90 |
-
outputs=list_output
|
91 |
)
|
92 |
|
93 |
list_button.click(
|
@@ -101,7 +91,7 @@ def create_document_management_tab(update_all_dropdowns):
|
|
101 |
inputs=[delete_file_input, db_name_list],
|
102 |
outputs=delete_file_output
|
103 |
).then(
|
104 |
-
fn=
|
105 |
outputs=[db_name_upload, db_name_list]
|
106 |
).then(
|
107 |
fn=list_files_callback,
|
@@ -109,4 +99,4 @@ def create_document_management_tab(update_all_dropdowns):
|
|
109 |
outputs=list_output
|
110 |
)
|
111 |
|
112 |
-
return
|
|
|
3 |
from app.document_handling import upload_and_index, list_indexed_files, delete_file_from_database
|
4 |
from app.functions.database_handling import list_databases
|
5 |
|
6 |
+
def create_document_management_tab():
|
7 |
"""Crea il tab 'Gestione Documenti' dell'interfaccia Gradio."""
|
8 |
|
9 |
+
def update_dropdowns():
|
10 |
"""Aggiorna localmente i dropdown con la lista aggiornata dei database."""
|
11 |
+
updated_dbs = list_databases()
|
12 |
+
logging.info(f"Aggiornamento dropdown con databases: {updated_dbs}")
|
13 |
+
return [
|
14 |
+
gr.update(choices=updated_dbs),
|
15 |
+
gr.update(choices=updated_dbs)
|
16 |
]
|
|
|
17 |
|
18 |
def upload_and_index_callback(files, title, author, db_name):
|
19 |
"""Carica e indicizza i documenti, quindi aggiorna la lista dei file."""
|
20 |
try:
|
21 |
status = upload_and_index(files, title, author, db_name)
|
22 |
logging.info(f"Upload completato: {status}")
|
23 |
+
return status, update_dropdowns()[0], update_dropdowns()[1]
|
24 |
except Exception as e:
|
25 |
logging.error(f"Errore durante l'upload: {str(e)}")
|
26 |
return f"Errore: {str(e)}"
|
|
|
49 |
)
|
50 |
db_name_upload = gr.Dropdown(
|
51 |
choices=databases,
|
52 |
+
label="Seleziona Database"
|
|
|
53 |
)
|
54 |
|
55 |
with gr.Row():
|
|
|
63 |
with gr.Row():
|
64 |
db_name_list = gr.Dropdown(
|
65 |
choices=databases,
|
66 |
+
label="Database"
|
|
|
67 |
)
|
68 |
list_button = gr.Button("Lista File")
|
69 |
list_output = gr.Textbox(label="File nel Database")
|
|
|
77 |
upload_button.click(
|
78 |
fn=upload_and_index_callback,
|
79 |
inputs=[file_input, title_input, author_input, db_name_upload],
|
80 |
+
outputs=[upload_output, db_name_upload, db_name_list]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
)
|
82 |
|
83 |
list_button.click(
|
|
|
91 |
inputs=[delete_file_input, db_name_list],
|
92 |
outputs=delete_file_output
|
93 |
).then(
|
94 |
+
fn=update_dropdowns,
|
95 |
outputs=[db_name_upload, db_name_list]
|
96 |
).then(
|
97 |
fn=list_files_callback,
|
|
|
99 |
outputs=list_output
|
100 |
)
|
101 |
|
102 |
+
return {"upload": db_name_upload, "list": db_name_list}
|
ui/management_tabs.py
ADDED
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import logging
|
3 |
+
from app.document_handling import upload_and_index, list_indexed_files, delete_file_from_database
|
4 |
+
from app.functions.database_handling import (
|
5 |
+
create_database,
|
6 |
+
modify_database,
|
7 |
+
delete_database,
|
8 |
+
list_databases
|
9 |
+
)
|
10 |
+
|
11 |
+
class ManagementTabs:
|
12 |
+
def __init__(self, update_all_dropdowns):
|
13 |
+
self.update_all_dropdowns = update_all_dropdowns
|
14 |
+
self.databases = list_databases()
|
15 |
+
|
16 |
+
def create_tabs(self):
|
17 |
+
with gr.Tabs():
|
18 |
+
self._create_db_management_tab()
|
19 |
+
self._create_document_management_tab()
|
20 |
+
|
21 |
+
def _create_db_management_tab(self):
|
22 |
+
with gr.Tab("Gestione Database"):
|
23 |
+
gr.Markdown("## Operazioni sui Database")
|
24 |
+
|
25 |
+
with gr.Row():
|
26 |
+
# Creazione Database
|
27 |
+
with gr.Column():
|
28 |
+
gr.Markdown("### Crea Database")
|
29 |
+
self.db_name_input = gr.Textbox(label="Nome Nuovo Database")
|
30 |
+
self.create_db_button = gr.Button("Crea Database")
|
31 |
+
self.create_output = gr.Textbox(label="Stato Creazione")
|
32 |
+
|
33 |
+
# Modifica Database
|
34 |
+
with gr.Column():
|
35 |
+
gr.Markdown("### Rinomina Database")
|
36 |
+
self.modify_db_old_name = gr.Dropdown(
|
37 |
+
choices=self.databases,
|
38 |
+
label="Database da Rinominare"
|
39 |
+
)
|
40 |
+
self.modify_db_new_name = gr.Textbox(label="Nuovo Nome")
|
41 |
+
self.modify_db_button = gr.Button("Rinomina Database")
|
42 |
+
self.modify_output = gr.Textbox(label="Stato Modifica")
|
43 |
+
|
44 |
+
# Eliminazione Database
|
45 |
+
with gr.Column():
|
46 |
+
gr.Markdown("### Elimina Database")
|
47 |
+
self.delete_db_dropdown = gr.Dropdown(
|
48 |
+
choices=self.databases,
|
49 |
+
label="Database da Eliminare"
|
50 |
+
)
|
51 |
+
self.delete_db_button = gr.Button("Elimina Database")
|
52 |
+
self.delete_output = gr.Textbox(label="Stato Eliminazione")
|
53 |
+
|
54 |
+
self._setup_db_events()
|
55 |
+
|
56 |
+
def _create_document_management_tab(self):
|
57 |
+
with gr.Tab("Gestione Documenti"):
|
58 |
+
with gr.Column():
|
59 |
+
# Upload Documenti
|
60 |
+
gr.Markdown("### Carica Documenti")
|
61 |
+
with gr.Row():
|
62 |
+
self.file_input = gr.File(
|
63 |
+
label="Carica i tuoi documenti",
|
64 |
+
file_types=[".txt", ".pdf", ".docx"],
|
65 |
+
file_count="multiple"
|
66 |
+
)
|
67 |
+
self.db_name_upload = gr.Dropdown(
|
68 |
+
choices=self.databases,
|
69 |
+
label="Seleziona Database",
|
70 |
+
value="default_db"
|
71 |
+
)
|
72 |
+
|
73 |
+
with gr.Row():
|
74 |
+
self.title_input = gr.Textbox(label="Titolo del documento")
|
75 |
+
self.author_input = gr.Textbox(label="Autore")
|
76 |
+
|
77 |
+
self.upload_button = gr.Button("Indicizza Documenti")
|
78 |
+
self.upload_output = gr.Textbox(label="Stato Upload")
|
79 |
+
|
80 |
+
# Gestione File
|
81 |
+
self._setup_file_management()
|
82 |
+
|
83 |
+
self._setup_document_events()
|
84 |
+
|
85 |
+
def _setup_file_management(self):
|
86 |
+
gr.Markdown("### Gestione File")
|
87 |
+
with gr.Row():
|
88 |
+
self.db_name_list = gr.Dropdown(
|
89 |
+
choices=self.databases,
|
90 |
+
label="Database",
|
91 |
+
value="default_db"
|
92 |
+
)
|
93 |
+
self.list_button = gr.Button("Lista File")
|
94 |
+
self.list_output = gr.Textbox(label="File nel Database")
|
95 |
+
|
96 |
+
with gr.Row():
|
97 |
+
self.delete_file_input = gr.Textbox(label="Nome File da Eliminare")
|
98 |
+
self.delete_file_button = gr.Button("Elimina File")
|
99 |
+
self.delete_file_output = gr.Textbox(label="Stato Eliminazione")
|
100 |
+
|
101 |
+
def _setup_db_events(self):
|
102 |
+
# Eventi per la gestione del database
|
103 |
+
self.create_db_button.click(
|
104 |
+
fn=create_database,
|
105 |
+
inputs=self.db_name_input,
|
106 |
+
outputs=self.create_output
|
107 |
+
).then(fn=self.update_all_dropdowns)
|
108 |
+
|
109 |
+
self.modify_db_button.click(
|
110 |
+
fn=modify_database,
|
111 |
+
inputs=[self.modify_db_old_name, self.modify_db_new_name],
|
112 |
+
outputs=self.modify_output
|
113 |
+
).then(fn=self.update_all_dropdowns)
|
114 |
+
|
115 |
+
self.delete_db_button.click(
|
116 |
+
fn=delete_database,
|
117 |
+
inputs=self.delete_db_dropdown,
|
118 |
+
outputs=self.delete_output
|
119 |
+
).then(fn=self.update_all_dropdowns)
|
120 |
+
|
121 |
+
def _setup_document_events(self):
|
122 |
+
# Eventi per la gestione dei documenti
|
123 |
+
self.upload_button.click(
|
124 |
+
fn=self._upload_and_index_callback,
|
125 |
+
inputs=[self.file_input, self.title_input, self.author_input, self.db_name_upload],
|
126 |
+
outputs=self.upload_output
|
127 |
+
).then(fn=self.update_all_dropdowns).then(
|
128 |
+
fn=self._list_files_callback,
|
129 |
+
inputs=[self.db_name_list],
|
130 |
+
outputs=self.list_output
|
131 |
+
)
|
132 |
+
|
133 |
+
self.list_button.click(
|
134 |
+
fn=self._list_files_callback,
|
135 |
+
inputs=[self.db_name_list],
|
136 |
+
outputs=self.list_output
|
137 |
+
)
|
138 |
+
|
139 |
+
self.delete_file_button.click(
|
140 |
+
fn=self._delete_file_callback,
|
141 |
+
inputs=[self.delete_file_input, self.db_name_list],
|
142 |
+
outputs=self.delete_file_output
|
143 |
+
).then(fn=self.update_all_dropdowns)
|
144 |
+
|
145 |
+
def _upload_and_index_callback(self, files, title, author, db_name):
|
146 |
+
try:
|
147 |
+
status = upload_and_index(files, title, author, db_name)
|
148 |
+
logging.info(f"Upload completato: {status}")
|
149 |
+
return status
|
150 |
+
except Exception as e:
|
151 |
+
logging.error(f"Errore durante l'upload: {str(e)}")
|
152 |
+
return f"Errore: {str(e)}"
|
153 |
+
|
154 |
+
def _list_files_callback(self, db_name):
|
155 |
+
return list_indexed_files(db_name)
|
156 |
+
|
157 |
+
def _delete_file_callback(self, file_name, db_name):
|
158 |
+
return delete_file_from_database(file_name, db_name)
|
159 |
+
|
160 |
+
def create_management_tabs(update_all_dropdowns):
|
161 |
+
tabs = ManagementTabs(update_all_dropdowns)
|
162 |
+
tabs.create_tabs()
|
163 |
+
return tabs
|