Annessha18 commited on
Commit
058e6c4
·
verified ·
1 Parent(s): ed95225

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
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-base",
23
  max_new_tokens=32
24
  )
25
 
26
  def __call__(self, question: str) -> str:
27
  prompt = (
28
- "Answer the question with ONLY the final answer. "
29
- "Do not add any extra words.\n"
30
- f"Question: {question}"
31
  )
 
32
  result = self.generator(prompt)[0]["generated_text"]
33
 
34
- # Post-process: keep only short answer
35
  answer = result.strip()
36
- answer = re.split(r"[.\n]", answer)[0] # cut after first sentence
 
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):