Spaces:
Sleeping
Sleeping
import gradio as gr | |
from smolagents import WebSearchTool, VisitWebpageTool | |
def search_web(query: str) -> str: | |
""" | |
Performs a web search for a query and returns a string of the top search results formatted as markdown with titles, links, and descriptions. | |
Args: | |
query (str): The search query to perform. | |
Returns: | |
str: Web search results. | |
""" | |
tool = WebSearchTool() | |
return tool(query) | |
def visit_webpage(url: str) -> str: | |
""" | |
Visits a webpage at the given url and reads its content as a markdown string. Use this to browse webpages. | |
Args: | |
url (str): The url of the webpage to visit. | |
Returns: | |
str: Webpage content in markdown string format. | |
""" | |
tool = VisitWebpageTool() | |
return tool(url) | |
websearch = gr.Interface( | |
fn = search_web, | |
inputs = gr.Textbox(placeholder = "Enter your search query here.", label = "Search Query"), | |
outputs = gr.TextArea(), | |
title = "Web Search", | |
description = "Perform web search on search query.", | |
) | |
visitwebpage = gr.Interface( | |
fn = visit_webpage, | |
inputs = gr.Textbox(placeholder = "Enter your URL here.", label = "URL"), | |
outputs = gr.TextArea(), | |
title = "Vist Webpage", | |
description = "Visit webpage at given URL.", | |
) | |
app = gr.TabbedInterface( | |
[websearch, visitwebpage], | |
["Web Search", "Visit Webpage"] | |
) | |
if __name__ == "__main__": | |
app.launch(mcp_server = True) |