Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,35 +1,37 @@
|
|
1 |
import streamlit as st
|
2 |
import time
|
3 |
from transformers import pipeline
|
|
|
4 |
st.title("Traductor Multilenguaje")
|
|
|
5 |
translation_models = {
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
}
|
17 |
|
18 |
idiomaseleccionado = st.selectbox("Idiomas: ", list(translation_models.keys()))
|
19 |
|
20 |
-
traductor = pipeline(task="
|
21 |
|
22 |
-
textoingresado = st.text_area("Ingrese el texto a traducir:","")
|
23 |
|
24 |
if st.button("Traducir"):
|
25 |
with st.spinner("Traduciendo..."):
|
26 |
time.sleep(2)
|
27 |
-
if
|
28 |
-
textotraducido = traductor(
|
29 |
-
st.success("Texto
|
30 |
else:
|
31 |
st.warning("Ingrese un texto")
|
32 |
-
|
33 |
if st.button("Limpiar"):
|
34 |
-
textoingresado=""
|
35 |
st.empty()
|
|
|
1 |
import streamlit as st
|
2 |
import time
|
3 |
from transformers import pipeline
|
4 |
+
|
5 |
st.title("Traductor Multilenguaje")
|
6 |
+
|
7 |
translation_models = {
|
8 |
+
"English to German": "Helsinki-NLP/opus-mt-en-de",
|
9 |
+
"German to English": "Helsinki-NLP/opus-mt-de-en",
|
10 |
+
"English to French": "Helsinki-NLP/opus-mt-en-fr",
|
11 |
+
"French to English": "Helsinki-NLP/opus-mt-fr-en",
|
12 |
+
"English to Urdu": "Helsinki-NLP/opus-mt-en-ur",
|
13 |
+
"Urdu to English": "Helsinki-NLP/opus-mt-ur-en",
|
14 |
+
"English to Spanish": "Helsinki-NLP/opus-mt-en-es",
|
15 |
+
"Spanish to English": "Helsinki-NLP/opus-mt-es-en",
|
16 |
+
"English to Chinese": "Helsinki-NLP/opus-mt-en-zh",
|
17 |
+
"Chinese to English": "Helsinki-NLP/opus-mt-zh-en",
|
18 |
}
|
19 |
|
20 |
idiomaseleccionado = st.selectbox("Idiomas: ", list(translation_models.keys()))
|
21 |
|
22 |
+
traductor = pipeline(task="translation", model=translation_models[idiomaseleccionado])
|
23 |
|
24 |
+
textoingresado = st.text_area("Ingrese el texto a traducir:", "")
|
25 |
|
26 |
if st.button("Traducir"):
|
27 |
with st.spinner("Traduciendo..."):
|
28 |
time.sleep(2)
|
29 |
+
if textoingresado:
|
30 |
+
textotraducido = traductor(textoingresado, max_length=500)[0]["translation_text"]
|
31 |
+
st.success(f"Texto traducido: {textotraducido}")
|
32 |
else:
|
33 |
st.warning("Ingrese un texto")
|
34 |
+
|
35 |
if st.button("Limpiar"):
|
36 |
+
textoingresado = ""
|
37 |
st.empty()
|