test / app.py
malavika-2016's picture
Update app.py
62f7377 verified
raw
history blame contribute delete
725 Bytes
import gradio as gr
from fpdf import FPDF
import os
import uuid
# PDF generation function
def text_to_pdf(text):
if not text.strip():
return "Please enter some text."
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
# Split text into lines
lines = text.split('\n')
for line in lines:
pdf.multi_cell(0, 10, line)
# Generate unique filename
filename = f"/tmp/output_{uuid.uuid4().hex[:8]}.pdf"
pdf.output(filename)
return filename
# Gradio UI
iface = gr.Interface(
fn=text_to_pdf,
inputs=gr.Textbox(lines=10, placeholder="Enter your text here..."),
outputs=gr.File(label="Download PDF"),
title="Text to PDF Generator"
)
iface.launch()