Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from smolagents import CodeAgent, DuckDuckGoSearchTool, FinalAnswerTool, HfApiModel, Tool, tool, VisitWebpageTool | |
| 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() |