Update app.py
Browse files
app.py
CHANGED
@@ -358,47 +358,6 @@ def generar_datos_sinteticos_evento(df):
|
|
358 |
df = generar_datos_sinteticos(df, desviacion_std)
|
359 |
return df
|
360 |
|
361 |
-
# Eventos de botones y actualización
|
362 |
-
def copiar_informe(informe):
|
363 |
-
# No retorna nada, para evitar el warning
|
364 |
-
pass
|
365 |
-
|
366 |
-
def exportar_word(df, informe_md):
|
367 |
-
df_valid = df.copy()
|
368 |
-
col_predicha = [col for col in df_valid.columns if 'Predicha' in col][0]
|
369 |
-
col_real = [col for col in df_valid.columns if 'Real' in col][0]
|
370 |
-
|
371 |
-
# Convertir columnas a numérico
|
372 |
-
df_valid[col_predicha] = pd.to_numeric(df_valid[col_predicha], errors='coerce')
|
373 |
-
df_valid[col_real] = pd.to_numeric(df_valid[col_real], errors='coerce')
|
374 |
-
|
375 |
-
df_valid = df_valid.dropna(subset=[col_predicha, col_real])
|
376 |
-
|
377 |
-
if df_valid.empty:
|
378 |
-
return None
|
379 |
-
|
380 |
-
filename = exportar_informe_word(df_valid, informe_md)
|
381 |
-
|
382 |
-
return filename # Retornamos el nombre del archivo
|
383 |
-
|
384 |
-
def exportar_latex(df, informe_md):
|
385 |
-
df_valid = df.copy()
|
386 |
-
col_predicha = [col for col in df_valid.columns if 'Predicha' in col][0]
|
387 |
-
col_real = [col for col in df_valid.columns if 'Real' in col][0]
|
388 |
-
|
389 |
-
# Convertir columnas a numérico
|
390 |
-
df_valid[col_predicha] = pd.to_numeric(df_valid[col_predicha], errors='coerce')
|
391 |
-
df_valid[col_real] = pd.to_numeric(df_valid[col_real], errors='coerce')
|
392 |
-
|
393 |
-
df_valid = df_valid.dropna(subset=[col_predicha, col_real])
|
394 |
-
|
395 |
-
if df_valid.empty:
|
396 |
-
return None
|
397 |
-
|
398 |
-
filename = exportar_informe_latex(df_valid, informe_md)
|
399 |
-
|
400 |
-
return filename # Retornamos el nombre del archivo
|
401 |
-
|
402 |
# Interfaz Gradio
|
403 |
with gr.Blocks(theme=gr.themes.Soft()) as interfaz:
|
404 |
gr.Markdown("""
|
@@ -448,7 +407,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as interfaz:
|
|
448 |
with gr.Tab("📊 Análisis y Reporte"):
|
449 |
estado_output = gr.Textbox(label="Estado", interactive=False)
|
450 |
graficos_output = gr.Plot(label="Gráficos de Análisis")
|
451 |
-
informe_output = gr.Markdown()
|
452 |
|
453 |
with gr.Row():
|
454 |
copiar_btn = gr.Button("📋 Copiar Informe", variant="secondary")
|
@@ -514,11 +473,23 @@ with gr.Blocks(theme=gr.themes.Soft()) as interfaz:
|
|
514 |
outputs=tabla_output
|
515 |
)
|
516 |
|
517 |
-
# Evento de copiar informe
|
518 |
copiar_btn.click(
|
519 |
-
|
520 |
-
|
521 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
522 |
)
|
523 |
|
524 |
# Eventos de exportar informes
|
|
|
358 |
df = generar_datos_sinteticos(df, desviacion_std)
|
359 |
return df
|
360 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
# Interfaz Gradio
|
362 |
with gr.Blocks(theme=gr.themes.Soft()) as interfaz:
|
363 |
gr.Markdown("""
|
|
|
407 |
with gr.Tab("📊 Análisis y Reporte"):
|
408 |
estado_output = gr.Textbox(label="Estado", interactive=False)
|
409 |
graficos_output = gr.Plot(label="Gráficos de Análisis")
|
410 |
+
informe_output = gr.Markdown(elem_id="informe_output") # Añadimos elem_id para poder referenciarlo en JS
|
411 |
|
412 |
with gr.Row():
|
413 |
copiar_btn = gr.Button("📋 Copiar Informe", variant="secondary")
|
|
|
473 |
outputs=tabla_output
|
474 |
)
|
475 |
|
476 |
+
# Evento de copiar informe utilizando JavaScript
|
477 |
copiar_btn.click(
|
478 |
+
None,
|
479 |
+
None,
|
480 |
+
None,
|
481 |
+
_js="""
|
482 |
+
function() {
|
483 |
+
const informeElement = document.querySelector('#informe_output');
|
484 |
+
const range = document.createRange();
|
485 |
+
range.selectNode(informeElement);
|
486 |
+
window.getSelection().removeAllRanges();
|
487 |
+
window.getSelection().addRange(range);
|
488 |
+
document.execCommand('copy');
|
489 |
+
window.getSelection().removeAllRanges();
|
490 |
+
alert('Informe copiado al portapapeles');
|
491 |
+
}
|
492 |
+
"""
|
493 |
)
|
494 |
|
495 |
# Eventos de exportar informes
|