Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -65,19 +65,19 @@ def HelsinkiNLPAutoTokenizer(sl, tl, input_text):
|
|
| 65 |
def HelsinkiNLP(sl, tl, input_text):
|
| 66 |
try:
|
| 67 |
model_name = f"Helsinki-NLP/opus-mt-{sl}-{tl}"
|
| 68 |
-
pipe = pipeline("translation", model=model_name)
|
| 69 |
# translation = pipe(input_text)
|
| 70 |
# return translation[0]['translation_text'], f'Translated from {sl} to {tl} with {model_name}.'
|
| 71 |
except EnvironmentError:
|
| 72 |
try:
|
| 73 |
model_name = f"Helsinki-NLP/opus-tatoeba-{sl}-{tl}"
|
| 74 |
-
pipe = pipeline("translation", model=model_name)
|
| 75 |
translation = pipe(input_text)
|
| 76 |
return translation[0]['translation_text'], f'Translated from {sl} to {tl} with {model_name}.'
|
| 77 |
except EnvironmentError as error:
|
| 78 |
return f"Error finding model: {model_name}! Try other available language combination.", error
|
| 79 |
except KeyError as error:
|
| 80 |
-
return f"Error: Translation direction {
|
| 81 |
|
| 82 |
def flan(model_name, sl, tl, input_text):
|
| 83 |
tokenizer = T5Tokenizer.from_pretrained(model_name, legacy=False)
|
|
@@ -214,7 +214,8 @@ def translate_text(input_text: str, sselected_language: str, tselected_language:
|
|
| 214 |
print(message_text)
|
| 215 |
|
| 216 |
if model_name.startswith("Helsinki-NLP"):
|
| 217 |
-
|
|
|
|
| 218 |
|
| 219 |
elif model_name == "utter-project/EuroLLM-1.7B-Instruct":
|
| 220 |
translated_text = eurollm_instruct(model_name, sselected_language, tselected_language, input_text)
|
|
|
|
| 65 |
def HelsinkiNLP(sl, tl, input_text):
|
| 66 |
try:
|
| 67 |
model_name = f"Helsinki-NLP/opus-mt-{sl}-{tl}"
|
| 68 |
+
pipe = pipeline("translation", model=model_name, device=-1)
|
| 69 |
# translation = pipe(input_text)
|
| 70 |
# return translation[0]['translation_text'], f'Translated from {sl} to {tl} with {model_name}.'
|
| 71 |
except EnvironmentError:
|
| 72 |
try:
|
| 73 |
model_name = f"Helsinki-NLP/opus-tatoeba-{sl}-{tl}"
|
| 74 |
+
pipe = pipeline("translation", model=model_name, device=-1)
|
| 75 |
translation = pipe(input_text)
|
| 76 |
return translation[0]['translation_text'], f'Translated from {sl} to {tl} with {model_name}.'
|
| 77 |
except EnvironmentError as error:
|
| 78 |
return f"Error finding model: {model_name}! Try other available language combination.", error
|
| 79 |
except KeyError as error:
|
| 80 |
+
return f"Error: Translation direction {sl} to {tl} is not supported by Helsinki Translation Models", error
|
| 81 |
|
| 82 |
def flan(model_name, sl, tl, input_text):
|
| 83 |
tokenizer = T5Tokenizer.from_pretrained(model_name, legacy=False)
|
|
|
|
| 214 |
print(message_text)
|
| 215 |
|
| 216 |
if model_name.startswith("Helsinki-NLP"):
|
| 217 |
+
translated_text, message_text = HelsinkiNLP(sl, tl, input_text)
|
| 218 |
+
return translated_text, message_text
|
| 219 |
|
| 220 |
elif model_name == "utter-project/EuroLLM-1.7B-Instruct":
|
| 221 |
translated_text = eurollm_instruct(model_name, sselected_language, tselected_language, input_text)
|