Spaces:
Paused
Paused
Update voice_chat.py
Browse files- voice_chat.py +18 -12
voice_chat.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
|
|
@@ -136,14 +152,4 @@ async def respond(audio, web_search):
|
|
| 136 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
| 137 |
tmp_path = tmp_file.name
|
| 138 |
await communicate.save(tmp_path)
|
| 139 |
-
return tmp_path
|
| 140 |
-
|
| 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="Voice Chat (BETA)", sources="microphone", type="filepath", waveform_options=False)
|
| 145 |
-
output = gr.Audio(label="JARVIS", type="filepath", interactive=False, autoplay=True, elem_classes="audio")
|
| 146 |
-
gr.Interface(fn=respond, inputs=[input, web_search], outputs=[output], live=True)
|
| 147 |
-
|
| 148 |
-
if __name__ == "__main__":
|
| 149 |
-
demo.queue(max_size=200).launch()
|
|
|
|
| 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
|
|
|
|
| 152 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
|
| 153 |
tmp_path = tmp_file.name
|
| 154 |
await communicate.save(tmp_path)
|
| 155 |
+
return tmp_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|