LarissaE commited on
Commit
cbdcec3
1 Parent(s): 37c51e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -57,10 +57,24 @@ def create_segments(audio_fpath, seconds_max):
57
  return segment_paths, segment_start_times
58
 
59
  def get_translation(text):
60
- translator = Translator(service_urls=['translate.googleapis.com'])
61
- translated_text = translator.translate(text, dest='en').text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
- return translated_text
64
 
65
  #translation_pipeline = pipeline("translation", model=model, tokenizer=tokenizer, src_lang=src_lang, tgt_lang=tgt_lang, max_length=400, device=device)
66
  #result = translation_pipeline(text)
 
57
  return segment_paths, segment_start_times
58
 
59
  def get_translation(text):
60
+ import six
61
+ from google.cloud import translate_v2 as translate
62
+
63
+ translate_client = translate.Client()
64
+
65
+ if isinstance(text, six.binary_type):
66
+ text = text.decode("utf-8")
67
+
68
+ # Text can also be a sequence of strings, in which case this method
69
+ # will return a sequence of results for each text.
70
+ result = translate_client.translate(text, target_language='en')
71
+ return result["translatedText"]
72
+
73
+
74
+ #translator = Translator(service_urls=['translate.googleapis.com'])
75
+ #translated_text = translator.translate(text, dest='en').text
76
 
77
+ #return translated_text
78
 
79
  #translation_pipeline = pipeline("translation", model=model, tokenizer=tokenizer, src_lang=src_lang, tgt_lang=tgt_lang, max_length=400, device=device)
80
  #result = translation_pipeline(text)