Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ from transformers import T5Tokenizer, T5ForConditionalGeneration, AutoTokenizer,
|
|
4 |
|
5 |
langs = {"English": "en", "Romanian": "ro", "German": "de", "French": "fr", "Spanish": "es", "Italian": "it"}
|
6 |
options = list(langs.keys())
|
7 |
-
models = ["Helsinki-NLP", "t5-base", "t5-small", "t5-large", "
|
8 |
|
9 |
@spaces.GPU
|
10 |
def translate_text(input_text, sselected_language, tselected_language, model_name):
|
@@ -22,7 +22,10 @@ def translate_text(input_text, sselected_language, tselected_language, model_nam
|
|
22 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_full)
|
23 |
except EnvironmentError as error:
|
24 |
return f"Error finding required model! Try other available language combination. Error: {error}"
|
25 |
-
|
|
|
|
|
|
|
26 |
else:
|
27 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
28 |
model = T5ForConditionalGeneration.from_pretrained(model_name, device_map="auto")
|
|
|
4 |
|
5 |
langs = {"English": "en", "Romanian": "ro", "German": "de", "French": "fr", "Spanish": "es", "Italian": "it"}
|
6 |
options = list(langs.keys())
|
7 |
+
models = ["Helsinki-NLP", "t5-base", "t5-small", "t5-large", "nllb-200-distilled-1.3B"]
|
8 |
|
9 |
@spaces.GPU
|
10 |
def translate_text(input_text, sselected_language, tselected_language, model_name):
|
|
|
22 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_full)
|
23 |
except EnvironmentError as error:
|
24 |
return f"Error finding required model! Try other available language combination. Error: {error}"
|
25 |
+
elif model_name.startswith('nllb'):
|
26 |
+
model_name_full = "facebook/nllb-200-distilled-1.3B"
|
27 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_full)
|
28 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name_full)
|
29 |
else:
|
30 |
tokenizer = T5Tokenizer.from_pretrained(model_name)
|
31 |
model = T5ForConditionalGeneration.from_pretrained(model_name, device_map="auto")
|