Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,7 @@ langs = {iso[0]: iso[1] for iso in non_empty_isos} # {'Romanian': 'ro', 'German'
|
|
| 21 |
|
| 22 |
|
| 23 |
models = ["Helsinki-NLP", "Argos", "Google", "t5-base", "t5-small", "t5-large", "Unbabel/Tower-Plus-2B",
|
| 24 |
-
"Unbabel/TowerInstruct-Mistral-7B-v0.2", "winninghealth/WiNGPT-Babel-2", "HPLT"]
|
| 25 |
allmodels = ["Helsinki-NLP",
|
| 26 |
"Helsinki-NLP/opus-mt-tc-bible-big-mul-mul", "Helsinki-NLP/opus-mt-tc-bible-big-mul-deu_eng_nld",
|
| 27 |
"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",
|
|
@@ -57,6 +57,13 @@ class Translators:
|
|
| 57 |
pipe = pipeline("translation", model=hplt_model, device=self.device)
|
| 58 |
translation = pipe(self.input_text)
|
| 59 |
return translation[0]['translation_text']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
@classmethod
|
| 62 |
def download_argos_model(cls, from_code, to_code):
|
|
@@ -480,6 +487,9 @@ def translate_text(model_name: str, s_language: str, t_language: str, input_text
|
|
| 480 |
|
| 481 |
elif model_name == "Bergamot":
|
| 482 |
translated_text, message_text = Translators(model_name, s_language, t_language, input_text).bergamot()
|
|
|
|
|
|
|
|
|
|
| 483 |
|
| 484 |
except Exception as error:
|
| 485 |
translated_text = error
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
models = ["Helsinki-NLP", "Argos", "Google", "t5-base", "t5-small", "t5-large", "Unbabel/Tower-Plus-2B",
|
| 24 |
+
"Unbabel/TowerInstruct-Mistral-7B-v0.2", "winninghealth/WiNGPT-Babel-2", "QUICKMT", "HPLT"]
|
| 25 |
allmodels = ["Helsinki-NLP",
|
| 26 |
"Helsinki-NLP/opus-mt-tc-bible-big-mul-mul", "Helsinki-NLP/opus-mt-tc-bible-big-mul-deu_eng_nld",
|
| 27 |
"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",
|
|
|
|
| 57 |
pipe = pipeline("translation", model=hplt_model, device=self.device)
|
| 58 |
translation = pipe(self.input_text)
|
| 59 |
return translation[0]['translation_text']
|
| 60 |
+
|
| 61 |
+
def quickmt(self)
|
| 62 |
+
from quickmt import Translator
|
| 63 |
+
# Auto-detects GPU, set to "cpu" to force CPU inference
|
| 64 |
+
translation = Translator(f"./quickmt-{self.sl}-{self.tl}/", device="auto")
|
| 65 |
+
# Translate - set beam size to 1 for faster speed (but lower quality)
|
| 66 |
+
return translation({self.input_text}, beam_size=5)
|
| 67 |
|
| 68 |
@classmethod
|
| 69 |
def download_argos_model(cls, from_code, to_code):
|
|
|
|
| 487 |
|
| 488 |
elif model_name == "Bergamot":
|
| 489 |
translated_text, message_text = Translators(model_name, s_language, t_language, input_text).bergamot()
|
| 490 |
+
|
| 491 |
+
elif model_name == "QUICKMT":
|
| 492 |
+
translated_text, message_text = Translators(model_name, s_language, t_language, input_text).quickmt()
|
| 493 |
|
| 494 |
except Exception as error:
|
| 495 |
translated_text = error
|