monarkshadow commited on
Commit
f4ddde3
·
verified ·
1 Parent(s): 6d94f63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
app.py CHANGED
@@ -1,35 +1,37 @@
1
  import streamlit as st
2
  import time
3
  from transformers import pipeline
 
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.success("Texto taducido: {textotraducido}")
30
  else:
31
  st.warning("Ingrese un texto")
32
-
33
  if st.button("Limpiar"):
34
- textoingresado=""
35
  st.empty()
 
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
 
22
+ traductor = pipeline(task="translation", model=translation_models[idiomaseleccionado])
23
 
24
+ textoingresado = st.text_area("Ingrese el texto a traducir:", "")
25
 
26
  if st.button("Traducir"):
27
  with st.spinner("Traduciendo..."):
28
  time.sleep(2)
29
+ if textoingresado:
30
+ textotraducido = traductor(textoingresado, max_length=500)[0]["translation_text"]
31
+ st.success(f"Texto traducido: {textotraducido}")
32
  else:
33
  st.warning("Ingrese un texto")
34
+
35
  if st.button("Limpiar"):
36
+ textoingresado = ""
37
  st.empty()