Update app.py
Browse files
    	
        app.py
    CHANGED
    
    | 
         @@ -47,7 +47,8 @@ _ = load_dotenv(find_dotenv()) 
     | 
|
| 47 | 
         
             
            #nur bei ersten Anfrage splitten der Dokumente - um die Vektordatenbank entsprechend zu füllen
         
     | 
| 48 | 
         
             
            splittet = False
         
     | 
| 49 | 
         
             
            #für eine Session werden die chatsverläufe hier gespeichert...
         
     | 
| 50 | 
         
            -
             
     | 
| 
         | 
|
| 51 | 
         | 
| 52 | 
         
             
            #############################################
         
     | 
| 53 | 
         
             
            # Allgemeine Konstanten
         
     | 
| 
         @@ -129,8 +130,7 @@ general_assistant_suche= openai_assistant_suche(client) 
     | 
|
| 129 | 
         | 
| 130 | 
         
             
            ##############################################
         
     | 
| 131 | 
         
             
            #wenn löschen Button geklickt
         
     | 
| 132 | 
         
            -
            def clear_all(history, uploaded_file_paths):
         
     | 
| 133 | 
         
            -
                global chats
         
     | 
| 134 | 
         
             
                dic_history = {schluessel: wert for schluessel, wert in history}
         
     | 
| 135 | 
         
             
                summary = "\n\n".join(f'{schluessel}: \n  {wert}' for schluessel, wert in dic_history.items())
         
     | 
| 136 | 
         | 
| 
         @@ -163,7 +163,7 @@ def clear_all(history, uploaded_file_paths): 
     | 
|
| 163 | 
         
             
                #die session variable in gradio erweitern und alle fliepath neu in das gr.File hochladen
         
     | 
| 164 | 
         
             
                uploaded_file_paths=  uploaded_file_paths + [file_path_download]
         
     | 
| 165 | 
         | 
| 166 | 
         
            -
                return None, gr.Image(visible=False), uploaded_file_paths, [], gr.File(uploaded_file_paths, label="Download-Chatverläufe",  visible=True, interactive = False) 
         
     | 
| 167 | 
         | 
| 168 | 
         | 
| 169 | 
         | 
| 
         @@ -530,6 +530,8 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo: 
     | 
|
| 530 | 
         
             
                # für die Übergabe an die ki aber der Pfad zum Bild behalten werden muss - was in der history der Fall ist!
         
     | 
| 531 | 
         
             
                history = gr.State([])
         
     | 
| 532 | 
         
             
                uploaded_file_paths= gr.State([])
         
     | 
| 
         | 
|
| 
         | 
|
| 533 | 
         
             
                #damit der Prompt auch nach dem upload in die History noch für predicts_args verfügbar ist
         
     | 
| 534 | 
         
             
                user_question = gr.State("")
         
     | 
| 535 | 
         
             
                #damit der Prompt auch nach dem upload in die History noch für predicts_args verfügbar ist
         
     | 
| 
         @@ -695,7 +697,7 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo: 
     | 
|
| 695 | 
         
             
                predict_event1 = user_input.submit(**transfer_input_args, queue=False,).then(**predict_args)
         
     | 
| 696 | 
         
             
                predict_event2 = submitBtn.click(**transfer_input_args, queue=False,).then(**predict_args)
         
     | 
| 697 | 
         
             
                predict_event3 = upload.upload(file_anzeigen, [upload], [image_display, image_display, attached_file] ) #.then(**predict_args)
         
     | 
| 698 | 
         
            -
                emptyBtn.click(clear_all, [history, uploaded_file_paths], [attached_file, image_display, uploaded_file_paths, history, file_download])
         
     | 
| 699 | 
         
             
                #Bild Anzeige neben dem Button wieder entfernen oder austauschen..
         
     | 
| 700 | 
         
             
                image_display.select(file_loeschen, [], [attached_file, image_display])
         
     | 
| 701 | 
         
             
                #download_button.click(fn=download_chats, inputs=chat_selector, outputs=[file_download])
         
     | 
| 
         | 
|
| 47 | 
         
             
            #nur bei ersten Anfrage splitten der Dokumente - um die Vektordatenbank entsprechend zu füllen
         
     | 
| 48 | 
         
             
            splittet = False
         
     | 
| 49 | 
         
             
            #für eine Session werden die chatsverläufe hier gespeichert...
         
     | 
| 50 | 
         
            +
            #geht hier nicht, da so für alle user sicherbar - muss für jeden user einzeln in gr-State gespeichert werden
         
     | 
| 51 | 
         
            +
            #chats={}
         
     | 
| 52 | 
         | 
| 53 | 
         
             
            #############################################
         
     | 
| 54 | 
         
             
            # Allgemeine Konstanten
         
     | 
| 
         | 
|
| 130 | 
         | 
| 131 | 
         
             
            ##############################################
         
     | 
| 132 | 
         
             
            #wenn löschen Button geklickt
         
     | 
| 133 | 
         
            +
            def clear_all(history, uploaded_file_paths, chats):
         
     | 
| 
         | 
|
| 134 | 
         
             
                dic_history = {schluessel: wert for schluessel, wert in history}
         
     | 
| 135 | 
         
             
                summary = "\n\n".join(f'{schluessel}: \n  {wert}' for schluessel, wert in dic_history.items())
         
     | 
| 136 | 
         | 
| 
         | 
|
| 163 | 
         
             
                #die session variable in gradio erweitern und alle fliepath neu in das gr.File hochladen
         
     | 
| 164 | 
         
             
                uploaded_file_paths=  uploaded_file_paths + [file_path_download]
         
     | 
| 165 | 
         | 
| 166 | 
         
            +
                return None, gr.Image(visible=False), uploaded_file_paths, [], gr.File(uploaded_file_paths, label="Download-Chatverläufe",  visible=True, interactive = False) , chats
         
     | 
| 167 | 
         | 
| 168 | 
         | 
| 169 | 
         | 
| 
         | 
|
| 530 | 
         
             
                # für die Übergabe an die ki aber der Pfad zum Bild behalten werden muss - was in der history der Fall ist!
         
     | 
| 531 | 
         
             
                history = gr.State([])
         
     | 
| 532 | 
         
             
                uploaded_file_paths= gr.State([])
         
     | 
| 533 | 
         
            +
                #alle chats einer Session sammeln
         
     | 
| 534 | 
         
            +
                chats = gr.State({})
         
     | 
| 535 | 
         
             
                #damit der Prompt auch nach dem upload in die History noch für predicts_args verfügbar ist
         
     | 
| 536 | 
         
             
                user_question = gr.State("")
         
     | 
| 537 | 
         
             
                #damit der Prompt auch nach dem upload in die History noch für predicts_args verfügbar ist
         
     | 
| 
         | 
|
| 697 | 
         
             
                predict_event1 = user_input.submit(**transfer_input_args, queue=False,).then(**predict_args)
         
     | 
| 698 | 
         
             
                predict_event2 = submitBtn.click(**transfer_input_args, queue=False,).then(**predict_args)
         
     | 
| 699 | 
         
             
                predict_event3 = upload.upload(file_anzeigen, [upload], [image_display, image_display, attached_file] ) #.then(**predict_args)
         
     | 
| 700 | 
         
            +
                emptyBtn.click(clear_all, [history, uploaded_file_paths, chats], [attached_file, image_display, uploaded_file_paths, history, file_download, chats])
         
     | 
| 701 | 
         
             
                #Bild Anzeige neben dem Button wieder entfernen oder austauschen..
         
     | 
| 702 | 
         
             
                image_display.select(file_loeschen, [], [attached_file, image_display])
         
     | 
| 703 | 
         
             
                #download_button.click(fn=download_chats, inputs=chat_selector, outputs=[file_download])
         
     |