AlexD108 commited on
Commit
9d1d7c5
·
verified ·
1 Parent(s): c87622f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import time
3
+ from transformers import pipeline
4
+
5
+ st.titl("Traductormultilenguaje")
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
+ idiomaseleccionado = st.selectbox("Idiomas: ",list(translation_models.keys()))
20
+ traductor = pipeline(task="translation", model = translation_models[idiomaseleccionado])
21
+
22
+ textoingresado = st.text_area("Ingrese el texto a trauducir", "")
23
+
24
+ if st.button("Traducir"):
25
+ with st.spinner("Traduciendo..."):
26
+ time.sleep(2)
27
+ if textoingresado:
28
+ textotraducido = traductor(textoingresado, max_length=500)[0]["textotraducido"]
29
+ st.succes("Texto Traducido: {textotraducido}")
30
+ else:
31
+ st.warning("Ingrese un texto, no seas vivo")
32
+
33
+ if st.button("Limpiar"):
34
+ textoingresado=""
35
+ st.empty()