Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -5,14 +5,12 @@ import inspect
|
|
5 |
import pandas as pd
|
6 |
import gradio as gr
|
7 |
import random
|
8 |
-
from langchain_core.messages import HumanMessage
|
9 |
|
|
|
|
|
10 |
|
11 |
# Import our custom tools from their modules
|
12 |
from langchain_community.tools import DuckDuckGoSearchRun
|
13 |
-
from smolagents import GradioUI, CodeAgent, HfApiModel
|
14 |
-
|
15 |
-
|
16 |
|
17 |
# Initialize the Hugging Face model
|
18 |
model = HfApiModel()
|
@@ -20,11 +18,21 @@ model = HfApiModel()
|
|
20 |
# Initialize the web search tool
|
21 |
search_tool = DuckDuckGoSearchRun()
|
22 |
|
|
|
|
|
|
|
|
|
|
|
23 |
|
|
|
|
|
24 |
|
|
|
|
|
25 |
|
|
|
26 |
agent = CodeAgent(
|
27 |
-
tools=[
|
28 |
model=model,
|
29 |
add_base_tools=True, # Add any additional base tools
|
30 |
planning_interval=3 # Enable planning every 3 steps
|
@@ -124,7 +132,7 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
124 |
print("Agent did not produce any answers to submit.")
|
125 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
126 |
|
127 |
-
# 4. Prepare Submission
|
128 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
129 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
130 |
print(status_update)
|
@@ -172,7 +180,6 @@ def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
172 |
results_df = pd.DataFrame(results_log)
|
173 |
return status_message, results_df
|
174 |
|
175 |
-
|
176 |
# --- Build Gradio Interface using Blocks ---
|
177 |
with gr.Blocks() as demo:
|
178 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
@@ -224,4 +231,4 @@ if __name__ == "__main__":
|
|
224 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
225 |
|
226 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
227 |
-
demo.launch(debug=True, share=False)
|
|
|
5 |
import pandas as pd
|
6 |
import gradio as gr
|
7 |
import random
|
|
|
8 |
|
9 |
+
from langchain_core.messages import HumanMessage
|
10 |
+
from smolagents import GradioUI, CodeAgent, HfApiModel, Tool
|
11 |
|
12 |
# Import our custom tools from their modules
|
13 |
from langchain_community.tools import DuckDuckGoSearchRun
|
|
|
|
|
|
|
14 |
|
15 |
# Initialize the Hugging Face model
|
16 |
model = HfApiModel()
|
|
|
18 |
# Initialize the web search tool
|
19 |
search_tool = DuckDuckGoSearchRun()
|
20 |
|
21 |
+
# Custom Tool Class
|
22 |
+
class CustomSearchTool(Tool):
|
23 |
+
def __init__(self, search_tool):
|
24 |
+
super().__init__()
|
25 |
+
self.search_tool = search_tool
|
26 |
|
27 |
+
def run(self, query):
|
28 |
+
return self.search_tool.run(query)
|
29 |
|
30 |
+
# Wrap the search tool in your custom tool class
|
31 |
+
custom_search_tool = CustomSearchTool(search_tool)
|
32 |
|
33 |
+
# Initialize the agent with the custom tool
|
34 |
agent = CodeAgent(
|
35 |
+
tools=[custom_search_tool],
|
36 |
model=model,
|
37 |
add_base_tools=True, # Add any additional base tools
|
38 |
planning_interval=3 # Enable planning every 3 steps
|
|
|
132 |
print("Agent did not produce any answers to submit.")
|
133 |
return "Agent did not produce any answers to submit.", pd.DataFrame(results_log)
|
134 |
|
135 |
+
# 4. Prepare Submission
|
136 |
submission_data = {"username": username.strip(), "agent_code": agent_code, "answers": answers_payload}
|
137 |
status_update = f"Agent finished. Submitting {len(answers_payload)} answers for user '{username}'..."
|
138 |
print(status_update)
|
|
|
180 |
results_df = pd.DataFrame(results_log)
|
181 |
return status_message, results_df
|
182 |
|
|
|
183 |
# --- Build Gradio Interface using Blocks ---
|
184 |
with gr.Blocks() as demo:
|
185 |
gr.Markdown("# Basic Agent Evaluation Runner")
|
|
|
231 |
print("-"*(60 + len(" App Starting ")) + "\n")
|
232 |
|
233 |
print("Launching Gradio Interface for Basic Agent Evaluation...")
|
234 |
+
demo.launch(debug=True, share=False)
|