jesusgj commited on
Commit
fbd2cf1
Β·
1 Parent(s): 914cd84

Modified files

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. agent.py +1 -0
  3. app.py +19 -10
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Agent Agents Course
3
  emoji: πŸ“š
4
  colorFrom: green
5
  colorTo: yellow
 
1
  ---
2
+ title: Agents Course
3
  emoji: πŸ“š
4
  colorFrom: green
5
  colorTo: yellow
agent.py CHANGED
@@ -66,6 +66,7 @@ def initialize_agent():
66
  model=model,
67
  managed_agents=[web_agent],
68
  additional_authorized_imports=["time", "numpy", "pandas"],
 
69
  )
70
  return manager_agent
71
  else:
 
66
  model=model,
67
  managed_agents=[web_agent],
68
  additional_authorized_imports=["time", "numpy", "pandas"],
69
+ system_prompt="""You are a general AI assistant. I will ask you a question. Report your thoughts, and finish your answer with the following template: FINAL ANSWER: [YOUR FINAL ANSWER]. YOUR FINAL ANSWER should be a number OR as few words as possible OR a comma separated list of numbers and/or strings. If you are asked for a number, don't use comma to write your number neither use units such as $ or percent sign unless specified otherwise. If you are asked for a string, don't use articles, neither abbreviations (e.g. for cities), and write the digits in plain text unless specified otherwise. If you are asked for a comma separated list, apply the above rules depending of whether the element to be put in the list is a number or a string."""
70
  )
71
  return manager_agent
72
  else:
app.py CHANGED
@@ -1,19 +1,21 @@
 
1
  import gradio as gr
2
  import requests
 
3
  from agent import initialize_agent
4
 
5
  # 1. Initialize the agent
6
  manager_agent = initialize_agent()
7
 
8
  # 2. Define the API URL
9
- API_URL = "https://gaia-benchmark-dev.hf.space"
10
 
11
  # 3. Gradio interface
12
  def run_evaluation(hf_username, space_url):
13
  if not manager_agent:
14
- return "Agent could not be initialized. Please check the model and token."
15
  if not hf_username or not space_url:
16
- return "Please provide your Hugging Face username and Space URL."
17
 
18
  try:
19
  # Get questions
@@ -29,12 +31,19 @@ def run_evaluation(hf_username, space_url):
29
  prompt = question["question"]
30
  print(f"Answering question {i+1}/{len(questions)}: {prompt}")
31
  try:
32
- answer = manager_agent.run(prompt)
33
- answers.append({"question_id": question["id"], "answer": answer})
 
 
 
 
 
 
 
34
  print(f"Got answer: {answer}")
35
  except Exception as e:
36
  print(f"Error running agent on question {question['id']}: {e}")
37
- answers.append({"question_id": question["id"], "answer": "Error: Could not generate an answer."})
38
 
39
  # Submit answers
40
  print("Submitting answers...")
@@ -43,7 +52,7 @@ def run_evaluation(hf_username, space_url):
43
  json={
44
  "hf_username": hf_username,
45
  "answers": answers,
46
- "space_url": space_url
47
  }
48
  )
49
  submission_response.raise_for_status()
@@ -51,10 +60,10 @@ def run_evaluation(hf_username, space_url):
51
  return submission_response.json()
52
  except requests.exceptions.RequestException as e:
53
  print(f"An error occurred: {e}")
54
- return f"An error occurred: {e}"
55
  except Exception as e:
56
  print(f"An unexpected error occurred: {e}")
57
- return f"An unexpected error occurred: {e}"
58
 
59
  with gr.Blocks() as demo:
60
  gr.Markdown("# GAIA Benchmark Evaluation with smolagent")
@@ -72,4 +81,4 @@ with gr.Blocks() as demo:
72
  )
73
 
74
  if __name__ == "__main__":
75
- demo.launch()
 
1
+
2
  import gradio as gr
3
  import requests
4
+ import re
5
  from agent import initialize_agent
6
 
7
  # 1. Initialize the agent
8
  manager_agent = initialize_agent()
9
 
10
  # 2. Define the API URL
11
+ API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
  # 3. Gradio interface
14
  def run_evaluation(hf_username, space_url):
15
  if not manager_agent:
16
+ return {"error": "Agent could not be initialized. Please check the model and token."}
17
  if not hf_username or not space_url:
18
+ return {"error": "Please provide your Hugging Face username and Space URL."}
19
 
20
  try:
21
  # Get questions
 
31
  prompt = question["question"]
32
  print(f"Answering question {i+1}/{len(questions)}: {prompt}")
33
  try:
34
+ raw_answer = manager_agent.run(prompt)
35
+ # Extract the final answer
36
+ match = re.search(r"FINAL ANSWER: (.*)", raw_answer, re.IGNORECASE)
37
+ if match:
38
+ answer = match.group(1).strip()
39
+ else:
40
+ answer = raw_answer # Fallback to the raw answer if the pattern is not found
41
+
42
+ answers.append({"task_id": question["id"], "submitted_answer": answer})
43
  print(f"Got answer: {answer}")
44
  except Exception as e:
45
  print(f"Error running agent on question {question['id']}: {e}")
46
+ answers.append({"task_id": question["id"], "submitted_answer": "Error: Could not generate an answer."})
47
 
48
  # Submit answers
49
  print("Submitting answers...")
 
52
  json={
53
  "hf_username": hf_username,
54
  "answers": answers,
55
+ "agent_code": space_url
56
  }
57
  )
58
  submission_response.raise_for_status()
 
60
  return submission_response.json()
61
  except requests.exceptions.RequestException as e:
62
  print(f"An error occurred: {e}")
63
+ return {"error": f"An error occurred: {e}"}
64
  except Exception as e:
65
  print(f"An unexpected error occurred: {e}")
66
+ return {"error": f"An unexpected error occurred: {e}"}
67
 
68
  with gr.Blocks() as demo:
69
  gr.Markdown("# GAIA Benchmark Evaluation with smolagent")
 
81
  )
82
 
83
  if __name__ == "__main__":
84
+ demo.launch()