julio07cesar10's picture
Update app.py
f412462 verified
raw
history blame
1.31 kB
import streamlit as st
import Time
from transformers import pipeline
st.title("Traductor Multilenguaje")
translation_models = {
"English to German": "Helsinki-NLP/opus-mt-en-de",
"German to English": "Helsinki-NLP/opus-mt-de-en",
"English to French": "Helsinki-NLP/opus-mt-en-fr",
"French to English": "Helsinki-NLP/opus-mt-fr-en",
"English to Urdu": "Helsinki-NLP/opus-mt-en-ur",
"Urdu to English": "Helsinki-NLP/opus-mt-ur-en",
"English to Spanish": "Helsinki-NLP/opus-mt-en-es",
"Spanish to English": "Helsinki-NLP/opus-mt-es-en",
"English to Chinese": "Helsinki-NLP/opus-mt-en-zh",
"Chinese to English": "Helsinki-NLP/opus-mt-zh-en",
}
idiomaseleccionado = st.selectbox("Idiomas:", list(translation_models.keys()))
traductor= pipeline(task="translation", model= translation_models[idiomaseleccionado])
textoingresado = st.text_Area("Ingrese el texto a traducir:", "")
if st.button("Traducir"):
with st.spinner("Traduciendo..."):
time.sleep(2)
if user_input:
textotraducido = traductor(textoingresado, max_lenght=500)[0]["textotraducido"]
st.succes("Texto Traducido: "{textotraducido})
else:
st.warning("Ingrese un Texto")
if st.button("Limpiar"):
textoingresado= ""
st.empty()