Shrijeeth-Suresh
commited on
Commit
·
1ce59c5
1
Parent(s):
3e53b8b
feat: add Tavily search engine integration with improved UI components
Browse files- .gitignore +2 -1
- Makefile +1 -1
- app.py +4 -14
- requirements.txt +3 -2
- search_engines/duckduckgo.py +20 -1
- search_engines/tavily.py +51 -0
.gitignore
CHANGED
@@ -4,4 +4,5 @@ poetry.lock
|
|
4 |
.ruff_cache
|
5 |
*.egg-info
|
6 |
build
|
7 |
-
__pycache__
|
|
|
|
4 |
.ruff_cache
|
5 |
*.egg-info
|
6 |
build
|
7 |
+
__pycache__
|
8 |
+
.gradio
|
Makefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
install:
|
2 |
-
python -m pip install .
|
3 |
|
4 |
format:
|
5 |
python -m ruff format .
|
|
|
1 |
install:
|
2 |
+
python -m pip install -r requirements.txt
|
3 |
|
4 |
format:
|
5 |
python -m ruff format .
|
app.py
CHANGED
@@ -1,21 +1,11 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
from search_engines.duckduckgo import
|
4 |
-
|
5 |
-
duckduckgo_interface = gr.Interface(
|
6 |
-
fn=duckduckgo_search,
|
7 |
-
inputs=[
|
8 |
-
gr.Textbox(label="Search Query"),
|
9 |
-
gr.Slider(minimum=1, maximum=10, step=1, value=5, label="Number of Results"),
|
10 |
-
],
|
11 |
-
outputs=gr.Dataframe(label="Search Results", headers=["title", "body", "link"]),
|
12 |
-
title="DuckDuckGo Search",
|
13 |
-
description="Search the web using DuckDuckGo Search Engine.",
|
14 |
-
)
|
15 |
|
16 |
app = gr.TabbedInterface(
|
17 |
-
interface_list=[duckduckgo_interface],
|
18 |
-
tab_names=["DuckDuckGo Search"],
|
19 |
)
|
20 |
|
21 |
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
from search_engines.duckduckgo import duckduckgo_interface
|
4 |
+
from search_engines.tavily import tavily_interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
app = gr.TabbedInterface(
|
7 |
+
interface_list=[duckduckgo_interface, tavily_interface],
|
8 |
+
tab_names=["DuckDuckGo Search", "Tavily Search"],
|
9 |
)
|
10 |
|
11 |
|
requirements.txt
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
python-dotenv==1.1.0
|
2 |
-
gradio==5.33.0
|
3 |
pydantic==2.11.5
|
4 |
pydantic_settings==2.9.1
|
5 |
langchain-community==0.3.24
|
6 |
duckduckgo-search==8.0.2
|
7 |
pandas==2.2.3
|
8 |
-
ruff==0.11.12
|
|
|
|
1 |
python-dotenv==1.1.0
|
2 |
+
gradio[mcp]==5.33.0
|
3 |
pydantic==2.11.5
|
4 |
pydantic_settings==2.9.1
|
5 |
langchain-community==0.3.24
|
6 |
duckduckgo-search==8.0.2
|
7 |
pandas==2.2.3
|
8 |
+
ruff==0.11.12
|
9 |
+
langchain-tavily==0.2.1
|
search_engines/duckduckgo.py
CHANGED
@@ -1,6 +1,6 @@
|
|
|
|
1 |
import pandas as pd
|
2 |
from langchain_community.tools import DuckDuckGoSearchResults
|
3 |
-
from langchain_community.utilities.duckduckgo_search import DuckDuckGoSearchAPIWrapper
|
4 |
|
5 |
from utils.helpers import map_results
|
6 |
|
@@ -28,3 +28,22 @@ async def duckduckgo_search(query: str, max_results: int = 5) -> pd.DataFrame:
|
|
28 |
}
|
29 |
results = await map_results(results, mapping)
|
30 |
return results
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
import pandas as pd
|
3 |
from langchain_community.tools import DuckDuckGoSearchResults
|
|
|
4 |
|
5 |
from utils.helpers import map_results
|
6 |
|
|
|
28 |
}
|
29 |
results = await map_results(results, mapping)
|
30 |
return results
|
31 |
+
|
32 |
+
|
33 |
+
duckduckgo_interface = gr.Interface(
|
34 |
+
fn=duckduckgo_search,
|
35 |
+
inputs=[
|
36 |
+
gr.Textbox(label="Search Query"),
|
37 |
+
gr.Slider(minimum=1, maximum=10, step=1, value=5, label="Number of Results"),
|
38 |
+
],
|
39 |
+
outputs=gr.Dataframe(
|
40 |
+
label="Search Results",
|
41 |
+
headers=["title", "body", "link"],
|
42 |
+
show_fullscreen_button=True,
|
43 |
+
show_row_numbers=True,
|
44 |
+
show_copy_button=True,
|
45 |
+
wrap=True,
|
46 |
+
),
|
47 |
+
title="DuckDuckGo Search",
|
48 |
+
description="Search the web using DuckDuckGo Search Engine.",
|
49 |
+
)
|
search_engines/tavily.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
from langchain_tavily import TavilySearch
|
4 |
+
|
5 |
+
from utils.helpers import map_results
|
6 |
+
|
7 |
+
|
8 |
+
async def tavily_search(query: str, api_key: str, max_results: int = 5) -> pd.DataFrame:
|
9 |
+
"""
|
10 |
+
Given a search query, returns the search results from Tavily.
|
11 |
+
|
12 |
+
Args:
|
13 |
+
query (str): The search query.
|
14 |
+
api_key (str): The API key for Tavily Search.
|
15 |
+
max_results (int, optional): The number of maximum results to return. Defaults to 5.
|
16 |
+
|
17 |
+
Returns:
|
18 |
+
str: The search results from Tavily Search Engine.
|
19 |
+
"""
|
20 |
+
tavily = TavilySearch(
|
21 |
+
tavily_api_key=api_key,
|
22 |
+
)
|
23 |
+
tavily.max_results = max_results
|
24 |
+
results = await tavily.ainvoke(query)
|
25 |
+
mapping = {
|
26 |
+
"title": "title",
|
27 |
+
"url": "link",
|
28 |
+
"content": "body",
|
29 |
+
}
|
30 |
+
results = await map_results(results["results"], mapping)
|
31 |
+
return results
|
32 |
+
|
33 |
+
|
34 |
+
tavily_interface = gr.Interface(
|
35 |
+
fn=tavily_search,
|
36 |
+
inputs=[
|
37 |
+
gr.Textbox(label="Search Query"),
|
38 |
+
gr.Textbox(label="API Key", type="password"),
|
39 |
+
gr.Slider(minimum=1, maximum=10, step=1, value=5, label="Number of Results"),
|
40 |
+
],
|
41 |
+
outputs=gr.Dataframe(
|
42 |
+
label="Search Results",
|
43 |
+
headers=["title", "body", "link"],
|
44 |
+
show_fullscreen_button=True,
|
45 |
+
show_row_numbers=True,
|
46 |
+
show_copy_button=True,
|
47 |
+
wrap=True,
|
48 |
+
),
|
49 |
+
title="Tavily Search",
|
50 |
+
description="Search the web using Tavily Search Engine.",
|
51 |
+
)
|