Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,6 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
|
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
from transformers import pipeline
|
| 14 |
-
|
| 15 |
import re
|
| 16 |
|
| 17 |
class BasicAgent:
|
|
@@ -19,26 +18,29 @@ class BasicAgent:
|
|
| 19 |
print("BasicAgent initialized.")
|
| 20 |
self.generator = pipeline(
|
| 21 |
"text2text-generation",
|
| 22 |
-
model="google/flan-t5-
|
| 23 |
max_new_tokens=32
|
| 24 |
)
|
| 25 |
|
| 26 |
def __call__(self, question: str) -> str:
|
| 27 |
prompt = (
|
| 28 |
-
"
|
| 29 |
-
"
|
| 30 |
-
f"
|
| 31 |
)
|
|
|
|
| 32 |
result = self.generator(prompt)[0]["generated_text"]
|
| 33 |
|
| 34 |
-
#
|
| 35 |
answer = result.strip()
|
| 36 |
-
answer =
|
|
|
|
| 37 |
answer = answer.strip()
|
| 38 |
|
| 39 |
print(f"Final answer: {answer}")
|
| 40 |
return answer
|
| 41 |
|
|
|
|
| 42 |
|
| 43 |
|
| 44 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
|
|
| 11 |
# --- Basic Agent Definition ---
|
| 12 |
# ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
|
| 13 |
from transformers import pipeline
|
|
|
|
| 14 |
import re
|
| 15 |
|
| 16 |
class BasicAgent:
|
|
|
|
| 18 |
print("BasicAgent initialized.")
|
| 19 |
self.generator = pipeline(
|
| 20 |
"text2text-generation",
|
| 21 |
+
model="google/flan-t5-large",
|
| 22 |
max_new_tokens=32
|
| 23 |
)
|
| 24 |
|
| 25 |
def __call__(self, question: str) -> str:
|
| 26 |
prompt = (
|
| 27 |
+
"Give ONLY the exact answer. "
|
| 28 |
+
"No explanation. No extra words.\n"
|
| 29 |
+
f"{question}"
|
| 30 |
)
|
| 31 |
+
|
| 32 |
result = self.generator(prompt)[0]["generated_text"]
|
| 33 |
|
| 34 |
+
# Strong cleanup
|
| 35 |
answer = result.strip()
|
| 36 |
+
answer = answer.replace("The answer is", "")
|
| 37 |
+
answer = re.split(r"[.\n,]", answer)[0]
|
| 38 |
answer = answer.strip()
|
| 39 |
|
| 40 |
print(f"Final answer: {answer}")
|
| 41 |
return answer
|
| 42 |
|
| 43 |
+
|
| 44 |
|
| 45 |
|
| 46 |
def run_and_submit_all( profile: gr.OAuthProfile | None):
|