sanjaystarc commited on
Commit
8aa686d
·
verified ·
1 Parent(s): 657e20c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -17
app.py CHANGED
@@ -4,10 +4,14 @@ import requests
4
  import pandas as pd
5
  import math
6
 
7
- from smolagents import CodeAgent, HfApiModel, tool
 
8
  from duckduckgo_search import DDGS
9
 
10
- # --- Constants (DO NOT CHANGE) ---
 
 
 
11
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
12
 
13
  # --------------------------------------------------
@@ -16,7 +20,7 @@ DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
16
 
17
  @tool
18
  def web_search(query: str) -> str:
19
- """Search the web and return short factual text."""
20
  with DDGS() as ddgs:
21
  results = list(ddgs.text(query, max_results=3))
22
  if not results:
@@ -37,13 +41,16 @@ def calculator(expression: str) -> str:
37
 
38
  class BasicAgent:
39
  def __init__(self):
40
- model = HfApiModel("meta-llama/Meta-Llama-3-8B-Instruct")
 
 
 
41
  self.agent = CodeAgent(
42
  tools=[web_search, calculator],
43
  model=model,
44
  system_prompt=(
45
  "You are a precise AI agent.\n"
46
- "Solve the task using tools if needed.\n"
47
  "Return ONLY the final answer.\n"
48
  "No explanation. No markdown. No extra words."
49
  ),
@@ -58,21 +65,21 @@ class BasicAgent:
58
  return "I don't know"
59
 
60
  # --------------------------------------------------
61
- # MAIN EVALUATION + SUBMISSION LOGIC (DO NOT CHANGE)
 
62
  # --------------------------------------------------
63
 
64
  def run_and_submit_all(profile: gr.OAuthProfile | None):
65
 
66
  space_id = os.getenv("SPACE_ID")
67
 
68
- if profile:
69
- username = profile.username
70
- else:
71
  return "Please login to Hugging Face.", None
72
 
73
- api_url = DEFAULT_API_URL
74
- questions_url = f"{api_url}/questions"
75
- submit_url = f"{api_url}/submit"
 
76
 
77
  # Instantiate agent
78
  try:
@@ -141,22 +148,23 @@ def run_and_submit_all(profile: gr.OAuthProfile | None):
141
  return f"Submission failed: {e}", pd.DataFrame(results_log)
142
 
143
  # --------------------------------------------------
144
- # GRADIO UI (DO NOT CHANGE)
145
  # --------------------------------------------------
146
 
147
  with gr.Blocks() as demo:
148
- gr.Markdown("# GAIA Level-1 Agent Evaluation")
149
 
150
  gr.Markdown(
151
  """
152
  **Instructions**
153
- 1. Login with Hugging Face
154
- 2. Click the button to run evaluation
155
- 3. Wait for submission and score
156
  """
157
  )
158
 
159
  gr.LoginButton()
 
160
  run_button = gr.Button("Run Evaluation & Submit All Answers")
161
 
162
  status_output = gr.Textbox(label="Submission Result", lines=5)
 
4
  import pandas as pd
5
  import math
6
 
7
+ from smolagents import CodeAgent, tool
8
+ from smolagents.models import LiteLLMModel
9
  from duckduckgo_search import DDGS
10
 
11
+ # --------------------------------------------------
12
+ # CONSTANTS (DO NOT CHANGE)
13
+ # --------------------------------------------------
14
+
15
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
16
 
17
  # --------------------------------------------------
 
20
 
21
  @tool
22
  def web_search(query: str) -> str:
23
+ """Search the web and return factual text."""
24
  with DDGS() as ddgs:
25
  results = list(ddgs.text(query, max_results=3))
26
  if not results:
 
41
 
42
  class BasicAgent:
43
  def __init__(self):
44
+ model = LiteLLMModel(
45
+ model_id="huggingface/meta-llama/Meta-Llama-3-8B-Instruct"
46
+ )
47
+
48
  self.agent = CodeAgent(
49
  tools=[web_search, calculator],
50
  model=model,
51
  system_prompt=(
52
  "You are a precise AI agent.\n"
53
+ "Solve the question using tools if needed.\n"
54
  "Return ONLY the final answer.\n"
55
  "No explanation. No markdown. No extra words."
56
  ),
 
65
  return "I don't know"
66
 
67
  # --------------------------------------------------
68
+ # MAIN EVALUATION + SUBMISSION LOGIC
69
+ # (KEEP AS IS)
70
  # --------------------------------------------------
71
 
72
  def run_and_submit_all(profile: gr.OAuthProfile | None):
73
 
74
  space_id = os.getenv("SPACE_ID")
75
 
76
+ if not profile:
 
 
77
  return "Please login to Hugging Face.", None
78
 
79
+ username = profile.username
80
+
81
+ questions_url = f"{DEFAULT_API_URL}/questions"
82
+ submit_url = f"{DEFAULT_API_URL}/submit"
83
 
84
  # Instantiate agent
85
  try:
 
148
  return f"Submission failed: {e}", pd.DataFrame(results_log)
149
 
150
  # --------------------------------------------------
151
+ # GRADIO UI
152
  # --------------------------------------------------
153
 
154
  with gr.Blocks() as demo:
155
+ gr.Markdown("# GAIA Level-1 Agent – Final Assignment")
156
 
157
  gr.Markdown(
158
  """
159
  **Instructions**
160
+ 1. Login with your Hugging Face account
161
+ 2. Click the button below
162
+ 3. Wait for the agent to answer all questions and submit
163
  """
164
  )
165
 
166
  gr.LoginButton()
167
+
168
  run_button = gr.Button("Run Evaluation & Submit All Answers")
169
 
170
  status_output = gr.Textbox(label="Submission Result", lines=5)