Update app.py
Browse files
app.py
CHANGED
|
@@ -270,7 +270,7 @@ def create_assistant_suche(prompt):
|
|
| 270 |
#########################################################
|
| 271 |
#Funktion wird direkt aufgerufen aus der GUI - von hier muss auch die Rückmeldung kommen....
|
| 272 |
#man kann einen Text-Prompt eingeben (mit oder ohne RAG), dazu ein Image hochladen, ein Bild zu einem reinen textprompt erzeugen lassen
|
| 273 |
-
def generate_auswahl(prompt, 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,):
|
| 274 |
global splittet, db
|
| 275 |
#wenn RAG angeschaltet - Vektorstore initialisieren
|
| 276 |
#aber nur, wenn es noch nicht geshehen ist (splittet = False)
|
|
@@ -278,7 +278,7 @@ def generate_auswahl(prompt, file, file_history, chatbot, history, rag_option, m
|
|
| 278 |
neu_file = file_history
|
| 279 |
|
| 280 |
#prompt normalisieren bevor er an die KIs geht
|
| 281 |
-
prompt = normalise_prompt(prompt_in)
|
| 282 |
|
| 283 |
if (rag_option == "An"):
|
| 284 |
#muss nur einmal ausgeführt werden...
|
|
@@ -294,7 +294,7 @@ def generate_auswahl(prompt, file, file_history, chatbot, history, rag_option, m
|
|
| 294 |
#kein Bild hochgeladen -> auf Text antworten...
|
| 295 |
status = "Antwort der KI ..."
|
| 296 |
if (file == None and file_history == None):
|
| 297 |
-
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,)
|
| 298 |
history = history + [[prompt, result]]
|
| 299 |
else:
|
| 300 |
#Es wurde ein File neu angehängt -> wenn prompt dazu, das Bild analysieren
|
|
@@ -398,7 +398,7 @@ def generate_text_zu_doc(file, prompt, k, rag_option, chatbot, history, db):
|
|
| 398 |
####################################################
|
| 399 |
#aus einem Text-Prompt die Antwort von KI bekommen
|
| 400 |
#mit oder ohne RAG möglich
|
| 401 |
-
def 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,):
|
| 402 |
global splittet
|
| 403 |
suche_im_Netz="Antwort der KI ..."
|
| 404 |
print("Text pur..............................")
|
|
@@ -434,7 +434,7 @@ def generate_text (prompt, chatbot, history, rag_option, model_option, openai_ap
|
|
| 434 |
else:
|
| 435 |
#oder an Hugging Face --------------------------
|
| 436 |
print("HF Anfrage.......................")
|
| 437 |
-
model_kwargs={"temperature": 0.5, "max_length":
|
| 438 |
llm = HuggingFaceHub(repo_id=repo_id, model_kwargs=model_kwargs)
|
| 439 |
#llm = HuggingFaceChain(model=MODEL_NAME_HF, model_kwargs={"temperature": 0.5, "max_length": 128})
|
| 440 |
#llm = HuggingFaceHub(url_??? = "https://wdgsjd6zf201mufn.us-east-1.aws.endpoints.huggingface.cloud", model_kwargs={"temperature": 0.5, "max_length": 64})
|
|
@@ -564,6 +564,15 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
| 564 |
label="Top-p",
|
| 565 |
visible=False,
|
| 566 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 567 |
temperature = gr.Slider(
|
| 568 |
minimum=0.1,
|
| 569 |
maximum=2.0,
|
|
@@ -652,7 +661,8 @@ with gr.Blocks(css=customCSS, theme=small_and_beautiful_theme) as demo:
|
|
| 652 |
temperature,
|
| 653 |
max_length_tokens,
|
| 654 |
max_context_length_tokens,
|
| 655 |
-
repetition_penalty
|
|
|
|
| 656 |
],
|
| 657 |
outputs=[chatbot, history, attached_file, attached_file_history, status_display],
|
| 658 |
show_progress=True,
|
|
|
|
| 270 |
#########################################################
|
| 271 |
#Funktion wird direkt aufgerufen aus der GUI - von hier muss auch die Rückmeldung kommen....
|
| 272 |
#man kann einen Text-Prompt eingeben (mit oder ohne RAG), dazu ein Image hochladen, ein Bild zu einem reinen textprompt erzeugen lassen
|
| 273 |
+
def generate_auswahl(prompt, 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):
|
| 274 |
global splittet, db
|
| 275 |
#wenn RAG angeschaltet - Vektorstore initialisieren
|
| 276 |
#aber nur, wenn es noch nicht geshehen ist (splittet = False)
|
|
|
|
| 278 |
neu_file = file_history
|
| 279 |
|
| 280 |
#prompt normalisieren bevor er an die KIs geht
|
| 281 |
+
prompt = prompt_in # hier könnte der Prompt normalisiert werden: normalise_prompt(prompt_in)
|
| 282 |
|
| 283 |
if (rag_option == "An"):
|
| 284 |
#muss nur einmal ausgeführt werden...
|
|
|
|
| 294 |
#kein Bild hochgeladen -> auf Text antworten...
|
| 295 |
status = "Antwort der KI ..."
|
| 296 |
if (file == None and file_history == None):
|
| 297 |
+
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,top_k=35)
|
| 298 |
history = history + [[prompt, result]]
|
| 299 |
else:
|
| 300 |
#Es wurde ein File neu angehängt -> wenn prompt dazu, das Bild analysieren
|
|
|
|
| 398 |
####################################################
|
| 399 |
#aus einem Text-Prompt die Antwort von KI bekommen
|
| 400 |
#mit oder ohne RAG möglich
|
| 401 |
+
def 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,top_k=35):
|
| 402 |
global splittet
|
| 403 |
suche_im_Netz="Antwort der KI ..."
|
| 404 |
print("Text pur..............................")
|
|
|
|
| 434 |
else:
|
| 435 |
#oder an Hugging Face --------------------------
|
| 436 |
print("HF Anfrage.......................")
|
| 437 |
+
model_kwargs={"temperature": 0.5, "max_length": 512, "num_return_sequences": 1, "top_k": top_k, "top_p": top_p, "repetition_penalty": repetition_penalty}
|
| 438 |
llm = HuggingFaceHub(repo_id=repo_id, model_kwargs=model_kwargs)
|
| 439 |
#llm = HuggingFaceChain(model=MODEL_NAME_HF, model_kwargs={"temperature": 0.5, "max_length": 128})
|
| 440 |
#llm = HuggingFaceHub(url_??? = "https://wdgsjd6zf201mufn.us-east-1.aws.endpoints.huggingface.cloud", model_kwargs={"temperature": 0.5, "max_length": 64})
|
|
|
|
| 564 |
label="Top-p",
|
| 565 |
visible=False,
|
| 566 |
)
|
| 567 |
+
top_k = gr.Slider(
|
| 568 |
+
minimum=1,
|
| 569 |
+
maximum=100,
|
| 570 |
+
value=35,
|
| 571 |
+
step=1,
|
| 572 |
+
interactive=True,
|
| 573 |
+
label="Top-k",
|
| 574 |
+
visible=False,
|
| 575 |
+
)
|
| 576 |
temperature = gr.Slider(
|
| 577 |
minimum=0.1,
|
| 578 |
maximum=2.0,
|
|
|
|
| 661 |
temperature,
|
| 662 |
max_length_tokens,
|
| 663 |
max_context_length_tokens,
|
| 664 |
+
repetition_penalty,
|
| 665 |
+
top_k
|
| 666 |
],
|
| 667 |
outputs=[chatbot, history, attached_file, attached_file_history, status_display],
|
| 668 |
show_progress=True,
|