Update app.py
Browse files
app.py
CHANGED
|
@@ -37,6 +37,16 @@ from beschreibungen import *
|
|
| 37 |
#Konstanten
|
| 38 |
#Validieren des PW
|
| 39 |
ANTI_BOT_PW = os.getenv("VALIDATE_PW")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
#max Anzahl der zurückgelieferten Dokumente
|
| 41 |
ANZAHL_DOCS = 5
|
| 42 |
PATH_WORK = "."
|
|
@@ -49,11 +59,11 @@ MODEL_NAME_HF = "HuggingFaceH4/zephyr-7b-alpha" #"mistralai/Mixtral-8x7B-Instru
|
|
| 49 |
|
| 50 |
#HuggingFace Reop ID--------------------------------
|
| 51 |
#repo_id = "meta-llama/Llama-2-13b-chat-hf"
|
| 52 |
-
|
| 53 |
#repo_id = "TheBloke/Yi-34B-Chat-GGUF"
|
| 54 |
#repo_id = "meta-llama/Llama-2-70b-chat-hf"
|
| 55 |
#repo_id = "tiiuae/falcon-40b"
|
| 56 |
-
repo_id = "Vicuna-33b"
|
| 57 |
#repo_id = "alexkueck/ChatBotLI2Klein"
|
| 58 |
#repo_id = "mistralai/Mistral-7B-v0.1"
|
| 59 |
#repo_id = "internlm/internlm-chat-7b"
|
|
@@ -65,9 +75,12 @@ repo_id = "Vicuna-33b"
|
|
| 65 |
#repo_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 66 |
#repo_id = "abacusai/Smaug-72B-v0.1"
|
| 67 |
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
###############################################
|
| 73 |
#globale Variablen
|
|
@@ -186,7 +199,6 @@ def reset_textbox():
|
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
-
|
| 190 |
####################################################
|
| 191 |
#aus einem Text-Prompt die Antwort von KI bekommen
|
| 192 |
def generate_text (prompt, chatbot, history, vektordatenbank, retriever, top_p=0.6, temperature=0.2, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3, top_k=35):
|
|
@@ -215,6 +227,7 @@ def generate_text (prompt, chatbot, history, vektordatenbank, retriever, top_p=0
|
|
| 215 |
repetition_penalty=repetition_penalty
|
| 216 |
)
|
| 217 |
"""
|
|
|
|
| 218 |
#######################################################
|
| 219 |
#Alternativ, wenn repro_id gegeben:
|
| 220 |
# Verwenden Sie die InferenceApi von huggingface_hub
|
|
@@ -227,7 +240,8 @@ def generate_text (prompt, chatbot, history, vektordatenbank, retriever, top_p=0
|
|
| 227 |
#zusätzliche Dokumenten Splits aus DB zum Prompt hinzufügen (aus VektorDB - Chroma oder Mongo DB)
|
| 228 |
print("LLM aufrufen mit RAG: ...........")
|
| 229 |
#result = rag_chain(history_text_und_prompt, vektordatenbank, ANZAHL_DOCS)
|
| 230 |
-
result = rag_chain(llm, history_text_und_prompt, retriever)
|
|
|
|
| 231 |
|
| 232 |
except Exception as e:
|
| 233 |
raise gr.Error(e)
|
|
|
|
| 37 |
#Konstanten
|
| 38 |
#Validieren des PW
|
| 39 |
ANTI_BOT_PW = os.getenv("VALIDATE_PW")
|
| 40 |
+
|
| 41 |
+
###############################
|
| 42 |
+
#HF Authentifizierung
|
| 43 |
+
HUGGINGFACEHUB_API_TOKEN = os.getenv("HF_READ")
|
| 44 |
+
os.environ["HUGGINGFACEHUB_API_TOKEN"] = HUGGINGFACEHUB_API_TOKEN
|
| 45 |
+
HEADERS = {"Authorization": f"Bearer {HUGGINGFACEHUB_API_TOKEN}"}
|
| 46 |
+
# Hugging Face Token direkt im Code setzen
|
| 47 |
+
hf_token = os.getenv("HF_READ")
|
| 48 |
+
|
| 49 |
+
|
| 50 |
#max Anzahl der zurückgelieferten Dokumente
|
| 51 |
ANZAHL_DOCS = 5
|
| 52 |
PATH_WORK = "."
|
|
|
|
| 59 |
|
| 60 |
#HuggingFace Reop ID--------------------------------
|
| 61 |
#repo_id = "meta-llama/Llama-2-13b-chat-hf"
|
| 62 |
+
repo_id = "HuggingFaceH4/zephyr-7b-alpha" #das Modell ist echt gut!!! Vom MIT
|
| 63 |
#repo_id = "TheBloke/Yi-34B-Chat-GGUF"
|
| 64 |
#repo_id = "meta-llama/Llama-2-70b-chat-hf"
|
| 65 |
#repo_id = "tiiuae/falcon-40b"
|
| 66 |
+
#repo_id = "Vicuna-33b"
|
| 67 |
#repo_id = "alexkueck/ChatBotLI2Klein"
|
| 68 |
#repo_id = "mistralai/Mistral-7B-v0.1"
|
| 69 |
#repo_id = "internlm/internlm-chat-7b"
|
|
|
|
| 75 |
#repo_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 76 |
#repo_id = "abacusai/Smaug-72B-v0.1"
|
| 77 |
|
| 78 |
+
####################################
|
| 79 |
+
#HF API - URL
|
| 80 |
+
API_URL = "https://api-inference.huggingface.co/models/Falconsai/text_summarization"
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
|
| 84 |
|
| 85 |
###############################################
|
| 86 |
#globale Variablen
|
|
|
|
| 199 |
|
| 200 |
|
| 201 |
|
|
|
|
| 202 |
####################################################
|
| 203 |
#aus einem Text-Prompt die Antwort von KI bekommen
|
| 204 |
def generate_text (prompt, chatbot, history, vektordatenbank, retriever, top_p=0.6, temperature=0.2, max_new_tokens=4048, max_context_length_tokens=2048, repetition_penalty=1.3, top_k=35):
|
|
|
|
| 227 |
repetition_penalty=repetition_penalty
|
| 228 |
)
|
| 229 |
"""
|
| 230 |
+
|
| 231 |
#######################################################
|
| 232 |
#Alternativ, wenn repro_id gegeben:
|
| 233 |
# Verwenden Sie die InferenceApi von huggingface_hub
|
|
|
|
| 240 |
#zusätzliche Dokumenten Splits aus DB zum Prompt hinzufügen (aus VektorDB - Chroma oder Mongo DB)
|
| 241 |
print("LLM aufrufen mit RAG: ...........")
|
| 242 |
#result = rag_chain(history_text_und_prompt, vektordatenbank, ANZAHL_DOCS)
|
| 243 |
+
#result = rag_chain(llm, history_text_und_prompt, retriever)
|
| 244 |
+
result = rag_chain2(history_text_und_prompt, retriever)
|
| 245 |
|
| 246 |
except Exception as e:
|
| 247 |
raise gr.Error(e)
|