cousintiz commited on
Commit
55f54a1
·
1 Parent(s): 81917a3

first commit

Browse files
Files changed (2) hide show
  1. app.py +63 -7
  2. requirements.txt +4 -1
app.py CHANGED
@@ -3,21 +3,77 @@ import gradio as gr
3
  import requests
4
  import inspect
5
  import pandas as pd
 
 
 
6
 
7
  # (Keep Constants as is)
8
  # --- Constants ---
9
  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
  """
@@ -40,7 +96,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
40
 
41
  # 1. Instantiate Agent ( modify this part to create your agent)
42
  try:
43
- agent = BasicAgent()
44
  except Exception as e:
45
  print(f"Error instantiating agent: {e}")
46
  return f"Error initializing agent: {e}", None
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, HfApiModel
7
+ from smolagents.tools import DuckDuckGoSearchTool, PythonInterpreterTool
8
+
9
 
10
  # (Keep Constants as is)
11
  # --- Constants ---
12
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
13
 
14
+ GAIA_SYSTEM_PROMPT = """
15
+ You are solving GAIA level 1 questions.
16
+
17
+ Return only your answer, which should be a number, or a short phrase with as few words as possible,
18
+ or a comma separated list of numbers and/or strings.
19
+
20
+ If the answer is a number, return only the number without any units unless specified otherwise.
21
+ If the answer is a string, don't include articles, and don't use abbreviations.
22
+ If the answer is a comma separated list, apply the above rules to each element.
23
+ Do NOT write 'FINAL ANSWER:' – return only the raw answer.
24
+ """
25
+
26
+
27
  # --- Basic Agent Definition ---
28
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
29
+ class SmolGaiaAgent:
30
+ """
31
+ Wraps a smolagents CodeAgent so that we can call it like a simple function:
32
+ answer = agent(question).
33
+ """
34
+
35
  def __init__(self):
36
+ print("Initializing SmolGaiaAgent...")
37
+
38
+ # 1) Model via HF router
39
+ # Make sure you have a valid HF token in the Space secrets if the model is gated.
40
+ self.model = HfApiModel(
41
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct", # or another strong chat/coder model on HF
42
+ api_key=os.getenv("HF_TOKEN"), # add HF_TOKEN secret in the Space
43
+ # base_url="https://router.huggingface.co", # optional, recent smolagents use router by default
44
+ )
45
+
46
+ # 2) Tools: web search + python
47
+ self.tools = [
48
+ DuckDuckGoSearchTool(),
49
+ PythonInterpreterTool(),
50
+ ]
51
+
52
+ # 3) CodeAgent
53
+ self.agent = CodeAgent(
54
+ tools=self.tools,
55
+ model=self.model,
56
+ max_steps=8,
57
+ name="gaia-code-agent",
58
+ description="Agent that uses web search and python to solve GAIA level 1 questions.",
59
+ # you can tune other args later: planning_interval, verbosity, etc.
60
+ )
61
+
62
  def __call__(self, question: str) -> str:
63
+ """
64
+ Runs the CodeAgent on one question and returns the final answer string.
65
+ """
66
+ print(f"[SmolGaiaAgent] Question: {question[:80]}...")
67
+ # Many course examples use `run()` on the agent
68
+ answer = self.agent.run(
69
+ question,
70
+ system_prompt=GAIA_SYSTEM_PROMPT,
71
+ )
72
+ # Make sure we cast to str just in case
73
+ answer = str(answer).strip()
74
+ print(f"[SmolGaiaAgent] Answer: {answer}")
75
+ return answer
76
+
77
 
78
  def run_and_submit_all( profile: gr.OAuthProfile | None):
79
  """
 
96
 
97
  # 1. Instantiate Agent ( modify this part to create your agent)
98
  try:
99
+ agent = SmolGaiaAgent()
100
  except Exception as e:
101
  print(f"Error instantiating agent: {e}")
102
  return f"Error initializing agent: {e}", None
requirements.txt CHANGED
@@ -1,2 +1,5 @@
1
  gradio
2
- requests
 
 
 
 
1
  gradio
2
+ pandas
3
+ requests
4
+ smolagents
5
+ duckduckgo-search