Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -31,19 +31,16 @@ def translation(source, target, text):
|
|
| 31 |
output = ""
|
| 32 |
|
| 33 |
start_time = time.time()
|
|
|
|
| 34 |
|
| 35 |
-
if source = "vie_Latn" or target ="eng_Latn":
|
| 36 |
-
chunks = text.splitlines(True)
|
| 37 |
for chunk in chunks:
|
| 38 |
stchunk = vinai_translator.translate_vi2en(chunk)
|
| 39 |
output += stchunk+"\n"
|
| 40 |
-
|
| 41 |
-
elif source = "eng_Latn" or target ="vie_Latn":
|
| 42 |
-
chunks = text.splitlines(True)
|
| 43 |
for chunk in chunks:
|
| 44 |
stchunk = vinai_translator.translate_en2vi(chunk)
|
| 45 |
output += stchunk+"\n"
|
| 46 |
-
pass
|
| 47 |
else:
|
| 48 |
if len(model_dict) == 2:
|
| 49 |
#model_name = 'nllb-distilled-600M'
|
|
@@ -53,11 +50,10 @@ def translation(source, target, text):
|
|
| 53 |
tokenizer = model_dict[model_name + '_tokenizer']
|
| 54 |
|
| 55 |
translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=source, tgt_lang=target)
|
| 56 |
-
chunks = text.splitlines(True)
|
| 57 |
for chunk in chunks:
|
| 58 |
stchunk = translator(chunk+"<mask>", max_length=400, num_beams=5)
|
| 59 |
output += stchunk[0]['translation_text']+"\n"
|
| 60 |
-
|
| 61 |
end_time = time.time()
|
| 62 |
|
| 63 |
result = {'inference_time': end_time - start_time,
|
|
|
|
| 31 |
output = ""
|
| 32 |
|
| 33 |
start_time = time.time()
|
| 34 |
+
chunks = text.splitlines(True)
|
| 35 |
|
| 36 |
+
if source == "vie_Latn" or target == "eng_Latn":
|
|
|
|
| 37 |
for chunk in chunks:
|
| 38 |
stchunk = vinai_translator.translate_vi2en(chunk)
|
| 39 |
output += stchunk+"\n"
|
| 40 |
+
elif source == "eng_Latn" or target == "vie_Latn":
|
|
|
|
|
|
|
| 41 |
for chunk in chunks:
|
| 42 |
stchunk = vinai_translator.translate_en2vi(chunk)
|
| 43 |
output += stchunk+"\n"
|
|
|
|
| 44 |
else:
|
| 45 |
if len(model_dict) == 2:
|
| 46 |
#model_name = 'nllb-distilled-600M'
|
|
|
|
| 50 |
tokenizer = model_dict[model_name + '_tokenizer']
|
| 51 |
|
| 52 |
translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=source, tgt_lang=target)
|
|
|
|
| 53 |
for chunk in chunks:
|
| 54 |
stchunk = translator(chunk+"<mask>", max_length=400, num_beams=5)
|
| 55 |
output += stchunk[0]['translation_text']+"\n"
|
| 56 |
+
|
| 57 |
end_time = time.time()
|
| 58 |
|
| 59 |
result = {'inference_time': end_time - start_time,
|