Update app.py
Browse files
app.py
CHANGED
|
@@ -9,15 +9,14 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 9 |
|
| 10 |
class BasicAgent:
|
| 11 |
def __init__(self):
|
| 12 |
-
print("
|
| 13 |
self.pipeline = pipeline(
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
print("✅ Model loaded.")
|
| 21 |
|
| 22 |
def __call__(self, question: str, task_id: str = None) -> str:
|
| 23 |
question_lower = question.lower()
|
|
@@ -39,10 +38,11 @@ class BasicAgent:
|
|
| 39 |
"Question: List just the vegetables from [milk, eggs, carrots, onions, cookies].\n"
|
| 40 |
"Answer: carrots, onions\n\n"
|
| 41 |
)
|
| 42 |
-
prompt =
|
| 43 |
result = self.pipeline(prompt)[0]["generated_text"]
|
| 44 |
return result.strip().split("Answer:")[-1].strip()
|
| 45 |
|
|
|
|
| 46 |
def search_wikipedia(self, question: str) -> str:
|
| 47 |
import wikipedia
|
| 48 |
try:
|
|
|
|
| 9 |
|
| 10 |
class BasicAgent:
|
| 11 |
def __init__(self):
|
| 12 |
+
print("Loading flan-t5-base...")
|
| 13 |
self.pipeline = pipeline(
|
| 14 |
+
"text2text-generation",
|
| 15 |
+
model="google/flan-t5-base",
|
| 16 |
+
max_new_tokens=128,
|
| 17 |
+
temperature=0.3
|
| 18 |
+
)
|
| 19 |
+
print("Model loaded.")
|
|
|
|
| 20 |
|
| 21 |
def __call__(self, question: str, task_id: str = None) -> str:
|
| 22 |
question_lower = question.lower()
|
|
|
|
| 38 |
"Question: List just the vegetables from [milk, eggs, carrots, onions, cookies].\n"
|
| 39 |
"Answer: carrots, onions\n\n"
|
| 40 |
)
|
| 41 |
+
prompt = f"Please solve the following step-by-step and return only the final answer:\n{question}"
|
| 42 |
result = self.pipeline(prompt)[0]["generated_text"]
|
| 43 |
return result.strip().split("Answer:")[-1].strip()
|
| 44 |
|
| 45 |
+
|
| 46 |
def search_wikipedia(self, question: str) -> str:
|
| 47 |
import wikipedia
|
| 48 |
try:
|