Spaces:
Sleeping
Sleeping
Javitron4257
commited on
This is the version 1.0 of app.py which is able to change languages
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
import gradio as gr
|
3 |
+
modelo_en_es="Helsinki-NLP/opus-mt-en-es"
|
4 |
+
option="Choose a language"
|
5 |
+
opcion="Escoge una opcion"
|
6 |
+
text1="Text to translate"
|
7 |
+
text2="Translation"
|
8 |
+
modelo_es_en="Helsinki-NLP/opus-mt-es-en"
|
9 |
+
texto1="Texto a traducir"
|
10 |
+
texto2="Texto traducido"
|
11 |
+
enviar="Enviar"
|
12 |
+
|
13 |
+
def traductor(prompt,modelo):
|
14 |
+
pipe = pipeline("translation", model= modelo_en_es if modelo=="En-Es" else modelo_es_en)
|
15 |
+
frase_traducida=pipe(prompt)
|
16 |
+
return frase_traducida[0]['translation_text']
|
17 |
+
|
18 |
+
# def actualizar(modelo):
|
19 |
+
# if modelo== "En-es":
|
20 |
+
# return text1, text2
|
21 |
+
# else:
|
22 |
+
# return texto1, texto2
|
23 |
+
|
24 |
+
def actualizar(modelo):
|
25 |
+
if modelo == "En-Es":
|
26 |
+
return gr.update(label=text1), gr.update(label=text2), gr.update(label=option)
|
27 |
+
else:
|
28 |
+
return gr.update(label=texto1), gr.update(label=texto2), gr.update(label=opcion)
|
29 |
+
|
30 |
+
|
31 |
+
with gr.Blocks() as demo:
|
32 |
+
with gr.Row():
|
33 |
+
modelo=gr.Dropdown(["En-Es","Es-En"],label="Choose a language", value="En-Es")
|
34 |
+
with gr.Row():
|
35 |
+
with gr.Column():
|
36 |
+
# txtbox1= gr.Textbox(label= text1 if modelo == "En-Es" else texto1)
|
37 |
+
txtbox1= gr.Textbox(label=text1)
|
38 |
+
|
39 |
+
with gr.Column():
|
40 |
+
# txtbox2= gr.Textbox(label= text2 if modelo == "En-Es" else texto2)
|
41 |
+
txtbox2= gr.Textbox(label= text2)
|
42 |
+
|
43 |
+
submit=gr.Button("Submit")
|
44 |
+
modelo.change(actualizar,inputs=modelo, outputs=[txtbox1, txtbox2,modelo])
|
45 |
+
submit.click(traductor,inputs=[txtbox1,modelo],outputs=txtbox2)
|
46 |
+
|
47 |
+
demo.launch()
|