File size: 1,139 Bytes
5cbeb2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e3d3c7
4d86236
1e3d3c7
 
 
 
 
 
5cbeb2d
 
 
 
 
 
 
 
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
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)