Annessha18 commited on
Commit
860a4ac
·
verified ·
1 Parent(s): 4921fed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -16
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=32,
21
- temperature=0.0, # VERY IMPORTANT: deterministic
22
  do_sample=False
23
  )
24
 
25
  def __call__(self, question: str) -> str:
26
  prompt = (
27
- "Answer the question with ONLY the final answer.\n"
28
- "No explanation. No extra words. No punctuation.\n\n"
29
- f"Question: {question}\n"
 
30
  "Answer:"
31
  )
32
 
33
  result = self.generator(prompt)[0]["generated_text"]
34
 
35
- # ---------- STRONG CLEANUP ----------
36
  answer = result.strip()
37
- answer = re.sub(r"(?i)^(the answer is|answer:)\s*", "", answer)
38
- answer = re.split(r"[\n\.]", answer)[0]
39
- answer = answer.strip()
40
- answer = answer.rstrip(".,;:")
41
-
42
- # Normalize boolean answers
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