Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -67,24 +67,20 @@ def input_changed(source_language_dropdown, input_text=""):
|
|
| 67 |
def translate(input_text, source, target):
|
| 68 |
source_readable = source
|
| 69 |
|
| 70 |
-
# Detect source if needed
|
| 71 |
if source == "Detect" or source.startswith("Detected"):
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
source = source_lang_dict[source]
|
| 77 |
-
if target in target_lang_dict:
|
| 78 |
-
target = target_lang_dict[target]
|
| 79 |
|
| 80 |
try:
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
except KeyError:
|
| 87 |
-
|
| 88 |
|
| 89 |
with st.container():
|
| 90 |
st.header("Basque (EU) Euskera Multilingual Translator (Basque as the Starting Point)")
|
|
|
|
| 67 |
def translate(input_text, source, target):
|
| 68 |
source_readable = source
|
| 69 |
|
|
|
|
| 70 |
if source == "Detect" or source.startswith("Detected"):
|
| 71 |
+
source, _ = auto_detect_language_code(input_text)
|
| 72 |
+
if source in source_lang_dict.keys():
|
| 73 |
+
source = source_lang_dict[source]
|
| 74 |
+
target_lang_dict, _ = get_target_languages(source)
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
try:
|
| 77 |
+
target = target_lang_dict[target]
|
| 78 |
+
model = f"Helsinki-NLP/opus-mt-{source}-{target}"
|
| 79 |
+
pipe = pipeline("translation", model=model)
|
| 80 |
+
translation = pipe(input_text)
|
| 81 |
+
return translation[0]['translation_text']
|
| 82 |
except KeyError:
|
| 83 |
+
return f"Error: Translation from {source_readable} to {target} is not supported by Translation Models"
|
| 84 |
|
| 85 |
with st.container():
|
| 86 |
st.header("Basque (EU) Euskera Multilingual Translator (Basque as the Starting Point)")
|