Spaces:
Runtime error
Runtime error
Añadi copy del box de salida y removi los ejemplo
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ def traducir_texto(texto_en):
|
|
15 |
str: El texto traducido al español.
|
16 |
"""
|
17 |
try:
|
18 |
-
if not texto_en.strip():
|
19 |
return ""
|
20 |
resultado = modelo_traduccion(texto_en)
|
21 |
return resultado[0]['translation_text']
|
@@ -36,19 +36,38 @@ def borrar_entrada(texto_entrada):
|
|
36 |
|
37 |
with gr.Blocks() as interfaz_traductor:
|
38 |
"""
|
39 |
-
Define la interfaz gráfica de la aplicación de traducción de inglés a español con
|
40 |
"""
|
41 |
gr.Markdown("# Traductor Inglés a Español")
|
42 |
with gr.Row():
|
43 |
with gr.Column():
|
44 |
-
texto_entrada_en = gr.Textbox(label="Texto en inglés", placeholder="Pega aquí el texto en inglés")
|
45 |
boton_borrar = gr.Button("Borrar todo")
|
46 |
with gr.Column():
|
47 |
-
texto_salida_es = gr.Textbox(label="Traducción al español", placeholder="La traducción aparecerá aquí", interactive=False)
|
|
|
48 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
texto_entrada_en.change(traducir_texto, inputs=texto_entrada_en, outputs=texto_salida_es)
|
50 |
boton_borrar.click(borrar_entrada, inputs=texto_entrada_en, outputs=texto_entrada_en)
|
51 |
|
52 |
-
gr.Examples([["Hello World"], ["How are you doing today?"], ["Thank you very much"]], inputs=texto_entrada_en)
|
53 |
-
|
54 |
interfaz_traductor.launch()
|
|
|
15 |
str: El texto traducido al español.
|
16 |
"""
|
17 |
try:
|
18 |
+
if not texto_en.strip():
|
19 |
return ""
|
20 |
resultado = modelo_traduccion(texto_en)
|
21 |
return resultado[0]['translation_text']
|
|
|
36 |
|
37 |
with gr.Blocks() as interfaz_traductor:
|
38 |
"""
|
39 |
+
Define la interfaz gráfica de la aplicación de traducción de inglés a español con cuadros de texto más grandes y sin ejemplos.
|
40 |
"""
|
41 |
gr.Markdown("# Traductor Inglés a Español")
|
42 |
with gr.Row():
|
43 |
with gr.Column():
|
44 |
+
texto_entrada_en = gr.Textbox(label="Texto en inglés", placeholder="Pega aquí el texto en inglés", lines=10)
|
45 |
boton_borrar = gr.Button("Borrar todo")
|
46 |
with gr.Column():
|
47 |
+
texto_salida_es = gr.Textbox(label="Traducción al español", placeholder="La traducción aparecerá aquí", interactive=False, elem_id="traduccion_salida", lines=10)
|
48 |
+
boton_copiar = gr.Button("Copiar traducción")
|
49 |
|
50 |
+
def copiar_al_portapapeles(texto):
|
51 |
+
"""
|
52 |
+
Función que devuelve un script de JavaScript para copiar el texto al portapapeles.
|
53 |
+
"""
|
54 |
+
return f"""
|
55 |
+
function copiarTexto() {{
|
56 |
+
const textoACopiar = document.getElementById('traduccion_salida').value;
|
57 |
+
navigator.clipboard.writeText(textoACopiar)
|
58 |
+
.then(() => {{
|
59 |
+
alert('¡Traducción copiada al portapapeles!');
|
60 |
+
}})
|
61 |
+
.catch(err => {{
|
62 |
+
console.error('Error al copiar al portapapeles: ', err);
|
63 |
+
alert('No se pudo copiar la traducción al portapapeles.');
|
64 |
+
}});
|
65 |
+
}}
|
66 |
+
copiarTexto();
|
67 |
+
"""
|
68 |
+
|
69 |
+
boton_copiar.click(copiar_al_portapapeles, inputs=texto_salida_es, outputs=gr.Javascript())
|
70 |
texto_entrada_en.change(traducir_texto, inputs=texto_entrada_en, outputs=texto_salida_es)
|
71 |
boton_borrar.click(borrar_entrada, inputs=texto_entrada_en, outputs=texto_entrada_en)
|
72 |
|
|
|
|
|
73 |
interfaz_traductor.launch()
|