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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -6
app.py CHANGED
@@ -11,21 +11,23 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
  # --- Basic Agent Definition ---
13
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
14
  class BasicAgent:
15
  def __init__(self):
16
- print("Loading Hugging Face model...")
17
  self.pipeline = pipeline(
18
- "text-generation",
19
- model="HuggingFaceH4/zephyr-7b-beta",
20
- max_new_tokens=256
21
  )
22
  print("Model loaded.")
23
 
24
  def __call__(self, question: str) -> str:
25
  print(f"Received question: {question[:60]}...")
26
- prompt = f"Answer the question clearly and concisely:\n{question.strip()}\nAnswer:"
27
  response = self.pipeline(prompt)[0]["generated_text"]
28
- answer = response.split("Answer:")[-1].strip().split("\n")[0]
29
  print(f"Generated answer: {answer}")
30
  return answer
31
 
@@ -33,6 +35,7 @@ class BasicAgent:
33
 
34
 
35
 
 
36
  def run_and_submit_all( profile: gr.OAuthProfile | None):
37
  """
38
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
11
 
12
  # --- Basic Agent Definition ---
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
 
 
35
 
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,