Spaces:
Sleeping
Sleeping
File size: 840 Bytes
e1c4426 dc946ef 4fde749 39fa25b dc946ef e1c4426 dc946ef 39fa25b dc946ef 2c78092 dc946ef 39fa25b dc946ef 39fa25b dc946ef 95cc944 dc946ef |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
import gradio as gr
from xhtml2pdf import pisa
from io import BytesIO
import os
import uuid
def generate_dummy_pdf():
html = """
<html>
<body>
<h1>Hello, PDF!</h1>
<p>This is a test PDF file.</p>
</body>
</html>
"""
result = BytesIO()
pisa_status = pisa.CreatePDF(html, dest=result)
if pisa_status.err:
print("PDF generation failed")
return None
pdf_path = os.path.join(os.path.expanduser("~"), "Downloads", f"test_pdf_{uuid.uuid4().hex}.pdf")
with open(pdf_path, "wb") as f:
f.write(result.getvalue())
print("β
PDF saved at:", pdf_path)
return pdf_path
with gr.Blocks() as demo:
btn = gr.Button("π Generate PDF")
output = gr.File(label="π₯ Download PDF")
btn.click(fn=generate_dummy_pdf, inputs=[], outputs=output)
demo.launch()
|