File size: 725 Bytes
36a5b4a
62f7377
36a5b4a
62f7377
36a5b4a
62f7377
 
 
 
36a5b4a
62f7377
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36a5b4a
62f7377
 
 
 
36a5b4a
 
 
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
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()