Spaces:
Running
Running
detect error fixed
Browse files
app.py
CHANGED
@@ -1,6 +1,3 @@
|
|
1 |
-
"""
|
2 |
-
@author: idoia lerchundi
|
3 |
-
"""
|
4 |
import streamlit as st
|
5 |
from language_directions import *
|
6 |
from transformers import pipeline
|
@@ -69,19 +66,24 @@ def input_changed(source_language_dropdown, input_text=""):
|
|
69 |
|
70 |
def translate(input_text, source, target):
|
71 |
source_readable = source
|
|
|
|
|
72 |
if source == "Detect" or source.startswith("Detected"):
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
77 |
try:
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
return translation[0]['translation_text']
|
83 |
except KeyError:
|
84 |
-
|
85 |
|
86 |
with st.container():
|
87 |
st.header("Basque (EU) Euskera Multilingual Translator (Basque as the Starting Point)")
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from language_directions import *
|
3 |
from transformers import pipeline
|
|
|
66 |
|
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 |
+
source, _ = auto_detect_language_code(input_text)
|
73 |
+
|
74 |
+
# Map from human-readable name to code if needed
|
75 |
+
if source in source_lang_dict:
|
76 |
+
source = source_lang_dict[source]
|
77 |
+
if target in target_lang_dict:
|
78 |
+
target = target_lang_dict[target]
|
79 |
+
|
80 |
try:
|
81 |
+
model_id = f"Helsinki-NLP/opus-mt-{source}-{target}"
|
82 |
+
pipe = pipeline("translation", model=model_id, device=-1) # CPU
|
83 |
+
translation = pipe(input_text)
|
84 |
+
return translation[0]['translation_text']
|
|
|
85 |
except KeyError:
|
86 |
+
return f"Error: Translation from {source_readable} to {target} is not supported"
|
87 |
|
88 |
with st.container():
|
89 |
st.header("Basque (EU) Euskera Multilingual Translator (Basque as the Starting Point)")
|