File size: 1,296 Bytes
9d1d7c5
 
 
 
4d28036
9d1d7c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4717a24
9d1d7c5
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import streamlit as st
import time
from transformers import pipeline

st.title("Traductormultilenguaje")

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 trauducir", "")

if st.button("Traducir"):
    with st.spinner("Traduciendo..."):
        time.sleep(2)
        if textoingresado:
            textotraducido = traductor(textoingresado, max_length=500)[0]['textotraducido']
            st.succes("Texto Traducido:  {textotraducido}")
        else:
            st.warning("Ingrese un texto, no seas vivo")

if st.button("Limpiar"):
    textoingresado=""
    st.empty()