Spaces:
Runtime error
Runtime error
Commit
·
bfcc104
1
Parent(s):
19a7b01
realtime translate
Browse files
app.py
CHANGED
@@ -11,7 +11,6 @@ import torch
|
|
11 |
import kenlm
|
12 |
import torchaudio
|
13 |
from pyctcdecode import Alphabet, BeamSearchDecoderCTC, LanguageModel
|
14 |
-
device = torch.device(0 if torch.cuda.is_available() else "cpu")
|
15 |
|
16 |
"""Vietnamese speech2text"""
|
17 |
cache_dir = './cache/'
|
@@ -125,16 +124,8 @@ def speech2text_en(input_file):
|
|
125 |
"""Machine translation"""
|
126 |
vien_model_checkpoint = "datnth1709/finetuned_HelsinkiNLP-opus-mt-vi-en_PhoMT"
|
127 |
envi_model_checkpoint = "datnth1709/finetuned_HelsinkiNLP-opus-mt-en-vi_PhoMT"
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
vien_tokenizer = AutoTokenizer.from_pretrained(vien_model_checkpoint, return_tensors="pt")
|
132 |
-
vien_model = ORTModelForSeq2SeqLM.from_pretrained(vien_model_checkpoint)
|
133 |
-
vien_translator = TranslationPipeline(model=vien_model, tokenizer=vien_tokenizer,clean_up_tokenization_spaces=True, device=device)
|
134 |
-
|
135 |
-
envi_tokenizer = AutoTokenizer.from_pretrained(envi_model_checkpoint, return_tensors="pt")
|
136 |
-
envi_model = ORTModelForSeq2SeqLM.from_pretrained(envi_model_checkpoint)
|
137 |
-
envi_translator = TranslationPipeline(model=envi_model, tokenizer=envi_tokenizer,clean_up_tokenization_spaces=True, device=device)
|
138 |
|
139 |
|
140 |
def translate_vi2en(Vietnamese):
|
|
|
11 |
import kenlm
|
12 |
import torchaudio
|
13 |
from pyctcdecode import Alphabet, BeamSearchDecoderCTC, LanguageModel
|
|
|
14 |
|
15 |
"""Vietnamese speech2text"""
|
16 |
cache_dir = './cache/'
|
|
|
124 |
"""Machine translation"""
|
125 |
vien_model_checkpoint = "datnth1709/finetuned_HelsinkiNLP-opus-mt-vi-en_PhoMT"
|
126 |
envi_model_checkpoint = "datnth1709/finetuned_HelsinkiNLP-opus-mt-en-vi_PhoMT"
|
127 |
+
vien_translator = pipeline("translation", model=vien_model_checkpoint)
|
128 |
+
envi_translator = pipeline("translation", model=envi_model_checkpoint)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
|
131 |
def translate_vi2en(Vietnamese):
|