Edmon02 commited on
Commit
87a8fd3
1 Parent(s): 39fef6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -31
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
- for sent in nlp(text).sents:
33
- try:
34
- # Add a timeout of 5 seconds (adjust as needed)
35
- response = requests.get(
36
- "https://translate.googleapis.com/translate_a/single",
37
- params={
38
- 'client': 'gtx',
39
- 'sl': 'auto',
40
- 'tl': 'hy',
41
- 'dt': 't',
42
- 'q': sent.text,
43
- },
44
- timeout=50,
45
- )
46
- response.raise_for_status() # Raise an HTTPError for bad responses
47
-
48
- # Extract the translated text from the response
49
- translation = response.json()[0][0][0]
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