iorikyo commited on
Commit
8a4b920
·
verified ·
1 Parent(s): a0f9df9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -13
app.py CHANGED
@@ -3,21 +3,48 @@ 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
  """
@@ -36,11 +63,9 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
36
 
37
  api_url = DEFAULT_API_URL
38
  questions_url = f"{api_url}/questions"
39
- submit_url = f"{api_url}/submit"
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
@@ -142,7 +167,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
142
 
143
  # --- Build Gradio Interface using Blocks ---
144
  with gr.Blocks() as demo:
145
- gr.Markdown("# Basic Agent Evaluation Runner")
146
  gr.Markdown(
147
  """
148
  **Instructions:**
@@ -151,6 +176,12 @@ with gr.Blocks() as demo:
151
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
152
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
153
 
 
 
 
 
 
 
154
  ---
155
  **Disclaimers:**
156
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
@@ -192,5 +223,5 @@ if __name__ == "__main__":
192
 
193
  print("-"*(60 + len(" App Starting ")) + "\n")
194
 
195
- print("Launching Gradio Interface for Basic Agent Evaluation...")
196
  demo.launch(debug=True, share=False)
 
3
  import requests
4
  import inspect
5
  import pandas as pd
6
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, InferenceClientModel
7
 
8
  # (Keep Constants as is)
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
+ # --- SmolaAgent Implementation ---
13
+ # ----- THIS IS WHERE YOU CAN BUILD WHAT YOU WANT ------
14
+ class SmolaAgent:
15
  def __init__(self):
16
+ print("SmolaAgent initialized.")
17
+ try:
18
+ # Initialize the CodeAgent with DuckDuckGoSearchTool and InferenceClientModel
19
+ self.agent = CodeAgent(
20
+ tools=[DuckDuckGoSearchTool()],
21
+ model=InferenceClientModel(),
22
+ add_base_tools=True, # Add additional base tools like web search
23
+ verbosity_level=1 # Show some debug information
24
+ )
25
+ print("CodeAgent successfully initialized with DuckDuckGoSearchTool.")
26
+ except Exception as e:
27
+ print(f"Error initializing CodeAgent: {e}")
28
+ # Fallback to a simple agent if initialization fails
29
+ self.agent = None
30
+
31
  def __call__(self, question: str) -> str:
32
  print(f"Agent received question (first 50 chars): {question[:50]}...")
33
+
34
+ if self.agent is None:
35
+ fallback_answer = "Agent initialization failed, providing fallback response."
36
+ print(f"Agent returning fallback answer: {fallback_answer}")
37
+ return fallback_answer
38
+
39
+ try:
40
+ # Use the CodeAgent to process the question
41
+ result = self.agent.run(question)
42
+ print(f"Agent returning result: {str(result)[:100]}...")
43
+ return str(result)
44
+ except Exception as e:
45
+ error_message = f"Error running agent: {str(e)}"
46
+ print(error_message)
47
+ return error_message
48
 
49
  def run_and_submit_all( profile: gr.OAuthProfile | None):
50
  """
 
63
 
64
  api_url = DEFAULT_API_URL
65
  questions_url = f"{api_url}/questions"
66
+ submit_url = f"{api_url}/submit" # 1. Instantiate Agent ( modify this part to create your agent)
 
 
67
  try:
68
+ agent = SmolaAgent()
69
  except Exception as e:
70
  print(f"Error instantiating agent: {e}")
71
  return f"Error initializing agent: {e}", None
 
167
 
168
  # --- Build Gradio Interface using Blocks ---
169
  with gr.Blocks() as demo:
170
+ gr.Markdown("# SmolaAgent Evaluation Runner")
171
  gr.Markdown(
172
  """
173
  **Instructions:**
 
176
  2. Log in to your Hugging Face account using the button below. This uses your HF username for submission.
177
  3. Click 'Run Evaluation & Submit All Answers' to fetch questions, run your agent, submit answers, and see the score.
178
 
179
+ **Agent Details:**
180
+ - Uses **smolagents** library with **CodeAgent**
181
+ - Equipped with **DuckDuckGoSearchTool** for web search capabilities
182
+ - Powered by **InferenceClientModel** for advanced reasoning
183
+ - Includes base tools for enhanced functionality
184
+
185
  ---
186
  **Disclaimers:**
187
  Once clicking on the "submit button, it can take quite some time ( this is the time for the agent to go through all the questions).
 
223
 
224
  print("-"*(60 + len(" App Starting ")) + "\n")
225
 
226
+ print("Launching Gradio Interface for SmolaAgent Evaluation...")
227
  demo.launch(debug=True, share=False)