Spaces:
Sleeping
Sleeping
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."""
|
@@ -33,7 +49,7 @@ def search(term, num_results=1, lang="en", advanced=True, sleep_interval=0, time
|
|
33 |
while start < num_results:
|
34 |
resp = requests.get(
|
35 |
url="https://www.google.com/search",
|
36 |
-
headers={"User-Agent":
|
37 |
params={
|
38 |
"q": term,
|
39 |
"num": num_results - start, # Number of results to fetch in this batch
|
@@ -141,8 +157,8 @@ async def respond(audio, web_search):
|
|
141 |
with gr.Blocks() as demo:
|
142 |
with gr.Row():
|
143 |
web_search = gr.Checkbox(label="Web Search", value=False)
|
144 |
-
input = gr.Audio(label="
|
145 |
-
output = gr.Audio(label="
|
146 |
gr.Interface(fn=respond, inputs=[input, web_search], outputs=[output], live=True)
|
147 |
|
148 |
if __name__ == "__main__":
|
|
|
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."""
|
|
|
49 |
while start < num_results:
|
50 |
resp = requests.get(
|
51 |
url="https://www.google.com/search",
|
52 |
+
headers={"User-Agent": get_useragent()}, # Set random user agent
|
53 |
params={
|
54 |
"q": term,
|
55 |
"num": num_results - start, # Number of results to fetch in this batch
|
|
|
157 |
with gr.Blocks() as demo:
|
158 |
with gr.Row():
|
159 |
web_search = gr.Checkbox(label="Web Search", value=False)
|
160 |
+
input = gr.Audio(label="User Input", sources="microphone", type="filepath")
|
161 |
+
output = gr.Audio(label="AI", autoplay=True)
|
162 |
gr.Interface(fn=respond, inputs=[input, web_search], outputs=[output], live=True)
|
163 |
|
164 |
if __name__ == "__main__":
|