julio07cesar10
commited on
Commit
•
56e9063
1
Parent(s):
adb0513
Create app.py
Browse files
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_lenght=500)[0]["textotraducido"]
|
30 |
+
st.succes("Texto Traducido: "{textotraducido})
|
31 |
+
else:
|
32 |
+
st.warning("Ingrese un Texto")
|
33 |
+
|
34 |
+
if st.button("Limpiar"):
|
35 |
+
textoingresado= ""
|
36 |
+
st.empty()
|