Update app.py
Browse files
app.py
CHANGED
|
@@ -11,21 +11,23 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
|
|
|
|
|
|
| 14 |
class BasicAgent:
|
| 15 |
def __init__(self):
|
| 16 |
-
print("Loading
|
| 17 |
self.pipeline = pipeline(
|
| 18 |
-
"
|
| 19 |
-
model="
|
| 20 |
-
max_new_tokens=
|
| 21 |
)
|
| 22 |
print("Model loaded.")
|
| 23 |
|
| 24 |
def __call__(self, question: str) -> str:
|
| 25 |
print(f"Received question: {question[:60]}...")
|
| 26 |
-
prompt = f"
|
| 27 |
response = self.pipeline(prompt)[0]["generated_text"]
|
| 28 |
-
answer = response.
|
| 29 |
print(f"Generated answer: {answer}")
|
| 30 |
return answer
|
| 31 |
|
|
@@ -33,6 +35,7 @@ class BasicAgent:
|
|
| 33 |
|
| 34 |
|
| 35 |
|
|
|
|
| 36 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 37 |
"""
|
| 38 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|
|
|
|
| 11 |
|
| 12 |
# --- Basic Agent Definition ---
|
| 13 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 14 |
+
from transformers import pipeline
|
| 15 |
+
|
| 16 |
class BasicAgent:
|
| 17 |
def __init__(self):
|
| 18 |
+
print("Loading lightweight FLAN-T5 model...")
|
| 19 |
self.pipeline = pipeline(
|
| 20 |
+
"text2text-generation",
|
| 21 |
+
model="google/flan-t5-base",
|
| 22 |
+
max_new_tokens=128
|
| 23 |
)
|
| 24 |
print("Model loaded.")
|
| 25 |
|
| 26 |
def __call__(self, question: str) -> str:
|
| 27 |
print(f"Received question: {question[:60]}...")
|
| 28 |
+
prompt = f"Question: {question.strip()}\nAnswer:"
|
| 29 |
response = self.pipeline(prompt)[0]["generated_text"]
|
| 30 |
+
answer = response.strip().split("\n")[0]
|
| 31 |
print(f"Generated answer: {answer}")
|
| 32 |
return answer
|
| 33 |
|
|
|
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
+
|
| 39 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 40 |
"""
|
| 41 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|