Subham9126 commited on
Commit
e6a86e4
·
verified ·
1 Parent(s): 594b1ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -23
app.py CHANGED
@@ -1,33 +1,27 @@
1
  import gradio as gr
2
- from duckduckgo_search import DDGS
 
3
 
4
- def search_duckduckgo(query: str) -> list[dict]:
5
- """
6
- Extract the information based on the query.
7
- Args:
8
- query (str): the query for getiing information
9
- Returns:
10
- list[dict]: A list of dictionaries containing title, href and body
11
- """
12
  with DDGS() as ddgs:
13
- results = ddgs.text(query, max_results=5)
14
- # return "\n".join([f"{r['title']} - {r['href']} - {r['body']}" for r in results])
15
- return results
16
 
17
  with gr.Blocks() as app:
18
- gr.Markdown("# DuckDuckGo Search Tool"),
19
- gr.Markdown("## Please checkout below video to know about this MCP Server"),
20
  gr.HTML(
21
- """<iframe width="560" height="315"
22
- src="https://www.youtube.com/embed/0EE3sD1MHeg"
23
- frameborder="0" allowfullscreen></iframe>""",
24
- label="Featured Video"
25
- ),
26
- with gr.Row():
27
- query_input = gr.Textbox(label="Enter Search Query")
28
- search_btn = gr.Button("Search")
29
- output = gr.Textbox(label="Results", interactive=False)
30
 
 
 
 
31
  search_btn.click(fn=search_duckduckgo, inputs=query_input, outputs=output)
32
 
33
  app.launch(mcp_server=True)
 
1
  import gradio as gr
2
+ from ddgs import DDGS
3
+ import spaces
4
 
5
+ MAX_RESULTS = 5
6
+
7
+ @spaces.queue # ✅ CPU-safe, enables Streamable HTTP MCP
8
+ def search_duckduckgo(query: str) -> str:
 
 
 
 
9
  with DDGS() as ddgs:
10
+ results = ddgs.text(query, max_results=MAX_RESULTS)
11
+ return "\n".join([f"{r['title']} - {r['href']}" for r in results])
 
12
 
13
  with gr.Blocks() as app:
14
+ gr.Markdown("# DuckDuckGo Search Tool")
15
+ gr.Markdown("## Example Video")
16
  gr.HTML(
17
+ """<iframe width="560" height="315"
18
+ src="https://www.youtube.com/embed/0EE3sD1MHeg"
19
+ frameborder="0" allowfullscreen></iframe>"""
20
+ )
 
 
 
 
 
21
 
22
+ query_input = gr.Textbox(label="Enter Search Query")
23
+ search_btn = gr.Button("Search")
24
+ output = gr.Textbox(label="Results", interactive=False)
25
  search_btn.click(fn=search_duckduckgo, inputs=query_input, outputs=output)
26
 
27
  app.launch(mcp_server=True)