DeekshithN05 commited on
Commit
f5c297a
·
verified ·
1 Parent(s): 7b203fc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -5
app.py CHANGED
@@ -13,21 +13,35 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
  from transformers import pipeline
15
 
 
 
16
  class BasicAgent:
17
  def __init__(self):
18
- print("Loading lightweight FLAN-T5 model...")
19
  self.pipeline = pipeline(
20
  "text2text-generation",
21
- model="google/flan-t5-base",
22
- max_new_tokens=128
 
23
  )
24
  print("Model loaded.")
25
 
26
  def __call__(self, question: str) -> str:
27
  print(f"Received question: {question[:60]}...")
28
- prompt = f"Question: {question.strip()}\nAnswer:"
 
 
 
 
 
 
 
 
 
 
 
29
  response = self.pipeline(prompt)[0]["generated_text"]
30
- answer = response.strip().split("\n")[0]
31
  print(f"Generated answer: {answer}")
32
  return answer
33
 
@@ -36,6 +50,7 @@ class BasicAgent:
36
 
37
 
38
 
 
39
  def run_and_submit_all( profile: gr.OAuthProfile | None):
40
  """
41
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
14
  from transformers import pipeline
15
 
16
+ from transformers import pipeline
17
+
18
  class BasicAgent:
19
  def __init__(self):
20
+ print("Loading smarter model: flan-t5-xl...")
21
  self.pipeline = pipeline(
22
  "text2text-generation",
23
+ model="google/flan-t5-xl",
24
+ max_new_tokens=256,
25
+ temperature=0.2
26
  )
27
  print("Model loaded.")
28
 
29
  def __call__(self, question: str) -> str:
30
  print(f"Received question: {question[:60]}...")
31
+
32
+ few_shot_example = (
33
+ "Question: List just the vegetables from [milk, eggs, carrots, onions, cookies].\n"
34
+ "Answer: carrots, onions\n\n"
35
+ )
36
+
37
+ prompt = (
38
+ few_shot_example +
39
+ "Please solve the following step by step and give only the final answer:\n"
40
+ f"{question.strip()}"
41
+ )
42
+
43
  response = self.pipeline(prompt)[0]["generated_text"]
44
+ answer = response.strip().split("Answer:")[-1].strip().split("\n")[0]
45
  print(f"Generated answer: {answer}")
46
  return answer
47
 
 
50
 
51
 
52
 
53
+
54
  def run_and_submit_all( profile: gr.OAuthProfile | None):
55
  """
56
  Fetches all questions, runs the BasicAgent on them, submits all answers,