monarkshadow commited on
Commit
b8d872f
·
verified ·
1 Parent(s): a9497e6

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 pepeline
4
+ st.title("Traductor Multilenguaje")
5
+ translation_models = {
6
+ "English to German": "Helsinki-NLP/opus-mt-en-de",
7
+ "German to English": "Helsinki-NLP/opus-mt-de-en",
8
+ "English to French": "Helsinki-NLP/opus-mt-en-fr",
9
+ "French to English": "Helsinki-NLP/opus-mt-fr-en",
10
+ "English to Urdu": "Helsinki-NLP/opus-mt-en-ur",
11
+ "Urdu to English": "Helsinki-NLP/opus-mt-ur-en",
12
+ "English to Spanish": "Helsinki-NLP/opus-mt-en-es",
13
+ "Spanish to English": "Helsinki-NLP/opus-mt-es-en",
14
+ "English to Chinese": "Helsinki-NLP/opus-mt-en-zh",
15
+ "Chinese to English": "Helsinki-NLP/opus-mt-zh-en",
16
+ }
17
+
18
+ idiomaseleccionado = st.selectbox("Idiomas: ", list(translation_models.keys()))
19
+
20
+ traductor = pipeline(task="traslation", model = translation_models[idiomaseleccionado])
21
+
22
+ textoingresado = st.text_area("Ingrese el texto a traducir:","")
23
+
24
+ if st.button("Traducir"):
25
+ with st.spinner("Traduciendo..."):
26
+ time.sleep(2)
27
+ if user_input:
28
+ textotraducido = traductor(user_input, max_legth=500)[0]["texto traducido"]
29
+ st.succes("Texto taducido: {textotraducido}")
30
+ else:
31
+ st.warning("Ingrese un texto")
32
+
33
+ if st.button("Limpiar"):
34
+ textoingresado=""
35
+ st.empty()