Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,7 +9,6 @@ import inflect
|
|
9 |
import re
|
10 |
|
11 |
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
12 |
-
import spacy
|
13 |
import requests
|
14 |
from requests.exceptions import Timeout
|
15 |
|
@@ -23,39 +22,27 @@ speaker_embeddings = {
|
|
23 |
"BDL": "cmu_us_bdl_arctic-wav-arctic_a0009.npy",
|
24 |
}
|
25 |
|
26 |
-
nlp = spacy.load("en_core_web_sm")
|
27 |
-
|
28 |
-
|
29 |
def translate_text(text):
|
30 |
trans_text = ''
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
trans_text += translation
|
52 |
-
|
53 |
-
except Timeout:
|
54 |
-
print("Translation request timed out.")
|
55 |
-
# Handle the timeout as needed
|
56 |
-
except requests.exceptions.RequestException as e:
|
57 |
-
print(f"An error occurred: {e}")
|
58 |
-
# Handle other request exceptions as needed
|
59 |
|
60 |
return trans_text
|
61 |
|
|
|
9 |
import re
|
10 |
|
11 |
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech, SpeechT5HifiGan
|
|
|
12 |
import requests
|
13 |
from requests.exceptions import Timeout
|
14 |
|
|
|
22 |
"BDL": "cmu_us_bdl_arctic-wav-arctic_a0009.npy",
|
23 |
}
|
24 |
|
|
|
|
|
|
|
25 |
def translate_text(text):
|
26 |
trans_text = ''
|
27 |
|
28 |
+
# Add a timeout of 5 seconds (adjust as needed)
|
29 |
+
response = requests.get(
|
30 |
+
"https://translate.googleapis.com/translate_a/single",
|
31 |
+
params={
|
32 |
+
'client': 'gtx',
|
33 |
+
'sl': 'auto',
|
34 |
+
'tl': 'hy',
|
35 |
+
'dt': 't',
|
36 |
+
'q': text,
|
37 |
+
},
|
38 |
+
timeout=50,
|
39 |
+
)
|
40 |
+
response.raise_for_status() # Raise an HTTPError for bad responses
|
41 |
+
|
42 |
+
# Extract the translated text from the response
|
43 |
+
translation = response.json()[0][0][0]
|
44 |
+
|
45 |
+
trans_text += translation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
return trans_text
|
48 |
|