Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import time
|
| 3 |
+
from transformers import pepeline
|
| 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 |
+
traductor = pipeline(task="translation", model= translation_models[idiomaseleccionado])
|
| 22 |
+
|
| 23 |
+
textoingresado = st.text_area("Ingrese el texto a traducir:","")
|
| 24 |
+
|
| 25 |
+
if st.button("Traducir"):
|
| 26 |
+
with st.spinner("Traduciendo..."):
|
| 27 |
+
time.sleep(2)
|
| 28 |
+
if user_input:
|
| 29 |
+
textotraducido= traductor(user_input, max_length=500)[0]["textotraducido"]
|
| 30 |
+
st.succes("Texto Traducido:" {textotraducido})
|
| 31 |
+
else:
|
| 32 |
+
st.warning("Ingrese un texto")
|
| 33 |
+
|
| 34 |
+
if st.button("Limpiar"):
|
| 35 |
+
textoingresado=""
|
| 36 |
+
st.empty()
|
| 37 |
+
|