Dwight18 commited on
Commit
647f241
1 Parent(s): 3bfb5c3

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ 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.success("Texto traducido: " {textotraducido})
31
+ else:
32
+ st.warning("Ingrese un texto")
33
+
34
+ if st.button("Limpiar"):
35
+ textoingresado=""
36
+ st.empty()