Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,7 @@ from tempfile import NamedTemporaryFile
|
|
10 |
from typing import List
|
11 |
from bs4 import BeautifulSoup
|
12 |
import logging
|
|
|
13 |
|
14 |
from langchain_community.llms import HuggingFaceHub
|
15 |
from langchain_community.vectorstores import FAISS
|
@@ -122,7 +123,7 @@ def google_search(term, num_results=5, lang="en", timeout=5, safe="active", ssl_
|
|
122 |
break
|
123 |
|
124 |
soup = BeautifulSoup(resp.text, "html.parser")
|
125 |
-
|
126 |
if not result_block:
|
127 |
break
|
128 |
|
@@ -149,10 +150,19 @@ def google_search(term, num_results=5, lang="en", timeout=5, safe="active", ssl_
|
|
149 |
|
150 |
return all_results
|
151 |
|
152 |
-
def duckduckgo_search(query):
|
153 |
-
|
154 |
-
|
155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
156 |
|
157 |
def respond(
|
158 |
message,
|
|
|
10 |
from typing import List
|
11 |
from bs4 import BeautifulSoup
|
12 |
import logging
|
13 |
+
from duckduckgo_search import ddg
|
14 |
|
15 |
from langchain_community.llms import HuggingFaceHub
|
16 |
from langchain_community.vectorstores import FAISS
|
|
|
123 |
break
|
124 |
|
125 |
soup = BeautifulSoup(resp.text, "html.parser")
|
126 |
+
result_block = soup.find_all("div", attrs={"class": "g"})
|
127 |
if not result_block:
|
128 |
break
|
129 |
|
|
|
150 |
|
151 |
return all_results
|
152 |
|
153 |
+
def duckduckgo_search(query, max_results=5):
|
154 |
+
try:
|
155 |
+
results = ddg(query, region='wt-wt', safesearch='Moderate', time=None, max_results=max_results)
|
156 |
+
formatted_results = []
|
157 |
+
for result in results:
|
158 |
+
formatted_results.append({
|
159 |
+
"link": result.get('href', ''),
|
160 |
+
"text": result.get('title', '') + '. ' + result.get('body', '')
|
161 |
+
})
|
162 |
+
return formatted_results
|
163 |
+
except Exception as e:
|
164 |
+
print(f"Error in DuckDuckGo search: {e}")
|
165 |
+
return [{"link": None, "text": "No information found in the web search results."}]
|
166 |
|
167 |
def respond(
|
168 |
message,
|