Vani7065 commited on
Commit
0adac64
·
verified ·
1 Parent(s): 81917a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -5
app.py CHANGED
@@ -10,14 +10,24 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
 
 
13
  class BasicAgent:
14
  def __init__(self):
15
- print("BasicAgent initialized.")
 
 
16
  def __call__(self, question: str) -> str:
17
- print(f"Agent received question (first 50 chars): {question[:50]}...")
18
- fixed_answer = "This is a default answer."
19
- print(f"Agent returning fixed answer: {fixed_answer}")
20
- return fixed_answer
 
 
 
 
 
 
21
 
22
  def run_and_submit_all( profile: gr.OAuthProfile | None):
23
  """
 
10
 
11
  # --- Basic Agent Definition ---
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
+ from transformers import pipeline
14
+
15
  class BasicAgent:
16
  def __init__(self):
17
+ print("Initializing BasicAgent with a transformer model...")
18
+ self.qa_pipeline = pipeline("text-generation", model="gpt2") # You can change model if needed
19
+
20
  def __call__(self, question: str) -> str:
21
+ print(f"Agent received question: {question}")
22
+ try:
23
+ response = self.qa_pipeline(question, max_length=100, do_sample=True)
24
+ answer = response[0]["generated_text"]
25
+ print(f"Generated answer: {answer}")
26
+ return answer.strip()
27
+ except Exception as e:
28
+ print(f"Error during model generation: {e}")
29
+ return f"Error generating answer: {e}"
30
+
31
 
32
  def run_and_submit_all( profile: gr.OAuthProfile | None):
33
  """