Update app.py
Browse files
app.py
CHANGED
|
@@ -45,6 +45,8 @@ _ = load_dotenv(find_dotenv())
|
|
| 45 |
##############################################
|
| 46 |
#nur bei ersten Anfrage splitten der Dokumente - um die Vektordatenbank entsprechend zu füllen
|
| 47 |
splittet = False
|
|
|
|
|
|
|
| 48 |
|
| 49 |
##################################################
|
| 50 |
#Für MongoDB statt Chroma als Vektorstore
|
|
@@ -121,8 +123,40 @@ general_assistant_suche= openai_assistant_suche(client)
|
|
| 121 |
|
| 122 |
##############################################
|
| 123 |
#wenn löschen Button geklickt
|
| 124 |
-
def clear_all():
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
##############################################
|
| 128 |
#History - die Frage oder das File eintragen...
|
|
@@ -499,7 +533,6 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
| 499 |
# history parallel zu chatbot speichern - da in chatbot bei Bildern zum Anzeigen in der GUI die Bilder speziell formatiert werden,
|
| 500 |
# für die Übergabe an die ki aber der Pfad zum Bild behalten werden muss - was in der history der Fall ist!
|
| 501 |
history = gr.State([])
|
| 502 |
-
long_history = gr.State([])
|
| 503 |
#damit der Prompt auch nach dem upload in die History noch für predicts_args verfügbar ist
|
| 504 |
user_question = gr.State("")
|
| 505 |
#damit der Prompt auch nach dem upload in die History noch für predicts_args verfügbar ist
|
|
@@ -538,6 +571,10 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
| 538 |
|
| 539 |
with gr.Column():
|
| 540 |
with gr.Column(min_width=50, scale=1):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
with gr.Tab(label="Parameter Einstellung"):
|
| 542 |
#gr.Markdown("# Parameters")
|
| 543 |
rag_option = gr.Radio(["Aus", "An"], label="LI Erweiterungen (RAG)", value = "Aus")
|
|
@@ -662,12 +699,11 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
| 662 |
predict_event1 = user_input.submit(**transfer_input_args, queue=False,).then(**predict_args)
|
| 663 |
predict_event2 = submitBtn.click(**transfer_input_args, queue=False,).then(**predict_args)
|
| 664 |
predict_event3 = upload.upload(file_anzeigen, [upload], [image_display, image_display, attached_file] ) #.then(**predict_args)
|
| 665 |
-
emptyBtn.click(clear_all, [], [attached_file, image_display, history])
|
| 666 |
#Bild Anzeige neben dem Button wieder entfernen oder austauschen..
|
| 667 |
image_display.select(file_loeschen, [], [attached_file, image_display])
|
| 668 |
-
|
| 669 |
-
|
| 670 |
-
download_button = gr.Button("Download")
|
| 671 |
|
| 672 |
#Berechnung oder Ausgabe anhalten (kann danach fortgesetzt werden)
|
| 673 |
cancelBtn.click(cancel_outputing, [], [status_display], cancels=[predict_event1,predict_event2, predict_event3])
|
|
|
|
| 45 |
##############################################
|
| 46 |
#nur bei ersten Anfrage splitten der Dokumente - um die Vektordatenbank entsprechend zu füllen
|
| 47 |
splittet = False
|
| 48 |
+
#für eine Session werden die chatsverläufe hier gespeichert...
|
| 49 |
+
chats={}
|
| 50 |
|
| 51 |
##################################################
|
| 52 |
#Für MongoDB statt Chroma als Vektorstore
|
|
|
|
| 123 |
|
| 124 |
##############################################
|
| 125 |
#wenn löschen Button geklickt
|
| 126 |
+
def clear_all(history):
|
| 127 |
+
global chats
|
| 128 |
+
dic_history = {schluessel: wert for schluessel, wert in history}
|
| 129 |
+
summary = "\n".join(f'{schluessel}: {wert}' for schluessel, wert in dic_history.items())
|
| 130 |
+
|
| 131 |
+
id_neu = len(chats)+1
|
| 132 |
+
#chats ist ein dictionary
|
| 133 |
+
chats[id_neu]= summary
|
| 134 |
+
|
| 135 |
+
return None, gr.Image(visible=False), [], gr.CheckboxGroup(label="Wähle Chats zum Download", choices=update_chat_options())
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
#########################################
|
| 139 |
+
# Funktionen, um vergangene Chats anzuzeigen und zum Download anzubieten
|
| 140 |
+
def update_chat_options():
|
| 141 |
+
global chats
|
| 142 |
+
# Diese Funktion aktualisiert die verfügbaren Chat-Optionen
|
| 143 |
+
if chats != {}:
|
| 144 |
+
return list(chats.keys())
|
| 145 |
+
else:
|
| 146 |
+
return None
|
| 147 |
+
|
| 148 |
+
def download_chats(selected_chats):
|
| 149 |
+
global chats
|
| 150 |
+
if chats != {}:
|
| 151 |
+
# Diese Funktion bereitet die ausgewählten Chats zum Download vor
|
| 152 |
+
data = "\n\n".join(chats[chat] for chat in selected_chats)
|
| 153 |
+
# Erstelle eine temporäre Datei mit den Chat-Daten
|
| 154 |
+
with tempfile.NamedTemporaryFile(delete=False, mode='w', suffix='.txt') as tmp:
|
| 155 |
+
tmp.write(data)
|
| 156 |
+
tmp_path = tmp.name
|
| 157 |
+
return gr.File(tmp_path, label="Download-Chat", visible = True)
|
| 158 |
+
else:
|
| 159 |
+
return gr.File(visible=False)
|
| 160 |
|
| 161 |
##############################################
|
| 162 |
#History - die Frage oder das File eintragen...
|
|
|
|
| 533 |
# history parallel zu chatbot speichern - da in chatbot bei Bildern zum Anzeigen in der GUI die Bilder speziell formatiert werden,
|
| 534 |
# für die Übergabe an die ki aber der Pfad zum Bild behalten werden muss - was in der history der Fall ist!
|
| 535 |
history = gr.State([])
|
|
|
|
| 536 |
#damit der Prompt auch nach dem upload in die History noch für predicts_args verfügbar ist
|
| 537 |
user_question = gr.State("")
|
| 538 |
#damit der Prompt auch nach dem upload in die History noch für predicts_args verfügbar ist
|
|
|
|
| 571 |
|
| 572 |
with gr.Column():
|
| 573 |
with gr.Column(min_width=50, scale=1):
|
| 574 |
+
with gr.Tab(label="Chats ..."):
|
| 575 |
+
chat_selector = gr.CheckboxGroup(label="Wähle Chats zum Download", choices=update_chat_options())
|
| 576 |
+
download_button = gr.Button("Download ausgewählte Chats")
|
| 577 |
+
file_download = gr.File(label="Download-Chat", visible=False)
|
| 578 |
with gr.Tab(label="Parameter Einstellung"):
|
| 579 |
#gr.Markdown("# Parameters")
|
| 580 |
rag_option = gr.Radio(["Aus", "An"], label="LI Erweiterungen (RAG)", value = "Aus")
|
|
|
|
| 699 |
predict_event1 = user_input.submit(**transfer_input_args, queue=False,).then(**predict_args)
|
| 700 |
predict_event2 = submitBtn.click(**transfer_input_args, queue=False,).then(**predict_args)
|
| 701 |
predict_event3 = upload.upload(file_anzeigen, [upload], [image_display, image_display, attached_file] ) #.then(**predict_args)
|
| 702 |
+
emptyBtn.click(clear_all, [history], [attached_file, image_display, history, chat_selector])
|
| 703 |
#Bild Anzeige neben dem Button wieder entfernen oder austauschen..
|
| 704 |
image_display.select(file_loeschen, [], [attached_file, image_display])
|
| 705 |
+
download_button.click(fn=download_chats, inputs=chat_selector, outputs=file_download)
|
| 706 |
+
|
|
|
|
| 707 |
|
| 708 |
#Berechnung oder Ausgabe anhalten (kann danach fortgesetzt werden)
|
| 709 |
cancelBtn.click(cancel_outputing, [], [status_display], cancels=[predict_event1,predict_event2, predict_event3])
|