Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,12 +6,13 @@ import gradio as gr
|
|
| 6 |
import os
|
| 7 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 8 |
|
| 9 |
-
|
| 10 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 11 |
from langchain_community.vectorstores import Chroma
|
| 12 |
from langchain_community.document_loaders import PyPDFLoader
|
| 13 |
from langchain.chains import RetrievalQA
|
| 14 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
# -------------------------
|
|
@@ -19,13 +20,11 @@ from langchain_community.embeddings import HuggingFaceEmbeddings
|
|
| 19 |
# -------------------------
|
| 20 |
|
| 21 |
# You can change this to any instruct model you like
|
| 22 |
-
HF_MODEL_ID = "ibm-granite/granite-3.1-8b-instruct"
|
| 23 |
|
| 24 |
# Option B: Llama 3.3 (Current industry standard)
|
| 25 |
# HF_MODEL_ID = "meta-llama/Llama-3.3-70B-Instruct"
|
| 26 |
|
| 27 |
-
# If you use a private token, set it as HF_TOKEN env var in Spaces
|
| 28 |
-
client = InferenceClient(HF_MODEL_ID, token=os.getenv("HF_TOKEN"))
|
| 29 |
|
| 30 |
|
| 31 |
# def get_llm():
|
|
@@ -68,13 +67,14 @@ llm_endpoint = HuggingFaceEndpoint(
|
|
| 68 |
max_new_tokens=512,
|
| 69 |
temperature=0.1,
|
| 70 |
huggingfacehub_api_token=os.getenv("HF_TOKEN"),
|
| 71 |
-
provider="hf-inference",
|
| 72 |
model_kwargs={"wait_for_model": True},
|
| 73 |
)
|
| 74 |
|
| 75 |
llm = ChatHuggingFace(llm=llm_endpoint)
|
| 76 |
|
| 77 |
|
|
|
|
| 78 |
# 2. ChatHuggingFace will correctly route this to the /v1/chat/completions
|
| 79 |
# endpoint which the Llama-3.1-8B-Instruct model supports.
|
| 80 |
# llm = ChatHuggingFace(llm=llm_endpoint)
|
|
|
|
| 6 |
import os
|
| 7 |
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 8 |
|
| 9 |
+
|
| 10 |
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 11 |
from langchain_community.vectorstores import Chroma
|
| 12 |
from langchain_community.document_loaders import PyPDFLoader
|
| 13 |
from langchain.chains import RetrievalQA
|
| 14 |
from langchain_community.embeddings import HuggingFaceEmbeddings
|
| 15 |
+
from langchain_huggingface import HuggingFaceEndpoint, ChatHuggingFace
|
| 16 |
|
| 17 |
|
| 18 |
# -------------------------
|
|
|
|
| 20 |
# -------------------------
|
| 21 |
|
| 22 |
# You can change this to any instruct model you like
|
| 23 |
+
# HF_MODEL_ID = "ibm-granite/granite-3.1-8b-instruct"
|
| 24 |
|
| 25 |
# Option B: Llama 3.3 (Current industry standard)
|
| 26 |
# HF_MODEL_ID = "meta-llama/Llama-3.3-70B-Instruct"
|
| 27 |
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
# def get_llm():
|
|
|
|
| 67 |
max_new_tokens=512,
|
| 68 |
temperature=0.1,
|
| 69 |
huggingfacehub_api_token=os.getenv("HF_TOKEN"),
|
| 70 |
+
provider="hf-inference", # forces router.huggingface.co
|
| 71 |
model_kwargs={"wait_for_model": True},
|
| 72 |
)
|
| 73 |
|
| 74 |
llm = ChatHuggingFace(llm=llm_endpoint)
|
| 75 |
|
| 76 |
|
| 77 |
+
|
| 78 |
# 2. ChatHuggingFace will correctly route this to the /v1/chat/completions
|
| 79 |
# endpoint which the Llama-3.1-8B-Instruct model supports.
|
| 80 |
# llm = ChatHuggingFace(llm=llm_endpoint)
|