Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -492,5 +492,30 @@ return (
|
|
| 492 |
fixed_code,
|
| 493 |
report
|
| 494 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 495 |
if __name__ == "__main__":
|
| 496 |
demo.launch()
|
|
|
|
| 492 |
fixed_code,
|
| 493 |
report
|
| 494 |
)
|
| 495 |
+
from reportlab.platypus import SimpleDocTemplate, Paragraph
|
| 496 |
+
from reportlab.lib.styles import getSampleStyleSheet
|
| 497 |
+
|
| 498 |
+
def create_pdf(report_text):
|
| 499 |
+
pdf_path = "security_report.pdf"
|
| 500 |
+
|
| 501 |
+
doc = SimpleDocTemplate(pdf_path)
|
| 502 |
+
|
| 503 |
+
styles = getSampleStyleSheet()
|
| 504 |
+
|
| 505 |
+
elements = [
|
| 506 |
+
Paragraph(report_text.replace("\n", "<br/>"), styles["BodyText"])
|
| 507 |
+
]
|
| 508 |
+
|
| 509 |
+
doc.build(elements)
|
| 510 |
+
|
| 511 |
+
return pdf_path
|
| 512 |
+
download_btn = gr.Button("Generate PDF Report")
|
| 513 |
+
pdf_file = gr.File(label="Download Report")
|
| 514 |
+
download_btn.click(
|
| 515 |
+
create_pdf,
|
| 516 |
+
inputs=report_output,
|
| 517 |
+
outputs=pdf_file
|
| 518 |
+
)
|
| 519 |
+
|
| 520 |
if __name__ == "__main__":
|
| 521 |
demo.launch()
|