Update app.py
#1
by joudbaz77 - opened
app.py
CHANGED
|
@@ -8,28 +8,23 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 8 |
|
| 9 |
|
| 10 |
# --- FIXED BASIC AGENT ---
|
|
|
|
|
|
|
| 11 |
class BasicAgent:
|
| 12 |
def __init__(self):
|
| 13 |
-
|
| 14 |
|
| 15 |
def __call__(self, question: str) -> str:
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
if "how many" in question:
|
| 22 |
-
return "unknown" # replace later with real logic if needed
|
| 23 |
-
|
| 24 |
-
if "opposite" in question:
|
| 25 |
-
return "left"
|
| 26 |
|
| 27 |
-
|
| 28 |
-
return "unknown"
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
return "unknown"
|
| 33 |
|
| 34 |
|
| 35 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
# --- FIXED BASIC AGENT ---
|
| 11 |
+
from transformers import pipeline
|
| 12 |
+
|
| 13 |
class BasicAgent:
|
| 14 |
def __init__(self):
|
| 15 |
+
self.model = pipeline("text-generation", model="gpt2")
|
| 16 |
|
| 17 |
def __call__(self, question: str) -> str:
|
| 18 |
+
prompt = (
|
| 19 |
+
"Answer ONLY with the final short result.\n"
|
| 20 |
+
"No explanation.\n\n"
|
| 21 |
+
f"Question: {question}\nAnswer:"
|
| 22 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
output = self.model(prompt, max_new_tokens=50, do_sample=False)[0]["generated_text"]
|
|
|
|
| 25 |
|
| 26 |
+
# extract only answer part
|
| 27 |
+
return output.split("Answer:")[-1].strip().split("\n")[0]
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
def run_and_submit_all(profile: gr.OAuthProfile | None):
|