rubenml commited on
Commit
4bb5321
·
verified ·
1 Parent(s): a07469f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -11
app.py CHANGED
@@ -14,26 +14,25 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
  class BasicAgent:
16
  def __init__(self):
17
- print("Initializing T5-based QA agent with custom prompt...")
18
- # Load the T5 model
19
- self.qa_pipeline = pipeline("text2text-generation", model="t5-large")
20
 
21
- def __call__(self, question: str) -> str:
22
  """
23
- Process the question using T5 with a clear and structured prompt, and return an answer.
24
  """
25
- # Create a clearer and more direct prompt
26
- prompt = f"Answer the following question: {question}"
27
-
28
  try:
29
- # Use the T5 pipeline to generate an answer
30
- result = self.qa_pipeline(prompt)
31
- answer = result[0]["generated_text"].strip()
32
  except Exception as e:
33
  print(f"Error during QA: {e}")
34
  answer = "Error processing question."
35
 
36
  return answer
 
 
37
  def run_and_submit_all( profile: gr.OAuthProfile | None):
38
  """
39
  Fetches all questions, runs the BasicAgent on them, submits all answers,
 
14
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
15
  class BasicAgent:
16
  def __init__(self):
17
+ print("Initializing BERT-based QA agent...")
18
+ # Load the BERT model fine-tuned on the SQuAD dataset
19
+ self.qa_pipeline = pipeline("question-answering", model="bert-large-uncased-whole-word-masking-finetuned-squad")
20
 
21
+ def __call__(self, question: str, context: str) -> str:
22
  """
23
+ Process the question using the BERT model fine-tuned on SQuAD, and return an answer based on the context.
24
  """
 
 
 
25
  try:
26
+ # Use the QA pipeline to get an answer based on the context and the question
27
+ result = self.qa_pipeline(question=question, context=context)
28
+ answer = result["answer"]
29
  except Exception as e:
30
  print(f"Error during QA: {e}")
31
  answer = "Error processing question."
32
 
33
  return answer
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,