Update app.py
Browse files
app.py
CHANGED
|
@@ -133,7 +133,9 @@ def clear_all(history):
|
|
| 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 |
-
|
|
|
|
|
|
|
| 137 |
#schlagwort finden zu dem chatverlauf
|
| 138 |
headers, payload = process_chatverlauf(summary, MODEL_NAME, OAI_API_KEY)
|
| 139 |
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
|
|
@@ -141,18 +143,25 @@ def clear_all(history):
|
|
| 141 |
data = response.json()
|
| 142 |
# Den "content" auswählen, da dort die Antwort der Ki enthalten ist
|
| 143 |
result = data['choices'][0]['message']['content']
|
| 144 |
-
|
| 145 |
#Alternatives Model umd schlagworte zu finden
|
| 146 |
llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0.5, "max_length": 128})
|
| 147 |
result = process_chatverlauf_hf(history,llm)
|
| 148 |
-
"""
|
| 149 |
#chat hinzufügen zu den chatverläufen und in GUI anzeigen
|
| 150 |
id_neu = str(len(chats)+1) + "_" + result
|
| 151 |
#chats ist ein dictionary
|
| 152 |
chats[id_neu]= summary
|
|
|
|
|
|
|
| 153 |
#falls file mit summay für download existiert hat: das zunächst löschen
|
| 154 |
cleanup(file_path_download)
|
| 155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
|
| 157 |
|
| 158 |
#########################################
|
|
@@ -557,9 +566,10 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
| 557 |
with gr.Column():
|
| 558 |
with gr.Column(min_width=50, scale=1):
|
| 559 |
with gr.Tab(label="Chats ..."):
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
|
|
|
| 563 |
|
| 564 |
with gr.Tab(label="Parameter Einstellung"):
|
| 565 |
#gr.Markdown("# Parameters")
|
|
@@ -682,10 +692,10 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
| 682 |
predict_event1 = user_input.submit(**transfer_input_args, queue=False,).then(**predict_args)
|
| 683 |
predict_event2 = submitBtn.click(**transfer_input_args, queue=False,).then(**predict_args)
|
| 684 |
predict_event3 = upload.upload(file_anzeigen, [upload], [image_display, image_display, attached_file] ) #.then(**predict_args)
|
| 685 |
-
emptyBtn.click(clear_all, [history], [attached_file, image_display, history,
|
| 686 |
#Bild Anzeige neben dem Button wieder entfernen oder austauschen..
|
| 687 |
image_display.select(file_loeschen, [], [attached_file, image_display])
|
| 688 |
-
download_button.click(fn=download_chats, inputs=chat_selector, outputs=[file_download])
|
| 689 |
|
| 690 |
|
| 691 |
#Berechnung oder Ausgabe anhalten (kann danach fortgesetzt werden)
|
|
|
|
| 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 |
+
|
| 137 |
+
#zur Zeit nicht in Gebracht, da das Anzeigen der chatverläufe für alle TN sichtbar ist
|
| 138 |
+
"""
|
| 139 |
#schlagwort finden zu dem chatverlauf
|
| 140 |
headers, payload = process_chatverlauf(summary, MODEL_NAME, OAI_API_KEY)
|
| 141 |
response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload)
|
|
|
|
| 143 |
data = response.json()
|
| 144 |
# Den "content" auswählen, da dort die Antwort der Ki enthalten ist
|
| 145 |
result = data['choices'][0]['message']['content']
|
| 146 |
+
|
| 147 |
#Alternatives Model umd schlagworte zu finden
|
| 148 |
llm = HuggingFaceHub(repo_id=repo_id, model_kwargs={"temperature": 0.5, "max_length": 128})
|
| 149 |
result = process_chatverlauf_hf(history,llm)
|
|
|
|
| 150 |
#chat hinzufügen zu den chatverläufen und in GUI anzeigen
|
| 151 |
id_neu = str(len(chats)+1) + "_" + result
|
| 152 |
#chats ist ein dictionary
|
| 153 |
chats[id_neu]= summary
|
| 154 |
+
"""
|
| 155 |
+
|
| 156 |
#falls file mit summay für download existiert hat: das zunächst löschen
|
| 157 |
cleanup(file_path_download)
|
| 158 |
+
#den aktuellen Chatverlauf zum Download bereitstellen:
|
| 159 |
+
if chats != {}:
|
| 160 |
+
chats.append(summary) #noch nicht im Einsatz, aber hier werden alle Chats einer Sitzung gespeichert
|
| 161 |
+
file_path_download = save_and_download(summary)
|
| 162 |
+
|
| 163 |
+
return None, gr.Image(visible=False), [], file_path_download
|
| 164 |
+
|
| 165 |
|
| 166 |
|
| 167 |
#########################################
|
|
|
|
| 566 |
with gr.Column():
|
| 567 |
with gr.Column(min_width=50, scale=1):
|
| 568 |
with gr.Tab(label="Chats ..."):
|
| 569 |
+
#Geht nicht, da für alle gleichzeitig sichtbar
|
| 570 |
+
#chat_selector = gr.CheckboxGroup(label="", choices=update_chat_options())
|
| 571 |
+
#download_button = gr.Button("Download ausgewählte Chats")
|
| 572 |
+
file_download = gr.File(label="Download-Chat", visible=True, file_count="multiple")
|
| 573 |
|
| 574 |
with gr.Tab(label="Parameter Einstellung"):
|
| 575 |
#gr.Markdown("# Parameters")
|
|
|
|
| 692 |
predict_event1 = user_input.submit(**transfer_input_args, queue=False,).then(**predict_args)
|
| 693 |
predict_event2 = submitBtn.click(**transfer_input_args, queue=False,).then(**predict_args)
|
| 694 |
predict_event3 = upload.upload(file_anzeigen, [upload], [image_display, image_display, attached_file] ) #.then(**predict_args)
|
| 695 |
+
emptyBtn.click(clear_all, [history], [attached_file, image_display, history, file_download])
|
| 696 |
#Bild Anzeige neben dem Button wieder entfernen oder austauschen..
|
| 697 |
image_display.select(file_loeschen, [], [attached_file, image_display])
|
| 698 |
+
#download_button.click(fn=download_chats, inputs=chat_selector, outputs=[file_download])
|
| 699 |
|
| 700 |
|
| 701 |
#Berechnung oder Ausgabe anhalten (kann danach fortgesetzt werden)
|