Spaces:
Sleeping
Sleeping
Delete agent.py
Browse files
agent.py
DELETED
|
@@ -1,25 +0,0 @@
|
|
| 1 |
-
# agent.py (Updated for Hugging Face inference with FLAN-T5)
|
| 2 |
-
|
| 3 |
-
from transformers import pipeline
|
| 4 |
-
|
| 5 |
-
# Load the Hugging Face inference pipeline
|
| 6 |
-
qa_pipeline = pipeline("text2text-generation", model="google/flan-t5-base")
|
| 7 |
-
|
| 8 |
-
def answer_question(question: str, file_context: str = None, do_search: bool = False) -> str:
|
| 9 |
-
"""
|
| 10 |
-
Answers the question using file context (if any) with a Hugging Face model.
|
| 11 |
-
|
| 12 |
-
Args:
|
| 13 |
-
question (str): The question to be answered.
|
| 14 |
-
file_context (str, optional): Optional context extracted from a file.
|
| 15 |
-
do_search (bool): Ignored for local mode.
|
| 16 |
-
|
| 17 |
-
Returns:
|
| 18 |
-
str: The generated answer.
|
| 19 |
-
"""
|
| 20 |
-
prompt = question if not file_context else f"Context: {file_context}\nQuestion: {question}"
|
| 21 |
-
try:
|
| 22 |
-
result = qa_pipeline(prompt, max_length=256, do_sample=False)
|
| 23 |
-
return result[0]["generated_text"].strip()
|
| 24 |
-
except Exception as e:
|
| 25 |
-
return f"[ERROR] Hugging Face pipeline failed: {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|