Spaces:
Sleeping
Sleeping
File size: 1,448 Bytes
21a1823 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import gradio as gr
from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, HfApiModel, Tool, tool, VisitWebpageTool
@tool
def search_web(query: str) -> str:
"""
Searches the web for information.
Args:
query: The search query string
Returns:
str: Search results summary
"""
search_tool = DuckDuckGoSearchTool()
return search_tool.forward(query)
# Create the agent
agent = CodeAgent(
tools=[
DuckDuckGoSearchTool(),
VisitWebpageTool(),
search_web
],
model=HfApiModel(),
max_steps=5,
verbosity_level=2
)
def process_query(query):
"""Process the user query using the agent."""
try:
result = agent.run(query)
return result
except Exception as e:
return f"An error occurred: {str(e)}"
# Create Gradio interface
iface = gr.Interface(
fn=process_query,
inputs=gr.Textbox(label="Enter your query", placeholder="What would you like to know about?"),
outputs=gr.Textbox(label="Results"),
title="Web Search Tool",
description="Enter any topic to get information from the web.",
examples=[
["Latest developments in quantum computing"],
["Current trends in artificial intelligence"],
["Recent breakthroughs in renewable energy"]
]
)
# Launch the app
if __name__ == "__main__":
iface.launch() |