Update app.py
Browse files
app.py
CHANGED
@@ -12,6 +12,22 @@ from huggingface_hub import hf_hub_download, InferenceClient
|
|
12 |
import requests
|
13 |
from bs4 import BeautifulSoup
|
14 |
import urllib
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def extract_text_from_webpage(html_content):
|
17 |
"""Extracts visible text from HTML content using BeautifulSoup."""
|
@@ -36,7 +52,7 @@ def search(term, num_results=3, lang="en", advanced=True, timeout=5, safe="activ
|
|
36 |
while start < num_results:
|
37 |
resp = session.get(
|
38 |
url="https://www.google.com/search",
|
39 |
-
headers={"User-Agent":
|
40 |
params={
|
41 |
"q": term,
|
42 |
"num": num_results - start,
|
@@ -126,13 +142,7 @@ def model(text, web_search):
|
|
126 |
return "".join([response.token.text for response in stream if response.token.text != "</s>"])
|
127 |
|
128 |
async def respond(audio, web_search):
|
129 |
-
|
130 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
131 |
-
tmp_path = tmp_file.name
|
132 |
-
audio_segment = AudioSegment(data=audio_data, sample_width=2, frame_rate=sr, channels=1) # Assuming 16-bit PCM audio
|
133 |
-
audio_segment.export(tmp_path, format="wav")
|
134 |
-
|
135 |
-
user = transcribe(tmp_path)
|
136 |
reply = model(user, web_search)
|
137 |
communicate = edge_tts.Communicate(reply)
|
138 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
|
|
12 |
import requests
|
13 |
from bs4 import BeautifulSoup
|
14 |
import urllib
|
15 |
+
import random
|
16 |
+
|
17 |
+
# List of user agents to choose from for requests
|
18 |
+
_useragent_list = [
|
19 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0',
|
20 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
|
21 |
+
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
|
22 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
|
23 |
+
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',
|
24 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36 Edg/111.0.1661.62',
|
25 |
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/111.0'
|
26 |
+
]
|
27 |
+
|
28 |
+
def get_useragent():
|
29 |
+
"""Returns a random user agent from the list."""
|
30 |
+
return random.choice(_useragent_list)
|
31 |
|
32 |
def extract_text_from_webpage(html_content):
|
33 |
"""Extracts visible text from HTML content using BeautifulSoup."""
|
|
|
52 |
while start < num_results:
|
53 |
resp = session.get(
|
54 |
url="https://www.google.com/search",
|
55 |
+
headers={"User-Agent":get_useragent()},
|
56 |
params={
|
57 |
"q": term,
|
58 |
"num": num_results - start,
|
|
|
142 |
return "".join([response.token.text for response in stream if response.token.text != "</s>"])
|
143 |
|
144 |
async def respond(audio, web_search):
|
145 |
+
user = transcribe(audio)
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
reply = model(user, web_search)
|
147 |
communicate = edge_tts.Communicate(reply)
|
148 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|