Praveen2915 commited on
Commit
80819cd
·
verified ·
1 Parent(s): 81917a3
Files changed (1) hide show
  1. app.py +60 -5
app.py CHANGED
@@ -12,12 +12,67 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
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
  """
 
12
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
13
  class BasicAgent:
14
  def __init__(self):
15
+ print("Initializing GAIA Agent...")
16
+
17
+ hf_token = os.getenv("HF_TOKEN")
18
+
19
+ if not hf_token:
20
+ raise ValueError("HF_TOKEN is not configured in Space Secrets.")
21
+
22
+ model = InferenceClientModel(
23
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct",
24
+ token=hf_token,
25
+ max_tokens=2048
26
+ )
27
+
28
+ self.agent = CodeAgent(
29
+ tools=[WebSearchTool(max_results=8)],
30
+ model=model,
31
+ additional_authorized_imports=[
32
+ "pandas",
33
+ "numpy",
34
+ "math",
35
+ "statistics",
36
+ "datetime",
37
+ "json",
38
+ "re"
39
+ ],
40
+ max_steps=8
41
+ )
42
+
43
+ print("GAIA Agent initialized successfully.")
44
+
45
  def __call__(self, question: str) -> str:
46
+ print(f"Agent received question: {question[:100]}...")
47
+
48
+ prompt = f"""
49
+ You are solving a GAIA benchmark question.
50
+
51
+ Solve the question carefully and use tools when necessary.
52
+
53
+ You can:
54
+ - Search the web when the question requires external information.
55
+ - Use Python for calculations, data processing, and reasoning.
56
+ - Carefully inspect the question before answering.
57
+ - Verify calculations before giving the final answer.
58
+
59
+ IMPORTANT:
60
+ Return ONLY the final answer.
61
+ Do not explain your reasoning.
62
+ Do not write "FINAL ANSWER".
63
+ Do not add unnecessary text.
64
+
65
+ Question:
66
+ {question}
67
+ """
68
+
69
+ result = self.agent.run(prompt)
70
+
71
+ answer = str(result).strip()
72
+
73
+ print(f"Agent final answer: {answer}")
74
+
75
+ return answer
76
 
77
  def run_and_submit_all( profile: gr.OAuthProfile | None):
78
  """