Shrijeeth-Suresh
commited on
Commit
·
34bff5b
1
Parent(s):
1ce59c5
feat: add SearxNG search engine integration with web interface
Browse files- app.py +3 -2
- search_engines/searxng.py +57 -0
app.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 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 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
from search_engines.duckduckgo import duckduckgo_interface
|
| 4 |
+
from search_engines.searxng import searxng_interface
|
| 5 |
from search_engines.tavily import tavily_interface
|
| 6 |
|
| 7 |
app = gr.TabbedInterface(
|
| 8 |
+
interface_list=[duckduckgo_interface, tavily_interface, searxng_interface],
|
| 9 |
+
tab_names=["DuckDuckGo Search", "Tavily Search", "SearxNG Search"],
|
| 10 |
)
|
| 11 |
|
| 12 |
|
search_engines/searxng.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from langchain_community.utilities import SearxSearchWrapper
|
| 4 |
+
|
| 5 |
+
from utils.helpers import map_results
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
async def searxng_search(
|
| 9 |
+
query: str, searxng_host: str, max_results: int = 5
|
| 10 |
+
) -> pd.DataFrame:
|
| 11 |
+
"""
|
| 12 |
+
Given a search query, returns the search results from SearxNG.
|
| 13 |
+
|
| 14 |
+
Args:
|
| 15 |
+
query (str): The search query.
|
| 16 |
+
searxng_host (str): The SearxNG host URL.
|
| 17 |
+
searxng_headers (dict): The SearxNG headers for additional metadata and authentication.
|
| 18 |
+
max_results (int, optional): The number of maximum results to return. Defaults to 5.
|
| 19 |
+
|
| 20 |
+
Returns:
|
| 21 |
+
str: The search results from SearxNG Search Engine.
|
| 22 |
+
"""
|
| 23 |
+
searxng = SearxSearchWrapper(
|
| 24 |
+
searx_host=searxng_host,
|
| 25 |
+
k=max_results,
|
| 26 |
+
)
|
| 27 |
+
results = await searxng.aresults(
|
| 28 |
+
query,
|
| 29 |
+
num_results=max_results,
|
| 30 |
+
)
|
| 31 |
+
mapping = {
|
| 32 |
+
"title": "title",
|
| 33 |
+
"link": "link",
|
| 34 |
+
"snippet": "body",
|
| 35 |
+
}
|
| 36 |
+
results = await map_results(results, mapping)
|
| 37 |
+
return results
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
searxng_interface = gr.Interface(
|
| 41 |
+
fn=searxng_search,
|
| 42 |
+
inputs=[
|
| 43 |
+
gr.Textbox(label="Search Query"),
|
| 44 |
+
gr.Textbox(label="SearxNG Host URL"),
|
| 45 |
+
gr.Slider(minimum=1, maximum=10, step=1, value=5, label="Number of Results"),
|
| 46 |
+
],
|
| 47 |
+
outputs=gr.Dataframe(
|
| 48 |
+
label="Search Results",
|
| 49 |
+
headers=["title", "body", "link"],
|
| 50 |
+
show_fullscreen_button=True,
|
| 51 |
+
show_row_numbers=True,
|
| 52 |
+
show_copy_button=True,
|
| 53 |
+
wrap=True,
|
| 54 |
+
),
|
| 55 |
+
title="SearxNG Search",
|
| 56 |
+
description="Search the web using SearxNG Search Engine.",
|
| 57 |
+
)
|