Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,6 +26,7 @@ models = ["Helsinki-NLP", "Helsinki-NLP/opus-mt-tc-bible-big-mul-mul",
|
|
| 26 |
"bigscience/bloomz-560m", "bigscience/bloomz-1b1", "bigscience/bloomz-1b7", "bigscience/bloomz-3b",
|
| 27 |
"t5-small", "t5-base", "t5-large",
|
| 28 |
"google/flan-t5-small", "google/flan-t5-base", "google/flan-t5-large", "google/flan-t5-xl",
|
|
|
|
| 29 |
"Argos", "Google",
|
| 30 |
"HuggingFaceTB/SmolLM3-3B", "winninghealth/WiNGPT-Babel-2",
|
| 31 |
"utter-project/EuroLLM-1.7B", "utter-project/EuroLLM-1.7B-Instruct",
|
|
@@ -125,7 +126,20 @@ class Translators:
|
|
| 125 |
return self.HelsinkiNLP_mulmul()
|
| 126 |
except KeyError as error:
|
| 127 |
return f"Error: Translation direction {self.sl} to {self.tl} is not supported by Helsinki Translation Models", error
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
def smollm(self):
|
| 130 |
tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
| 131 |
model = AutoModelForCausalLM.from_pretrained(self.model_name)
|
|
@@ -402,6 +416,9 @@ def translate_text(input_text: str, s_language: str, t_language: str, model_name
|
|
| 402 |
|
| 403 |
elif 'flan' in model_name.lower():
|
| 404 |
translated_text = Translators(model_name, s_language, t_language, input_text).flan()
|
|
|
|
|
|
|
|
|
|
| 405 |
|
| 406 |
elif 'mt0' in model_name.lower():
|
| 407 |
translated_text = Translators(model_name, s_language, t_language, input_text).bigscience()
|
|
|
|
| 26 |
"bigscience/bloomz-560m", "bigscience/bloomz-1b1", "bigscience/bloomz-1b7", "bigscience/bloomz-3b",
|
| 27 |
"t5-small", "t5-base", "t5-large",
|
| 28 |
"google/flan-t5-small", "google/flan-t5-base", "google/flan-t5-large", "google/flan-t5-xl",
|
| 29 |
+
"google/madlad400-3b-mt", "jbochi/madlad400-3b-mt",
|
| 30 |
"Argos", "Google",
|
| 31 |
"HuggingFaceTB/SmolLM3-3B", "winninghealth/WiNGPT-Babel-2",
|
| 32 |
"utter-project/EuroLLM-1.7B", "utter-project/EuroLLM-1.7B-Instruct",
|
|
|
|
| 126 |
return self.HelsinkiNLP_mulmul()
|
| 127 |
except KeyError as error:
|
| 128 |
return f"Error: Translation direction {self.sl} to {self.tl} is not supported by Helsinki Translation Models", error
|
| 129 |
+
|
| 130 |
+
def madlad(self):
|
| 131 |
+
model = T5ForConditionalGeneration.from_pretrained(self.model_name, device_map="auto")
|
| 132 |
+
tokenizer = T5Tokenizer.from_pretrained(self.model_name)
|
| 133 |
+
text = f"<2{self.tl}> {self.input_text}"
|
| 134 |
+
# input_ids = tokenizer(text, return_tensors="pt").input_ids.to(model.device)
|
| 135 |
+
# outputs = model.generate(input_ids=input_ids)
|
| 136 |
+
# return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 137 |
+
# Use a pipeline as a high-level helper
|
| 138 |
+
translator = pipeline('translation', model=model, tokenizer=tokenizer, src_lang=self.sl, tgt_lang=self.tl)
|
| 139 |
+
translated_text = translator(text, max_length=512)
|
| 140 |
+
return translated_text[0]['translation_text']
|
| 141 |
+
# pipe = pipeline("translation", model=)
|
| 142 |
+
|
| 143 |
def smollm(self):
|
| 144 |
tokenizer = AutoTokenizer.from_pretrained(self.model_name)
|
| 145 |
model = AutoModelForCausalLM.from_pretrained(self.model_name)
|
|
|
|
| 416 |
|
| 417 |
elif 'flan' in model_name.lower():
|
| 418 |
translated_text = Translators(model_name, s_language, t_language, input_text).flan()
|
| 419 |
+
|
| 420 |
+
elif 'madlad' in model_name.lower():
|
| 421 |
+
translated_text = Translators(model_name, s_language, t_language, input_text).madlad()
|
| 422 |
|
| 423 |
elif 'mt0' in model_name.lower():
|
| 424 |
translated_text = Translators(model_name, s_language, t_language, input_text).bigscience()
|