Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
titulo = "Traductor EN-ES / ES-EN"
|
5 |
+
def modelo(text, model):
|
6 |
+
if model == "Ingles a Español":
|
7 |
+
model = "Helsinki-NLP/opus-mt-en-es"
|
8 |
+
else:
|
9 |
+
model = "Helsinki-NLP/opus-mt-es-en"
|
10 |
+
|
11 |
+
pipe = pipeline("translation", model=model)
|
12 |
+
response = pipe(text)
|
13 |
+
return response[0]['translation_text']
|
14 |
+
|
15 |
+
descripcion = """<div style="display: flex; justify-content: space-between; align-items: center;">
|
16 |
+
<div style="width: 100%; padding-right: 10px;">
|
17 |
+
El objetivo de esta pagina es traducir un texto tanto de Ingles a Español como de Español a Ingles
|
18 |
+
</div>
|
19 |
+
</div>
|
20 |
+
"""
|
21 |
+
|
22 |
+
|
23 |
+
# Creamos el interface pasandole la funcion los inputs y los outputs ademas del titulo, el tema y el article
|
24 |
+
demo = gr.Interface(
|
25 |
+
fn=modelo,
|
26 |
+
inputs=[gr.Text(), gr.Dropdown(["Español a Ingles", "Ingles a Español"], label="Selecciona a que idioma quieres traducir")],
|
27 |
+
outputs='text',
|
28 |
+
title=titulo,
|
29 |
+
theme="gstaff/xkcd",
|
30 |
+
description=descripcion
|
31 |
+
)
|
32 |
+
|
33 |
+
# Con autentificacion
|
34 |
+
|
35 |
+
demo.launch(auth=("iabd", "iabd"))
|
36 |
+
|
37 |
+
# Sin autentificacion
|
38 |
+
|
39 |
+
#demo.launch()
|