Update app.py
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import torch
|
|
5 |
# Use a pipeline as a high-level helper
|
6 |
from transformers import pipeline
|
7 |
|
8 |
-
|
9 |
"translation",
|
10 |
model="facebook/nllb-200-distilled-600M",
|
11 |
torch_dtype=torch.bfloat16)
|
@@ -22,11 +22,11 @@ def get_FLORES_code_from_language(language):
|
|
22 |
|
23 |
|
24 |
def translate_text(text, destination_language):
|
25 |
-
|
26 |
-
dest_code
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
return translation[0]["translation_text"]
|
31 |
|
32 |
gr.close_all()
|
|
|
5 |
# Use a pipeline as a high-level helper
|
6 |
from transformers import pipeline
|
7 |
|
8 |
+
text_translator = pipeline(
|
9 |
"translation",
|
10 |
model="facebook/nllb-200-distilled-600M",
|
11 |
torch_dtype=torch.bfloat16)
|
|
|
22 |
|
23 |
|
24 |
def translate_text(text, destination_language):
|
25 |
+
dest_code = get_FLORES_code_from_language(destination_language)
|
26 |
+
if dest_code is None:
|
27 |
+
return "Invalid destination language."
|
28 |
+
|
29 |
+
translation = text_translator(text, src_lang="eng_Latn", tgt_lang=dest_code)
|
30 |
return translation[0]["translation_text"]
|
31 |
|
32 |
gr.close_all()
|