samuelleecong commited on
Commit
26f8e67
1 Parent(s): 43f3b59

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -17,8 +17,7 @@ device = "cuda:0" if torch.cuda.is_available() else "cpu"
17
  asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device, generate_kwargs = {"task": "translate"})
18
 
19
 
20
- model = M2M100ForConditionalGeneration.from_pretrained("facebook/m2m100_418M")
21
- tokenizer = M2M100Tokenizer.from_pretrained("facebook/m2m100_418M")
22
 
23
  # load text-to-speech checkpoint and speaker embeddings
24
  # processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
@@ -34,11 +33,12 @@ speaker_embeddings = torch.tensor(embeddings_dataset[7306]["xvector"]).unsqueeze
34
 
35
  def translate(audio):
36
  outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
37
- encoded_text = tokenizer(outputs["text"], return_tensors="pt")
38
- generated_tokens = model.generate(**encoded_text)
39
- output_translated = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
 
40
  # return outputs["text"]
41
- return output_translated
42
 
43
  def synthesise(text):
44
  inputs = processor(text=text, return_tensors="pt")
 
17
  asr_pipe = pipeline("automatic-speech-recognition", model="openai/whisper-base", device=device, generate_kwargs = {"task": "translate"})
18
 
19
 
20
+ m2m100_en_sw = pipeline('translation', 'facebook/m2m100_418M', src_lang='en', tgt_lang="sw")
 
21
 
22
  # load text-to-speech checkpoint and speaker embeddings
23
  # processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
 
33
 
34
  def translate(audio):
35
  outputs = asr_pipe(audio, max_new_tokens=256, generate_kwargs={"task": "translate"})
36
+ output_translated = m2m100_en_sw(outputs["text"])
37
+ # encoded_text = tokenizer(outputs["text"], return_tensors="pt")
38
+ # generated_tokens = model.generate(**encoded_text)
39
+ # output_translated = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
40
  # return outputs["text"]
41
+ return output_translated["translation_text"]
42
 
43
  def synthesise(text):
44
  inputs = processor(text=text, return_tensors="pt")