Ubik80 commited on
Commit
38c5e1d
·
verified ·
1 Parent(s): 83dce65
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import os
2
  import gradio as gr
3
  import requests
@@ -5,30 +6,32 @@ import pandas as pd
5
 
6
  from tools import AnswerTool
7
  from smolagents import CodeAgent, OpenAIServerModel
 
8
 
9
  # --- Constants ---
10
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
11
 
12
  class BasicAgent:
13
  def __init__(self):
14
- # Initialize CodeAgent with GPT-4o and only the custom AnswerTool
15
  model = OpenAIServerModel(model_id="gpt-4o")
16
  answer_tool = AnswerTool()
 
17
  self.agent = CodeAgent(
18
  model=model,
19
- tools=[answer_tool],
20
- add_base_tools=False,
21
- max_steps=1,
22
  verbosity_level=0
23
  )
24
 
25
  def __call__(self, question: str) -> str:
26
- # Single-step invocation of AnswerTool
27
  return self.agent.run(question)
28
 
29
 
30
  def run_and_submit_all(username):
31
- # Username provided manually by the user
32
  if not username:
33
  return "Please enter your Hugging Face username.", None
34
 
@@ -94,6 +97,7 @@ def test_random_question(username):
94
  except Exception as e:
95
  return f"Error during test: {e}", ""
96
 
 
97
  # --- Gradio UI ---
98
  with gr.Blocks() as demo:
99
  gr.Markdown("# Basic Agent Evaluation Runner")
@@ -110,13 +114,13 @@ with gr.Blocks() as demo:
110
  run_btn = gr.Button("Run Evaluation & Submit All Answers")
111
  test_btn = gr.Button("Test Random Question")
112
 
113
- status_out = gr.Textbox(label="Status / Result", lines=5, interactive=False)
114
- table_out = gr.DataFrame(label="Full Results Table", wrap=True)
115
  question_out = gr.Textbox(label="Random Question", lines=3, interactive=False)
116
- answer_out = gr.Textbox(label="Agent Answer", lines=3, interactive=False)
117
 
118
- run_btn.click(fn=run_and_submit_all, inputs=[username_input], outputs=[status_out, table_out])
119
  test_btn.click(fn=test_random_question, inputs=[username_input], outputs=[question_out, answer_out])
120
 
121
  if __name__ == "__main__":
122
- demo.launch(debug=True, share=False)
 
1
+ # app.py
2
  import os
3
  import gradio as gr
4
  import requests
 
6
 
7
  from tools import AnswerTool
8
  from smolagents import CodeAgent, OpenAIServerModel
9
+ from smolagents import DuckDuckGoSearchTool # ← importiamo il search tool
10
 
11
  # --- Constants ---
12
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
13
 
14
  class BasicAgent:
15
  def __init__(self):
16
+ # Initialize CodeAgent with GPT-4o, AnswerTool e DuckDuckGoSearchTool
17
  model = OpenAIServerModel(model_id="gpt-4o")
18
  answer_tool = AnswerTool()
19
+ web_tool = DuckDuckGoSearchTool()
20
  self.agent = CodeAgent(
21
  model=model,
22
+ tools=[answer_tool, web_tool], # ← due tool
23
+ add_base_tools=False, # niente altri tool
24
+ max_steps=2, # fino a due passaggi
25
  verbosity_level=0
26
  )
27
 
28
  def __call__(self, question: str) -> str:
29
+ # Fai girare l'agente: prima prova AnswerTool, poi DuckDuckGo se serve
30
  return self.agent.run(question)
31
 
32
 
33
  def run_and_submit_all(username):
34
+ # Username fornito manualmente
35
  if not username:
36
  return "Please enter your Hugging Face username.", None
37
 
 
97
  except Exception as e:
98
  return f"Error during test: {e}", ""
99
 
100
+
101
  # --- Gradio UI ---
102
  with gr.Blocks() as demo:
103
  gr.Markdown("# Basic Agent Evaluation Runner")
 
114
  run_btn = gr.Button("Run Evaluation & Submit All Answers")
115
  test_btn = gr.Button("Test Random Question")
116
 
117
+ status_out = gr.Textbox(label="Status / Result", lines=5, interactive=False)
118
+ table_out = gr.DataFrame(label="Full Results Table", wrap=True)
119
  question_out = gr.Textbox(label="Random Question", lines=3, interactive=False)
120
+ answer_out = gr.Textbox(label="Agent Answer", lines=3, interactive=False)
121
 
122
+ run_btn.click(fn=run_and_submit_all, inputs=[username_input], outputs=[status_out, table_out])
123
  test_btn.click(fn=test_random_question, inputs=[username_input], outputs=[question_out, answer_out])
124
 
125
  if __name__ == "__main__":
126
+ demo.launch(debug=True, share=False)