Update app.py
Browse files
app.py
CHANGED
|
@@ -325,66 +325,62 @@ def create_assistant_suche_hf(chatbot, prompt):
|
|
| 325 |
#Funktion wird direkt aufgerufen aus der GUI - von hier muss auch die Rückmeldung kommen....
|
| 326 |
#man kann einen Text-Prompt eingeben (mit oder ohne RAG), dazu ein Image hochladen, ein Bild zu einem reinen textprompt erzeugen lassen
|
| 327 |
def generate_auswahl(prompt_in, file, file_history, chatbot, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,top_k=35, websuche="Aus", validate=False):
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
|
| 336 |
-
|
| 337 |
-
|
| 338 |
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 349 |
|
| 350 |
-
#
|
| 351 |
-
|
| 352 |
-
if (
|
| 353 |
-
result
|
| 354 |
-
history = history + [[prompt, result]]
|
| 355 |
else:
|
| 356 |
-
|
| 357 |
-
#das history_fiel muss neu gesetzt werden
|
| 358 |
-
if (file != None):
|
| 359 |
-
# file_history wird neu gesetzt in der Rückgabe dieser Funktion...
|
| 360 |
-
neu_file = file
|
| 361 |
-
|
| 362 |
-
#herausfinden, ob Bild oder Dokument...
|
| 363 |
-
ext = analyze_file(neu_file)
|
| 364 |
-
if (ext == "png" or ext == "PNG" or ext == "jpg" or ext == "jpeg" or ext == "JPG" or ext == "JPEG"):
|
| 365 |
-
result= generate_text_zu_bild(neu_file, prompt, k, rag_option, chatbot, history, db)
|
| 366 |
-
else:
|
| 367 |
-
result = generate_text_zu_doc(neu_file, prompt, k, rag_option, chatbot, history, db)
|
| 368 |
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
|
| 389 |
##################################################
|
| 390 |
#zu einem Text-Prompt ein Bild via Stable Diffusion generieren
|
|
|
|
| 325 |
#Funktion wird direkt aufgerufen aus der GUI - von hier muss auch die Rückmeldung kommen....
|
| 326 |
#man kann einen Text-Prompt eingeben (mit oder ohne RAG), dazu ein Image hochladen, ein Bild zu einem reinen textprompt erzeugen lassen
|
| 327 |
def generate_auswahl(prompt_in, file, file_history, chatbot, history, rag_option, model_option, openai_api_key, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3,top_k=35, websuche="Aus", validate=False):
|
| 328 |
+
global vektorstore, retriever
|
| 329 |
+
#nur wenn man sich validiert hat, kann die Anwendung los legen
|
| 330 |
+
if (validate and not prompt_in == "" and not prompt_in == None):
|
| 331 |
+
#wenn RAG angeschaltet - Vektorstore initialisieren
|
| 332 |
+
#aber nur, wenn es noch nicht geshehen ist (splittet = False)
|
| 333 |
+
#falls schon ein File hochgeladen wurde, ist es in history_file gespeichert - falls ein neues File hochgeladen wurde, wird es anschließend neu gesetzt
|
| 334 |
+
neu_file = file_history
|
| 335 |
|
| 336 |
+
#prompt normalisieren bevor er an die KIs geht
|
| 337 |
+
prompt = normalise_prompt(prompt_in)
|
| 338 |
|
| 339 |
+
if (rag_option == "An"):
|
| 340 |
+
#muss nur einmal ausgeführt werden...
|
| 341 |
+
if vectorstore == None:
|
| 342 |
+
print("db neu aufbauen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1")
|
| 343 |
+
splits = document_loading_splitting()
|
| 344 |
+
vectorstore, retriever = document_storage_chroma(splits)
|
| 345 |
+
|
| 346 |
+
#kein Bild hochgeladen -> auf Text antworten...
|
| 347 |
+
status = "Antwort der KI ..."
|
| 348 |
+
if (file == None and file_history == None):
|
| 349 |
+
result, status = generate_text(prompt, chatbot, history, rag_option, model_option, openai_api_key, db, websuche, k=3, top_p=0.6, temperature=0.5, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3, top_k=3)
|
| 350 |
+
history = history + [[prompt, result]]
|
| 351 |
+
else:
|
| 352 |
+
#Es wurde ein File neu angehängt -> wenn prompt dazu, das Bild analysieren
|
| 353 |
+
#das history_fiel muss neu gesetzt werden
|
| 354 |
+
if (file != None):
|
| 355 |
+
# file_history wird neu gesetzt in der Rückgabe dieser Funktion...
|
| 356 |
+
neu_file = file
|
| 357 |
|
| 358 |
+
#herausfinden, ob Bild oder Dokument...
|
| 359 |
+
ext = analyze_file(neu_file)
|
| 360 |
+
if (ext == "png" or ext == "PNG" or ext == "jpg" or ext == "jpeg" or ext == "JPG" or ext == "JPEG"):
|
| 361 |
+
result= generate_text_zu_bild(neu_file, prompt, k, rag_option, chatbot, history, db)
|
|
|
|
| 362 |
else:
|
| 363 |
+
result = generate_text_zu_doc(neu_file, prompt, k, rag_option, chatbot, history, db)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
|
| 365 |
+
#die history erweitern - abhängig davon, ob gerade ein file hochgeladen wurde oder nicht
|
| 366 |
+
if (file != None):
|
| 367 |
+
history = history + [[(file,), None],[prompt, result]]
|
| 368 |
+
else:
|
| 369 |
+
history = history + [[prompt, result]]
|
| 370 |
|
| 371 |
+
chatbot[-1][1] = ""
|
| 372 |
+
for character in result:
|
| 373 |
+
chatbot[-1][1] += character
|
| 374 |
+
time.sleep(0.03)
|
| 375 |
+
yield chatbot, history, None, neu_file, status
|
| 376 |
+
if shared_state.interrupted:
|
| 377 |
+
shared_state.recover()
|
| 378 |
+
try:
|
| 379 |
+
yield chatbot, history, None, neu_file, "Stop: Success"
|
| 380 |
+
except:
|
| 381 |
+
pass
|
| 382 |
+
else: #noch nicht validiert, oder kein Prompt
|
| 383 |
+
return chatbot, history, None, file_history, "Erst validieren oder einen Prompt eingeben!"
|
| 384 |
|
| 385 |
##################################################
|
| 386 |
#zu einem Text-Prompt ein Bild via Stable Diffusion generieren
|