Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -17,33 +17,30 @@ class BasicAgent:
|
|
| 17 |
self.generator = pipeline(
|
| 18 |
"text2text-generation",
|
| 19 |
model="google/flan-t5-large",
|
| 20 |
-
max_new_tokens=
|
| 21 |
-
temperature=0.0,
|
| 22 |
do_sample=False
|
| 23 |
)
|
| 24 |
|
| 25 |
def __call__(self, question: str) -> str:
|
| 26 |
prompt = (
|
| 27 |
-
"Answer the question
|
| 28 |
-
"
|
| 29 |
-
|
|
|
|
| 30 |
"Answer:"
|
| 31 |
)
|
| 32 |
|
| 33 |
result = self.generator(prompt)[0]["generated_text"]
|
| 34 |
|
| 35 |
-
#
|
| 36 |
answer = result.strip()
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
answer =
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
if answer.lower() == "true":
|
| 44 |
-
answer = "True"
|
| 45 |
-
elif answer.lower() == "false":
|
| 46 |
-
answer = "False"
|
| 47 |
|
| 48 |
print(f"\nQ: {question}\nA: {answer}\n")
|
| 49 |
return answer
|
|
|
|
| 17 |
self.generator = pipeline(
|
| 18 |
"text2text-generation",
|
| 19 |
model="google/flan-t5-large",
|
| 20 |
+
max_new_tokens=64,
|
| 21 |
+
temperature=0.0,
|
| 22 |
do_sample=False
|
| 23 |
)
|
| 24 |
|
| 25 |
def __call__(self, question: str) -> str:
|
| 26 |
prompt = (
|
| 27 |
+
"Answer the question EXACTLY as expected.\n"
|
| 28 |
+
"Give the final answer only.\n"
|
| 29 |
+
"Do not explain.\n\n"
|
| 30 |
+
f"Question:\n{question}\n\n"
|
| 31 |
"Answer:"
|
| 32 |
)
|
| 33 |
|
| 34 |
result = self.generator(prompt)[0]["generated_text"]
|
| 35 |
|
| 36 |
+
# ✅ MINIMAL CLEANUP (CRITICAL)
|
| 37 |
answer = result.strip()
|
| 38 |
+
|
| 39 |
+
# Remove only obvious prefixes
|
| 40 |
+
answer = re.sub(r"(?i)^(answer:|the answer is)\s*", "", answer)
|
| 41 |
+
|
| 42 |
+
# Keep full line, keep units, keep words
|
| 43 |
+
answer = answer.split("\n")[0].strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
print(f"\nQ: {question}\nA: {answer}\n")
|
| 46 |
return answer
|