mianf4884 commited on
Commit
56a7f71
·
verified ·
1 Parent(s): 284a233

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -10
app.py CHANGED
@@ -2,7 +2,8 @@ import os
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
5
- from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, VisitWebpageTool
 
6
 
7
  # --- Constants ---
8
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
@@ -10,13 +11,12 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
10
  # --- Agent Definition ---
11
  class AgentArchitect:
12
  def __init__(self):
13
- # Using a high-parameter model for better reasoning on the GAIA benchmark
14
- self.model = HfApiModel(model_id="Qwen/Qwen2.5-72B-Instruct")
 
15
 
16
- # Tools allow the agent to reach outside its training data
17
  self.tools = [DuckDuckGoSearchTool(), VisitWebpageTool()]
18
 
19
- # CodeAgent is superior here as it can write Python to solve the math/sorting questions
20
  self.agent = CodeAgent(
21
  tools=self.tools,
22
  model=self.model,
@@ -25,7 +25,6 @@ class AgentArchitect:
25
 
26
  def __call__(self, question: str) -> str:
27
  try:
28
- # We enforce conciseness to match the 'exact match' scoring of the leaderboard
29
  prompt = f"{question}\n\nFinal Answer Requirement: Provide ONLY the specific answer requested (number, name, or list) with no extra text."
30
  result = self.agent.run(prompt)
31
  return str(result)
@@ -44,10 +43,8 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
44
  submit_url = f"{api_url}/submit"
45
 
46
  try:
47
- # Initialize the new agent logic
48
  agent_instance = AgentArchitect()
49
 
50
- # Fetch Questions
51
  response = requests.get(questions_url, timeout=15)
52
  response.raise_for_status()
53
  questions_data = response.json()
@@ -59,13 +56,11 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
59
  task_id = item.get("task_id")
60
  question_text = item.get("question")
61
 
62
- # This is where the agent actually 'thinks'
63
  submitted_answer = agent_instance(question_text)
64
 
65
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
66
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
67
 
68
- # Submit to Leaderboard
69
  agent_code_link = f"https://huggingface.co/spaces/{space_id}/tree/main"
70
  submission_data = {"username": username.strip(), "agent_code": agent_code_link, "answers": answers_payload}
71
 
 
2
  import gradio as gr
3
  import requests
4
  import pandas as pd
5
+ # Fixed Imports for 2026 smolagents version
6
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, LiteLLMModel, VisitWebpageTool
7
 
8
  # --- Constants ---
9
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
 
11
  # --- Agent Definition ---
12
  class AgentArchitect:
13
  def __init__(self):
14
+ # We use LiteLLMModel here - it's the updated, more stable way to call HF models
15
+ # and other providers in the current smolagents version.
16
+ self.model = LiteLLMModel(model_id="huggingface/Qwen/Qwen2.5-72B-Instruct")
17
 
 
18
  self.tools = [DuckDuckGoSearchTool(), VisitWebpageTool()]
19
 
 
20
  self.agent = CodeAgent(
21
  tools=self.tools,
22
  model=self.model,
 
25
 
26
  def __call__(self, question: str) -> str:
27
  try:
 
28
  prompt = f"{question}\n\nFinal Answer Requirement: Provide ONLY the specific answer requested (number, name, or list) with no extra text."
29
  result = self.agent.run(prompt)
30
  return str(result)
 
43
  submit_url = f"{api_url}/submit"
44
 
45
  try:
 
46
  agent_instance = AgentArchitect()
47
 
 
48
  response = requests.get(questions_url, timeout=15)
49
  response.raise_for_status()
50
  questions_data = response.json()
 
56
  task_id = item.get("task_id")
57
  question_text = item.get("question")
58
 
 
59
  submitted_answer = agent_instance(question_text)
60
 
61
  answers_payload.append({"task_id": task_id, "submitted_answer": submitted_answer})
62
  results_log.append({"Task ID": task_id, "Question": question_text, "Submitted Answer": submitted_answer})
63
 
 
64
  agent_code_link = f"https://huggingface.co/spaces/{space_id}/tree/main"
65
  submission_data = {"username": username.strip(), "agent_code": agent_code_link, "answers": answers_payload}
66