Update app.py
Browse files
app.py
CHANGED
|
@@ -126,6 +126,8 @@ def clear_all():
|
|
| 126 |
|
| 127 |
##############################################
|
| 128 |
#History - die Frage oder das File eintragen...
|
|
|
|
|
|
|
| 129 |
def add_text(chatbot, history, prompt, file, file_history):
|
| 130 |
if (file == None):
|
| 131 |
chatbot = chatbot +[(prompt, None)]
|
|
@@ -267,6 +269,7 @@ def generate_auswahl(prompt, file, file_history, chatbot, history, rag_option, m
|
|
| 267 |
#aber nur, wenn es noch nicht geshehen ist (splittet = False)
|
| 268 |
#falls schon ein File hochgeladen wurde, ist es in history_file gespeichert - falls ein neues File hochgeladen wurde, wird es anschließend neu gesetzt
|
| 269 |
neu_file = file_history
|
|
|
|
| 270 |
if (rag_option == "An"):
|
| 271 |
#muss nur einmal ausgeführt werden...
|
| 272 |
if not splittet:
|
|
@@ -284,19 +287,20 @@ def generate_auswahl(prompt, file, file_history, chatbot, history, rag_option, m
|
|
| 284 |
result, status = generate_text(prompt, chatbot, history, rag_option, model_option, openai_api_key, db, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,)
|
| 285 |
history = history + [[prompt, result]]
|
| 286 |
else:
|
| 287 |
-
#Es wurde ein File angehängt -> wenn prompt dazu, das Bild analysieren
|
|
|
|
| 288 |
if (file != None):
|
| 289 |
# file_history wird neu gesetzt in der Rückgabe dieser Funktion...
|
| 290 |
neu_file = file
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
#geht nur über spezielle OpenAI-Schnittstelle...
|
| 294 |
ext = analyze_file(neu_file)
|
| 295 |
if (ext == "png" or ext == "PNG" or ext == "jpg" or ext == "jpeg" or ext == "JPG" or ext == "JPEG"):
|
| 296 |
result= generate_text_zu_bild(neu_file, prompt, k, rag_option, chatbot, history, db)
|
| 297 |
else:
|
| 298 |
result = generate_text_zu_doc(_neu_file, prompt, k, rag_option, chatbot, history, db)
|
| 299 |
-
|
|
|
|
| 300 |
if (file != None):
|
| 301 |
history = history + [[(file,), None],[prompt, result]]
|
| 302 |
else:
|
|
@@ -344,7 +348,6 @@ def generate_bild(prompt, chatbot, model_option_zeichnen='HuggingFace', temperat
|
|
| 344 |
def generate_text_zu_bild(file, prompt, k, rag_option, chatbot, history, db):
|
| 345 |
global splittet
|
| 346 |
print("Text mit Bild ..............................")
|
| 347 |
-
print(file)
|
| 348 |
prompt_neu = generate_prompt_with_history(prompt, history)
|
| 349 |
if (rag_option == "An"):
|
| 350 |
print("Bild mit RAG..............................")
|
|
@@ -369,7 +372,7 @@ def generate_text_zu_doc(file, prompt, k, rag_option, chatbot, history, db):
|
|
| 369 |
global splittet
|
| 370 |
print("text mit doc ..............................")
|
| 371 |
|
| 372 |
-
prompt_neu = prompt
|
| 373 |
if (rag_option == "An"):
|
| 374 |
print("Doc mit RAG..............................")
|
| 375 |
neu_text_mit_chunks = rag_chain2(prompt, db, k)
|
|
|
|
| 126 |
|
| 127 |
##############################################
|
| 128 |
#History - die Frage oder das File eintragen...
|
| 129 |
+
#in history_file ist ein file gespeichert, falls voher im Verlauf schon ein File hochgeladen wurde.
|
| 130 |
+
#wird ein neuer File hochgeladen, so wird history_fiel dadurch ersetzt
|
| 131 |
def add_text(chatbot, history, prompt, file, file_history):
|
| 132 |
if (file == None):
|
| 133 |
chatbot = chatbot +[(prompt, None)]
|
|
|
|
| 269 |
#aber nur, wenn es noch nicht geshehen ist (splittet = False)
|
| 270 |
#falls schon ein File hochgeladen wurde, ist es in history_file gespeichert - falls ein neues File hochgeladen wurde, wird es anschließend neu gesetzt
|
| 271 |
neu_file = file_history
|
| 272 |
+
|
| 273 |
if (rag_option == "An"):
|
| 274 |
#muss nur einmal ausgeführt werden...
|
| 275 |
if not splittet:
|
|
|
|
| 287 |
result, status = generate_text(prompt, chatbot, history, rag_option, model_option, openai_api_key, db, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,)
|
| 288 |
history = history + [[prompt, result]]
|
| 289 |
else:
|
| 290 |
+
#Es wurde ein File neu angehängt -> wenn prompt dazu, das Bild analysieren
|
| 291 |
+
#das history_fiel muss neu gesetzt werden
|
| 292 |
if (file != None):
|
| 293 |
# file_history wird neu gesetzt in der Rückgabe dieser Funktion...
|
| 294 |
neu_file = file
|
| 295 |
+
|
| 296 |
+
#herausfinden, ob Bild oder Dokument...
|
|
|
|
| 297 |
ext = analyze_file(neu_file)
|
| 298 |
if (ext == "png" or ext == "PNG" or ext == "jpg" or ext == "jpeg" or ext == "JPG" or ext == "JPEG"):
|
| 299 |
result= generate_text_zu_bild(neu_file, prompt, k, rag_option, chatbot, history, db)
|
| 300 |
else:
|
| 301 |
result = generate_text_zu_doc(_neu_file, prompt, k, rag_option, chatbot, history, db)
|
| 302 |
+
|
| 303 |
+
#die history erweitern - abhängig davon, ob gerade ein file hochgeladen wurde oder nicht
|
| 304 |
if (file != None):
|
| 305 |
history = history + [[(file,), None],[prompt, result]]
|
| 306 |
else:
|
|
|
|
| 348 |
def generate_text_zu_bild(file, prompt, k, rag_option, chatbot, history, db):
|
| 349 |
global splittet
|
| 350 |
print("Text mit Bild ..............................")
|
|
|
|
| 351 |
prompt_neu = generate_prompt_with_history(prompt, history)
|
| 352 |
if (rag_option == "An"):
|
| 353 |
print("Bild mit RAG..............................")
|
|
|
|
| 372 |
global splittet
|
| 373 |
print("text mit doc ..............................")
|
| 374 |
|
| 375 |
+
prompt_neu = generate_prompt_with_history(prompt, history)
|
| 376 |
if (rag_option == "An"):
|
| 377 |
print("Doc mit RAG..............................")
|
| 378 |
neu_text_mit_chunks = rag_chain2(prompt, db, k)
|