Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,7 @@ from datetime import datetime
|
|
6 |
import re
|
7 |
import os
|
8 |
import tempfile
|
|
|
9 |
from fpdf import FPDF, HTMLMixin
|
10 |
|
11 |
# ---------------- Funciones de an谩lisis y grafo -------------------
|
@@ -97,7 +98,7 @@ def analizar_transaccion(tx_id):
|
|
97 |
- Aplica heur铆stica para detectar posibles CoinJoin/mixers.
|
98 |
- Incorpora informaci贸n adicional de blockchain.com (etiqueta MIXER).
|
99 |
- Genera un grafo interactivo.
|
100 |
-
- Retorna un informe en HTML, la figura del grafo y una tupla (
|
101 |
"""
|
102 |
tx_data = get_transaction(tx_id)
|
103 |
if not tx_data:
|
@@ -246,7 +247,7 @@ def analizar_transaccion(tx_id):
|
|
246 |
</p>
|
247 |
</div>
|
248 |
"""
|
249 |
-
#
|
250 |
return reporte, fig, (reporte, fig)
|
251 |
|
252 |
except Exception as e:
|
@@ -299,13 +300,24 @@ def generar_pdf(report, fig):
|
|
299 |
|
300 |
def descargar_pdf(analysis_tuple):
|
301 |
"""
|
302 |
-
Funci贸n para generar y retornar
|
303 |
-
|
304 |
"""
|
305 |
if not analysis_tuple:
|
306 |
-
return
|
307 |
report, fig = analysis_tuple
|
308 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
309 |
|
310 |
# ---------------- INTERFAZ GR脕FICA CON GRADIO -------------------
|
311 |
|
@@ -364,8 +376,9 @@ with gr.Blocks(
|
|
364 |
|
365 |
analyze_btn.click(fn=analizar_transaccion, inputs=tx_input, outputs=[reporte_html, plot_output, analysis_state])
|
366 |
|
367 |
-
# Bot贸n
|
368 |
-
|
369 |
-
|
|
|
370 |
|
371 |
demo.launch()
|
|
|
6 |
import re
|
7 |
import os
|
8 |
import tempfile
|
9 |
+
import base64
|
10 |
from fpdf import FPDF, HTMLMixin
|
11 |
|
12 |
# ---------------- Funciones de an谩lisis y grafo -------------------
|
|
|
98 |
- Aplica heur铆stica para detectar posibles CoinJoin/mixers.
|
99 |
- Incorpora informaci贸n adicional de blockchain.com (etiqueta MIXER).
|
100 |
- Genera un grafo interactivo.
|
101 |
+
- Retorna un informe en HTML, la figura del grafo y una tupla (reporte, fig) para el PDF.
|
102 |
"""
|
103 |
tx_data = get_transaction(tx_id)
|
104 |
if not tx_data:
|
|
|
247 |
</p>
|
248 |
</div>
|
249 |
"""
|
250 |
+
# Devolver adem谩s una tupla (reporte, fig) para generar el PDF
|
251 |
return reporte, fig, (reporte, fig)
|
252 |
|
253 |
except Exception as e:
|
|
|
300 |
|
301 |
def descargar_pdf(analysis_tuple):
|
302 |
"""
|
303 |
+
Funci贸n para generar el PDF y retornar un HTML que incluya un enlace de descarga.
|
304 |
+
Se codifica el PDF en base64 y se inserta en un enlace que se activa autom谩ticamente.
|
305 |
"""
|
306 |
if not analysis_tuple:
|
307 |
+
return "<p>No hay an谩lisis generado.</p>"
|
308 |
report, fig = analysis_tuple
|
309 |
+
pdf_bytes = generar_pdf(report, fig)
|
310 |
+
pdf_b64 = base64.b64encode(pdf_bytes).decode("utf-8")
|
311 |
+
html_download = f'''
|
312 |
+
<html>
|
313 |
+
<body>
|
314 |
+
<a id="downloadLink" href="data:application/pdf;base64,{pdf_b64}" download="analisis.pdf" style="display:none;"></a>
|
315 |
+
<script>document.getElementById("downloadLink").click();</script>
|
316 |
+
<p>Si no se descarga autom谩ticamente, <a href="data:application/pdf;base64,{pdf_b64}" download="analisis.pdf">haz clic aqu铆</a>.</p>
|
317 |
+
</body>
|
318 |
+
</html>
|
319 |
+
'''
|
320 |
+
return html_download
|
321 |
|
322 |
# ---------------- INTERFAZ GR脕FICA CON GRADIO -------------------
|
323 |
|
|
|
376 |
|
377 |
analyze_btn.click(fn=analizar_transaccion, inputs=tx_input, outputs=[reporte_html, plot_output, analysis_state])
|
378 |
|
379 |
+
# Bot贸n para generar el PDF; al hacer clic se descarga autom谩ticamente el PDF
|
380 |
+
pdf_download_btn = gr.Button("GENERAR ANALISIS EN PDF", elem_classes=["custom-btn"])
|
381 |
+
download_html = gr.HTML()
|
382 |
+
pdf_download_btn.click(fn=descargar_pdf, inputs=analysis_state, outputs=download_html)
|
383 |
|
384 |
demo.launch()
|