mrolando commited on
Commit
efea913
1 Parent(s): 44c548d

added translation

Browse files
Files changed (1) hide show
  1. app.py +20 -15
app.py CHANGED
@@ -24,14 +24,29 @@ import base64
24
  with open("Iso_Logotipo_Ceibal.png", "rb") as image_file:
25
  encoded_image = base64.b64encode(image_file.read()).decode()
26
 
27
- # CKPT = "facebook/nllb-200-distilled-600M"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
- # model = AutoModelForSeq2SeqLM.from_pretrained(CKPT)
30
- # tokenizer = AutoTokenizer.from_pretrained(CKPT)
31
  def generate_sound(text,steps,audio_length,negative_prompt):
32
  print(text)
33
- # text=translate_text(text)
34
- # negative_prompt = translate_text(negative_prompt)
35
  print(text)
36
  waveforms = pipe(text,
37
  num_inference_steps=steps,
@@ -40,17 +55,7 @@ def generate_sound(text,steps,audio_length,negative_prompt):
40
  rate =16000
41
  return rate, waveforms[0]
42
 
43
- # def translate_text(text):
44
- # translation_pipeline = pipeline("translation",
45
- # model=model,
46
- # tokenizer=tokenizer,
47
- # src_lang="spa_Latn",
48
- # tgt_lang="eng_Latn",
49
- # max_length=400,
50
- # device=device)
51
 
52
- # result = translation_pipeline(text)
53
- # return result[0]['translation_text']
54
  # def translate_text(text):
55
  # text = es_en_translator(text)[0].get("translation_text")
56
  # return text
 
24
  with open("Iso_Logotipo_Ceibal.png", "rb") as image_file:
25
  encoded_image = base64.b64encode(image_file.read()).decode()
26
 
27
+ CKPT = "facebook/nllb-200-distilled-600M"
28
+
29
+ model = AutoModelForSeq2SeqLM.from_pretrained(CKPT)
30
+ tokenizer = AutoTokenizer.from_pretrained(CKPT)
31
+
32
+ def translate_text(text):
33
+ translation_pipeline = pipeline("translation",
34
+ model=model,
35
+ tokenizer=tokenizer,
36
+ src_lang="spa_Latn",
37
+ tgt_lang="eng_Latn",
38
+ max_length=400,
39
+ device=device)
40
+
41
+ result = translation_pipeline(text)
42
+ return result[0]['translation_text']
43
+
44
+
45
 
 
 
46
  def generate_sound(text,steps,audio_length,negative_prompt):
47
  print(text)
48
+ text=translate_text(text)
49
+ negative_prompt = translate_text(negative_prompt)
50
  print(text)
51
  waveforms = pipe(text,
52
  num_inference_steps=steps,
 
55
  rate =16000
56
  return rate, waveforms[0]
57
 
 
 
 
 
 
 
 
 
58
 
 
 
59
  # def translate_text(text):
60
  # text = es_en_translator(text)[0].get("translation_text")
61
  # return text