Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,7 +4,7 @@ warnings.filterwarnings("ignore")
|
|
| 4 |
import uuid
|
| 5 |
import gradio as gr
|
| 6 |
import os
|
| 7 |
-
from langchain_huggingface import HuggingFaceEndpoint
|
| 8 |
|
| 9 |
from huggingface_hub import InferenceClient
|
| 10 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
|
@@ -42,18 +42,28 @@ client = InferenceClient(HF_MODEL_ID, token=os.getenv("HF_TOKEN"))
|
|
| 42 |
# return response
|
| 43 |
# return _llm
|
| 44 |
|
| 45 |
-
llm = HuggingFaceEndpoint(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 47 |
-
|
| 48 |
-
# repo_id="ibm-granite/granite-3.1-8b-instruct", # Using Granite for 2026 stability
|
| 49 |
-
task="conversational",
|
| 50 |
max_new_tokens=512,
|
| 51 |
-
temperature=0.1,
|
| 52 |
huggingfacehub_api_token=os.getenv("HF_TOKEN"),
|
| 53 |
-
wait_for_model=True
|
| 54 |
)
|
| 55 |
|
| 56 |
-
|
|
|
|
|
|
|
| 57 |
|
| 58 |
# -------------------------
|
| 59 |
# Document loader
|
|
|
|
| 4 |
import uuid
|
| 5 |
import gradio as gr
|
| 6 |
import os
|
| 7 |
+
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 8 |
|
| 9 |
from huggingface_hub import InferenceClient
|
| 10 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
|
|
|
| 42 |
# return response
|
| 43 |
# return _llm
|
| 44 |
|
| 45 |
+
# llm = HuggingFaceEndpoint(
|
| 46 |
+
# repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 47 |
+
# # repo_id="meta-llama/Llama-3.1-8B-Instruct", # This is the "Live" 2026 model
|
| 48 |
+
# # repo_id="ibm-granite/granite-3.1-8b-instruct", # Using Granite for 2026 stability
|
| 49 |
+
# task="conversational",
|
| 50 |
+
# max_new_tokens=512,
|
| 51 |
+
# temperature=0.1,
|
| 52 |
+
# huggingfacehub_api_token=os.getenv("HF_TOKEN"),
|
| 53 |
+
# wait_for_model=True
|
| 54 |
+
# )
|
| 55 |
+
|
| 56 |
+
# 1. First, define the base endpoint (keep task as text-generation here)
|
| 57 |
+
llm_endpoint = HuggingFaceEndpoint(
|
| 58 |
repo_id="mistralai/Mistral-7B-Instruct-v0.3",
|
| 59 |
+
task="text-generation",
|
|
|
|
|
|
|
| 60 |
max_new_tokens=512,
|
|
|
|
| 61 |
huggingfacehub_api_token=os.getenv("HF_TOKEN"),
|
|
|
|
| 62 |
)
|
| 63 |
|
| 64 |
+
# 2. Wrap it in ChatHuggingFace to fix the task mismatch
|
| 65 |
+
# This automatically handles the "conversational" formatting for you
|
| 66 |
+
llm = ChatHuggingFace(llm=llm_endpoint)
|
| 67 |
|
| 68 |
# -------------------------
|
| 69 |
# Document loader
|