Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -97,20 +97,21 @@ def HelsinkiNLPAutoTokenizer(sl, tl, input_text):
|
|
| 97 |
return f"Error finding model: {model_name}! Try other available language combination.", error
|
| 98 |
|
| 99 |
def HelsinkiNLP(sl, tl, input_text):
|
| 100 |
-
try:
|
| 101 |
model_name = f"Helsinki-NLP/opus-mt-{sl}-{tl}"
|
| 102 |
pipe = pipeline("translation", model=model_name, device=-1)
|
| 103 |
# translation = pipe(input_text)
|
| 104 |
# return translation[0]['translation_text'], f'Translated from {sl} to {tl} with {model_name}.'
|
| 105 |
except EnvironmentError:
|
| 106 |
-
try:
|
| 107 |
model_name = f"Helsinki-NLP/opus-tatoeba-{sl}-{tl}"
|
| 108 |
pipe = pipeline("translation", model=model_name, device=-1)
|
| 109 |
translation = pipe(input_text)
|
| 110 |
return translation[0]['translation_text'], f'Translated from {sl} to {tl} with {model_name}.'
|
| 111 |
except EnvironmentError as error:
|
| 112 |
-
try:
|
| 113 |
-
|
|
|
|
| 114 |
translation = pipe(input_text)
|
| 115 |
return translation[0]['translation_text'], f'Translated from {sl} to {tl} with {model_name}.'
|
| 116 |
except Exception as error:
|
|
|
|
| 97 |
return f"Error finding model: {model_name}! Try other available language combination.", error
|
| 98 |
|
| 99 |
def HelsinkiNLP(sl, tl, input_text):
|
| 100 |
+
try: # Standard bilingual model
|
| 101 |
model_name = f"Helsinki-NLP/opus-mt-{sl}-{tl}"
|
| 102 |
pipe = pipeline("translation", model=model_name, device=-1)
|
| 103 |
# translation = pipe(input_text)
|
| 104 |
# return translation[0]['translation_text'], f'Translated from {sl} to {tl} with {model_name}.'
|
| 105 |
except EnvironmentError:
|
| 106 |
+
try: # Tatoeba models
|
| 107 |
model_name = f"Helsinki-NLP/opus-tatoeba-{sl}-{tl}"
|
| 108 |
pipe = pipeline("translation", model=model_name, device=-1)
|
| 109 |
translation = pipe(input_text)
|
| 110 |
return translation[0]['translation_text'], f'Translated from {sl} to {tl} with {model_name}.'
|
| 111 |
except EnvironmentError as error:
|
| 112 |
+
try: # Last resort: multi to multi
|
| 113 |
+
model_name = "Helsinki-NLP/opus-mt-tc-bible-big-mul-mul"
|
| 114 |
+
pipe = pipeline("translation", model=model_name)
|
| 115 |
translation = pipe(input_text)
|
| 116 |
return translation[0]['translation_text'], f'Translated from {sl} to {tl} with {model_name}.'
|
| 117 |
except Exception as error:
|