yuvscherbatov commited on
Commit
8e253e0
1 Parent(s): 665125d

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -11,7 +11,7 @@ import gradio as gr
11
  import numpy as np
12
  import torch
13
 
14
- from transformers import pipeline, VitsModel, VitsTokenizer
15
 
16
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
17
 
@@ -19,7 +19,11 @@ device = "cuda:0" if torch.cuda.is_available() else "cpu"
19
  asr_pipe = pipeline("automatic-speech-recognition", model="asapp/sew-d-tiny-100k-ft-ls100h", device=device)
20
 
21
  #eng text to rus text translation
22
- translation_pipe = pipeline("translation", model="facebook/wmt19-en-ru")
 
 
 
 
23
 
24
  #rus text to rus speech transformation
25
  vits_model = VitsModel.from_pretrained("facebook/mms-tts-rus")
@@ -30,8 +34,12 @@ def transform_audio_to_speech_en(audio):
30
  return outputs["text"]
31
 
32
  def translator(text):
33
- translated_text = translation_pipe(text)
34
- return translated_text[0]['translation_text']
 
 
 
 
35
 
36
  def synthesise(translated_text):
37
  translated_text = translator(translated_text)
 
11
  import numpy as np
12
  import torch
13
 
14
+ from transformers import pipeline, VitsModel, VitsTokenizer, FSMTForConditionalGeneration, FSMTTokenizer
15
 
16
  device = "cuda:0" if torch.cuda.is_available() else "cpu"
17
 
 
19
  asr_pipe = pipeline("automatic-speech-recognition", model="asapp/sew-d-tiny-100k-ft-ls100h", device=device)
20
 
21
  #eng text to rus text translation
22
+ mname = "facebook/wmt19-en-ru"
23
+ tokenizer = FSMTTokenizer.from_pretrained(mname)
24
+ model = FSMTForConditionalGeneration.from_pretrained(mname)
25
+
26
+ #translation_pipe = pipeline("translation", model="facebook/wmt19-en-ru")
27
 
28
  #rus text to rus speech transformation
29
  vits_model = VitsModel.from_pretrained("facebook/mms-tts-rus")
 
34
  return outputs["text"]
35
 
36
  def translator(text):
37
+ input_ids = tokenizer.encode(text, return_tensors="pt")
38
+ outputs = model.generate(input_ids)
39
+ decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
40
+ return decoded
41
+ #translated_text = translation_pipe(text)
42
+ #return translated_text[0]['translation_text']
43
 
44
  def synthesise(translated_text):
45
  translated_text = translator(translated_text)