Update app.py
Browse files
app.py
CHANGED
|
@@ -21,6 +21,7 @@ langs.extend(list(all_langs.keys()))
|
|
| 21 |
models = ["Helsinki-NLP",
|
| 22 |
"Helsinki-NLP/opus-mt-tc-bible-big-mul-mul", "Helsinki-NLP/opus-mt-tc-bible-big-mul-deu_eng_nld",
|
| 23 |
"Helsinki-NLP/opus-mt-tc-bible-big-mul-deu_eng_fra_por_spa", "Helsinki-NLP/opus-mt-tc-bible-big-deu_eng_fra_por_spa-mul",
|
|
|
|
| 24 |
"facebook/nllb-200-distilled-600M", "facebook/nllb-200-distilled-1.3B", "facebook/nllb-200-1.3B", "facebook/nllb-200-3.3B",
|
| 25 |
"facebook/mbart-large-50-many-to-many-mmt", "facebook/mbart-large-50-one-to-many-mmt", "facebook/mbart-large-50-many-to-one-mmt",
|
| 26 |
"facebook/m2m100_418M", "facebook/m2m100_1.2B",
|
|
@@ -102,7 +103,7 @@ class Translators:
|
|
| 102 |
translated_text = error
|
| 103 |
return translated_text
|
| 104 |
|
| 105 |
-
def
|
| 106 |
try:
|
| 107 |
pipe = pipeline("translation", model=self.model_name, device=self.device)
|
| 108 |
iso_dict = {iso[1]: iso[3] for iso in non_empty_isos}
|
|
@@ -141,7 +142,6 @@ class Translators:
|
|
| 141 |
translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=self.sl, tgt_lang=self.tl)
|
| 142 |
translated_text = translator(text, max_length=512)
|
| 143 |
return translated_text[0]['translation_text']
|
| 144 |
-
# pipe = pipeline("translation", model=)
|
| 145 |
|
| 146 |
def smollm(self):
|
| 147 |
tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
|
@@ -400,8 +400,8 @@ def translate_text(input_text: str, s_language: str, t_language: str, model_name
|
|
| 400 |
message_text = f'Translated from {s_language} to {t_language} with {model_name}'
|
| 401 |
translated_text = None
|
| 402 |
try:
|
| 403 |
-
if "-mul" in model_name.lower() or "mul-" in model_name.lower():
|
| 404 |
-
translated_text, message_text = Translators(model_name, sl, tl, input_text).
|
| 405 |
|
| 406 |
elif model_name == "Helsinki-NLP":
|
| 407 |
translated_text, message_text = Translators(model_name, sl, tl, input_text).HelsinkiNLP()
|
|
@@ -501,7 +501,8 @@ def create_interface():
|
|
| 501 |
swap_btn.click(fn=swap_languages, inputs=[s_language, t_language], outputs=[s_language, t_language], api_name=False, show_api=False)
|
| 502 |
# with gr.Row(equal_height=True):
|
| 503 |
model_name = gr.Dropdown(choices=models, label=f"Select a model. Default is {DEFAULTS[2]}.", value=DEFAULTS[2], interactive=True, scale=2)
|
| 504 |
-
|
|
|
|
| 505 |
|
| 506 |
translated_text = gr.Textbox(label="Translated text:", placeholder="Display field for translation", interactive=False, show_copy_button=True)
|
| 507 |
message_text = gr.Textbox(label="Messages:", placeholder="Display field for status and error messages", interactive=False,
|
|
|
|
| 21 |
models = ["Helsinki-NLP",
|
| 22 |
"Helsinki-NLP/opus-mt-tc-bible-big-mul-mul", "Helsinki-NLP/opus-mt-tc-bible-big-mul-deu_eng_nld",
|
| 23 |
"Helsinki-NLP/opus-mt-tc-bible-big-mul-deu_eng_fra_por_spa", "Helsinki-NLP/opus-mt-tc-bible-big-deu_eng_fra_por_spa-mul",
|
| 24 |
+
"Helsinki-NLP/opus-mt-tc-bible-big-roa-deu_eng_fra_por_spa", "Helsinki-NLP/opus-mt-tc-bible-big-deu_eng_fra_por_spa-roa",
|
| 25 |
"facebook/nllb-200-distilled-600M", "facebook/nllb-200-distilled-1.3B", "facebook/nllb-200-1.3B", "facebook/nllb-200-3.3B",
|
| 26 |
"facebook/mbart-large-50-many-to-many-mmt", "facebook/mbart-large-50-one-to-many-mmt", "facebook/mbart-large-50-many-to-one-mmt",
|
| 27 |
"facebook/m2m100_418M", "facebook/m2m100_1.2B",
|
|
|
|
| 103 |
translated_text = error
|
| 104 |
return translated_text
|
| 105 |
|
| 106 |
+
def HelsinkiNLP_mulroa(self):
|
| 107 |
try:
|
| 108 |
pipe = pipeline("translation", model=self.model_name, device=self.device)
|
| 109 |
iso_dict = {iso[1]: iso[3] for iso in non_empty_isos}
|
|
|
|
| 142 |
translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=self.sl, tgt_lang=self.tl)
|
| 143 |
translated_text = translator(text, max_length=512)
|
| 144 |
return translated_text[0]['translation_text']
|
|
|
|
| 145 |
|
| 146 |
def smollm(self):
|
| 147 |
tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
|
|
|
| 400 |
message_text = f'Translated from {s_language} to {t_language} with {model_name}'
|
| 401 |
translated_text = None
|
| 402 |
try:
|
| 403 |
+
if "-mul" in model_name.lower() or "mul-" in model_name.lower() or "-roa" in model_name.lower():
|
| 404 |
+
translated_text, message_text = Translators(model_name, sl, tl, input_text).HelsinkiNLP_mulroa()
|
| 405 |
|
| 406 |
elif model_name == "Helsinki-NLP":
|
| 407 |
translated_text, message_text = Translators(model_name, sl, tl, input_text).HelsinkiNLP()
|
|
|
|
| 501 |
swap_btn.click(fn=swap_languages, inputs=[s_language, t_language], outputs=[s_language, t_language], api_name=False, show_api=False)
|
| 502 |
# with gr.Row(equal_height=True):
|
| 503 |
model_name = gr.Dropdown(choices=models, label=f"Select a model. Default is {DEFAULTS[2]}.", value=DEFAULTS[2], interactive=True, scale=2)
|
| 504 |
+
translate_btn = gr.Button(fn=translate_text, inputs=[input_text, s_language, t_language, model_name],
|
| 505 |
+
outputs=[translated_text, message_text]value="Translate", scale=1)
|
| 506 |
|
| 507 |
translated_text = gr.Textbox(label="Translated text:", placeholder="Display field for translation", interactive=False, show_copy_button=True)
|
| 508 |
message_text = gr.Textbox(label="Messages:", placeholder="Display field for status and error messages", interactive=False,
|