Added web_search and page crawling tools.
Browse files- Gradio_UI.py +2 -3
- app.py +8 -1
- tools/visit_webpage.py +1 -0
Gradio_UI.py
CHANGED
@@ -158,10 +158,9 @@ def stream_to_gradio(
|
|
158 |
if isinstance(final_answer.final_answer, AgentText):
|
159 |
yield gr.ChatMessage(
|
160 |
role="assistant",
|
161 |
-
content=
|
162 |
)
|
163 |
elif isinstance(final_answer.final_answer, AgentImage):
|
164 |
-
|
165 |
yield gr.ChatMessage(
|
166 |
role="assistant",
|
167 |
content=gr.Image(str(final_answer.final_answer)),
|
@@ -173,7 +172,7 @@ def stream_to_gradio(
|
|
173 |
content={"path": final_answer.to_string(), "mime_type": "audio/wav"},
|
174 |
)
|
175 |
else:
|
176 |
-
yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer)}")
|
177 |
|
178 |
|
179 |
class GradioUI:
|
|
|
158 |
if isinstance(final_answer.final_answer, AgentText):
|
159 |
yield gr.ChatMessage(
|
160 |
role="assistant",
|
161 |
+
content=str(final_answer.final_answer)
|
162 |
)
|
163 |
elif isinstance(final_answer.final_answer, AgentImage):
|
|
|
164 |
yield gr.ChatMessage(
|
165 |
role="assistant",
|
166 |
content=gr.Image(str(final_answer.final_answer)),
|
|
|
172 |
content={"path": final_answer.to_string(), "mime_type": "audio/wav"},
|
173 |
)
|
174 |
else:
|
175 |
+
yield gr.ChatMessage(role="assistant", content=f"**Final answer:** {str(final_answer.final_answer)}")
|
176 |
|
177 |
|
178 |
class GradioUI:
|
app.py
CHANGED
@@ -1,9 +1,12 @@
|
|
1 |
-
from smolagents import CodeAgent,
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
|
|
|
|
|
|
7 |
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
@@ -35,6 +38,8 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
35 |
|
36 |
|
37 |
final_answer = FinalAnswerTool()
|
|
|
|
|
38 |
|
39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
@@ -57,6 +62,8 @@ demo = CodeAgent(
|
|
57 |
tools=[
|
58 |
get_current_time_in_timezone,
|
59 |
image_generation_tool,
|
|
|
|
|
60 |
final_answer
|
61 |
], ## add your tools here (don't remove final answer)
|
62 |
max_steps=6,
|
|
|
1 |
+
from smolagents import CodeAgent, HfApiModel, load_tool, tool #DuckDuckGoSearchTool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
+
from tools.visit_webpage import VisitWebpageTool
|
8 |
+
from tools.web_search import DuckDuckGoSearchTool
|
9 |
+
|
10 |
|
11 |
from Gradio_UI import GradioUI
|
12 |
|
|
|
38 |
|
39 |
|
40 |
final_answer = FinalAnswerTool()
|
41 |
+
web_search = DuckDuckGoSearchTool()
|
42 |
+
visit_page = VisitWebpageTool()
|
43 |
|
44 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
45 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
62 |
tools=[
|
63 |
get_current_time_in_timezone,
|
64 |
image_generation_tool,
|
65 |
+
web_search,
|
66 |
+
visit_page,
|
67 |
final_answer
|
68 |
], ## add your tools here (don't remove final answer)
|
69 |
max_steps=6,
|
tools/visit_webpage.py
CHANGED
@@ -3,6 +3,7 @@ from smolagents.tools import Tool
|
|
3 |
import requests
|
4 |
import markdownify
|
5 |
import smolagents
|
|
|
6 |
|
7 |
class VisitWebpageTool(Tool):
|
8 |
name = "visit_webpage"
|
|
|
3 |
import requests
|
4 |
import markdownify
|
5 |
import smolagents
|
6 |
+
import re
|
7 |
|
8 |
class VisitWebpageTool(Tool):
|
9 |
name = "visit_webpage"
|