rajaramesh commited on
Commit
5cbeb2d
·
1 Parent(s): c4efdb2

Add app.py and requirements.txt file

Browse files
Files changed (2) hide show
  1. app.py +26 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ with gr.Row():
20
+ query_input = gr.Textbox(label="Enter Search Query")
21
+ search_btn = gr.Button("Search")
22
+ output = gr.Textbox(label="Results", interactive=False)
23
+
24
+ search_btn.click(fn=search_duckduckgo, inputs=query_input, outputs=output)
25
+
26
+ app.launch(mcp_server=True)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio[mcp]
2
+ langchain-community
3
+ unstructured
4
+ duckduckgo_search