alexkueck commited on
Commit
bb2645b
1 Parent(s): d83ad17

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -12
app.py CHANGED
@@ -54,10 +54,16 @@ CHROMA_DIR = "/chroma/kkg"
54
  CHROMA_PDF = './chroma/kkg/pdf'
55
  CHROMA_WORD = './chroma/kkg/word'
56
  CHROMA_EXCEL = './chroma/kkg/excel'
57
- #HuggingFace Model name--------------------------------
58
- MODEL_NAME_HF = 'all-MiniLM-L6-v2' #"t5-small" #"meta-llama/Meta-Llama-3-8B-Instruct" #"mistralai/Mistral-7B-Instruct-v0.3" #"microsoft/Phi-3-mini-4k-instruct" #"HuggingFaceH4/zephyr-7b-alpha"
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"
@@ -75,8 +81,8 @@ repo_id = "HuggingFaceH4/zephyr-7b-alpha" #das Modell ist echt gut!!! Vom MIT
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
 
@@ -217,16 +223,17 @@ def generate_text (prompt, chatbot, history, vektordatenbank, retriever, top_p=0
217
  print("HF Anfrage.......................")
218
  #zusätzliche Dokumenten Splits aus DB zum Prompt hinzufügen (aus VektorDB - Chroma oder Mongo DB)
219
  print("LLM aufrufen mit RAG: .....................................................")
 
220
  ##############################################
221
  #Verschiedene Alternativen als llm übergeben an die rag-chain
222
  #############################################
223
  #0. Alternative - repo ID
224
- #Alternativ, wenn repro_id gegeben:
225
- # Verwenden Sie die InferenceApi von huggingface_hub
226
  #llm = InferenceApi(repo_id, token=hf_token)
227
  #result = rag_chain(llm, history_text_und_prompt, retriever)
228
 
229
- #1.Alternative mit Inference API
 
230
  # Erstelle eine HuggingFaceEndPoints-Instanz mit den entsprechenden Endpunkt-Parametern
231
  """
232
  llm = HuggingFaceEndpoint(
@@ -240,15 +247,17 @@ def generate_text (prompt, chatbot, history, vektordatenbank, retriever, top_p=0
240
  )
241
  result = rag_chain(llm, history_text_und_prompt, retriever)
242
  """
243
-
 
244
  #2. Alternative: mit API_URL
245
- #result = rag_chain(API_URL, history_text_und_prompt, retriever)
246
 
 
247
  #3.te Alternative für pipeline
248
  # Erstelle eine Pipeline mit den gewünschten Parametern
249
  #llm = pipeline("text-generation", model=MODEL_NAME_HF, config={"temperature": 0.5, "max_length": 1024, "num_return_sequences": 1, "top_k": top_k, "top_p": top_p, "repetition_penalty": repetition_penalty}, trust_remote_code=True)
250
- llm = pipeline("summarization", model=MODEL_NAME_HF, trust_remote_code=True)
251
- result = rag_chain(llm, history_text_und_prompt, retriever)
252
 
253
  except Exception as e:
254
  raise gr.Error(e)
 
54
  CHROMA_PDF = './chroma/kkg/pdf'
55
  CHROMA_WORD = './chroma/kkg/word'
56
  CHROMA_EXCEL = './chroma/kkg/excel'
 
 
57
 
58
+ ###########################################
59
+ # Alternativen, um HF Modelle in der rAG Chain einzusetzen
60
+ ###########################################
61
+ #######################################
62
+ #1. Alternative: HuggingFace Model name--------------------------------
63
+ MODEL_NAME_HF = "t5-small" #"meta-llama/Meta-Llama-3-8B-Instruct" #"mistralai/Mistral-7B-Instruct-v0.3" #"microsoft/Phi-3-mini-4k-instruct" #"HuggingFaceH4/zephyr-7b-alpha"
64
+
65
+ ############################################
66
+ #2. Alternative_ HuggingFace Reop ID--------------------------------
67
  #repo_id = "meta-llama/Llama-2-13b-chat-hf"
68
  repo_id = "HuggingFaceH4/zephyr-7b-alpha" #das Modell ist echt gut!!! Vom MIT
69
  #repo_id = "TheBloke/Yi-34B-Chat-GGUF"
 
81
  #repo_id = "mistralai/Mixtral-8x7B-Instruct-v0.1"
82
  #repo_id = "abacusai/Smaug-72B-v0.1"
83
 
84
+ ###########################################
85
+ #3. Alternative: HF API - URL
86
  API_URL = "https://api-inference.huggingface.co/models/Falconsai/text_summarization"
87
 
88
 
 
223
  print("HF Anfrage.......................")
224
  #zusätzliche Dokumenten Splits aus DB zum Prompt hinzufügen (aus VektorDB - Chroma oder Mongo DB)
225
  print("LLM aufrufen mit RAG: .....................................................")
226
+
227
  ##############################################
228
  #Verschiedene Alternativen als llm übergeben an die rag-chain
229
  #############################################
230
  #0. Alternative - repo ID
231
+ # Verwenden Sie die Inference Api von huggingface_hub
 
232
  #llm = InferenceApi(repo_id, token=hf_token)
233
  #result = rag_chain(llm, history_text_und_prompt, retriever)
234
 
235
+ ##############################################
236
+ #1.Alternative mit Inference API ung HF EndPoint
237
  # Erstelle eine HuggingFaceEndPoints-Instanz mit den entsprechenden Endpunkt-Parametern
238
  """
239
  llm = HuggingFaceEndpoint(
 
247
  )
248
  result = rag_chain(llm, history_text_und_prompt, retriever)
249
  """
250
+
251
+ #############################################
252
  #2. Alternative: mit API_URL
253
+ result = rag_chain(API_URL, history_text_und_prompt, retriever)
254
 
255
+ #############################################
256
  #3.te Alternative für pipeline
257
  # Erstelle eine Pipeline mit den gewünschten Parametern
258
  #llm = pipeline("text-generation", model=MODEL_NAME_HF, config={"temperature": 0.5, "max_length": 1024, "num_return_sequences": 1, "top_k": top_k, "top_p": top_p, "repetition_penalty": repetition_penalty}, trust_remote_code=True)
259
+ #llm = pipeline("summarization", model=MODEL_NAME_HF, trust_remote_code=True)
260
+ #result = rag_chain(llm, history_text_und_prompt, retriever)
261
 
262
  except Exception as e:
263
  raise gr.Error(e)