Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -44,9 +44,11 @@ client = InferenceClient(HF_MODEL_ID, token=os.getenv("HF_TOKEN"))
|
|
| 44 |
|
| 45 |
llm = HuggingFaceEndpoint(
|
| 46 |
repo_id="ibm-granite/granite-3.1-8b-instruct", # Using Granite for 2026 stability
|
|
|
|
| 47 |
max_new_tokens=512,
|
| 48 |
temperature=0.1,
|
| 49 |
-
huggingfacehub_api_token=os.getenv("HF_TOKEN")
|
|
|
|
| 50 |
)
|
| 51 |
|
| 52 |
|
|
@@ -122,8 +124,7 @@ def build_retriever(file_path: str):
|
|
| 122 |
# 2. Simplified QA Chain function
|
| 123 |
def retriever_qa(file, query):
|
| 124 |
retr = build_retriever(file)
|
| 125 |
-
|
| 126 |
-
# RetrievalQA works perfectly with HuggingFaceEndpoint
|
| 127 |
qa = RetrievalQA.from_chain_type(
|
| 128 |
llm=llm,
|
| 129 |
chain_type="stuff",
|
|
@@ -131,9 +132,9 @@ def retriever_qa(file, query):
|
|
| 131 |
return_source_documents=False,
|
| 132 |
)
|
| 133 |
|
| 134 |
-
#
|
| 135 |
-
|
| 136 |
-
return
|
| 137 |
|
| 138 |
|
| 139 |
# -------------------------
|
|
|
|
| 44 |
|
| 45 |
llm = HuggingFaceEndpoint(
|
| 46 |
repo_id="ibm-granite/granite-3.1-8b-instruct", # Using Granite for 2026 stability
|
| 47 |
+
task="text-generation",
|
| 48 |
max_new_tokens=512,
|
| 49 |
temperature=0.1,
|
| 50 |
+
huggingfacehub_api_token=os.getenv("HF_TOKEN"),
|
| 51 |
+
wait_for_model=True
|
| 52 |
)
|
| 53 |
|
| 54 |
|
|
|
|
| 124 |
# 2. Simplified QA Chain function
|
| 125 |
def retriever_qa(file, query):
|
| 126 |
retr = build_retriever(file)
|
| 127 |
+
|
|
|
|
| 128 |
qa = RetrievalQA.from_chain_type(
|
| 129 |
llm=llm,
|
| 130 |
chain_type="stuff",
|
|
|
|
| 132 |
return_source_documents=False,
|
| 133 |
)
|
| 134 |
|
| 135 |
+
# Use a dictionary for the input
|
| 136 |
+
result = qa.invoke({"query": query})
|
| 137 |
+
return result["result"]
|
| 138 |
|
| 139 |
|
| 140 |
# -------------------------
|