rajaramesh's picture
Update app.py
4d86236 verified
import gradio as gr
from duckduckgo_search import DDGS
def search_duckduckgo(query: str) -> list[dict]:
"""
Extract the information based on the query.
Args:
query (str): the query for getiing information
Returns:
list[dict]: A list of dictionaries containing title, href and body
"""
with DDGS() as ddgs:
results = ddgs.text(query, max_results=5)
# return "\n".join([f"{r['title']} - {r['href']} - {r['body']}" for r in results])
return results
with gr.Blocks() as app:
gr.Markdown("# DuckDuckGo Search Tool"),
gr.Markdown("## Please checkout below video to know about this MCP Server"),
gr.HTML(
"""<iframe width="560" height="315"
src="https://www.youtube.com/embed/0EE3sD1MHeg"
frameborder="0" allowfullscreen></iframe>""",
label="Featured Video"
),
with gr.Row():
query_input = gr.Textbox(label="Enter Search Query")
search_btn = gr.Button("Search")
output = gr.Textbox(label="Results", interactive=False)
search_btn.click(fn=search_duckduckgo, inputs=query_input, outputs=output)
app.launch(mcp_server=True)