Update app.py
Browse files
app.py
CHANGED
|
@@ -11,9 +11,11 @@ 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 |
-
|
| 16 |
-
print("
|
| 17 |
self.pipeline = pipeline(
|
| 18 |
"text2text-generation",
|
| 19 |
model="google/flan-t5-base",
|
|
@@ -32,7 +34,8 @@ class BasicAgent:
|
|
| 32 |
"plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules "
|
| 33 |
"depending of whether the element to be put in the list is a number or a string."
|
| 34 |
)
|
| 35 |
-
|
|
|
|
| 36 |
prompt = f"{self.system_prompt}\n\nQuestion: {question}"
|
| 37 |
print(f"Prompt:\n{prompt[:300]}...")
|
| 38 |
|
|
@@ -45,6 +48,7 @@ class BasicAgent:
|
|
| 45 |
print(f"Pipeline error: {e}")
|
| 46 |
return "FINAL ANSWER: ERROR"
|
| 47 |
|
|
|
|
| 48 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 49 |
"""
|
| 50 |
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 FLAN-T5 pipeline...")
|
| 19 |
self.pipeline = pipeline(
|
| 20 |
"text2text-generation",
|
| 21 |
model="google/flan-t5-base",
|
|
|
|
| 34 |
"plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules "
|
| 35 |
"depending of whether the element to be put in the list is a number or a string."
|
| 36 |
)
|
| 37 |
+
|
| 38 |
+
def __call__(self, question: str) -> str:
|
| 39 |
prompt = f"{self.system_prompt}\n\nQuestion: {question}"
|
| 40 |
print(f"Prompt:\n{prompt[:300]}...")
|
| 41 |
|
|
|
|
| 48 |
print(f"Pipeline error: {e}")
|
| 49 |
return "FINAL ANSWER: ERROR"
|
| 50 |
|
| 51 |
+
|
| 52 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
| 53 |
"""
|
| 54 |
Fetches all questions, runs the BasicAgent on them, submits all answers,
|