File size: 631 Bytes
bd45f63
 
 
 
 
 
 
 
 
 
 
a9d05a2
 
 
 
 
bd45f63
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import gradio as gr
import os

def compress_pdf(input_pdf):
    output_pdf = f"{os.path.splitext(input_pdf.name)[0]}_comprimido.pdf"
    gs_command = f"gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile={output_pdf} {input_pdf.name}"
    os.system(gs_command)
    return output_pdf

# Interface do Gradio
interface = gr.Interface(
    fn=compress_pdf,
    inputs=gr.inputs.File(label="Upload your PDF"),
    outputs=gr.outputs.File(label="Download compressed PDF"),
    title="PDF Compressor",
    description="Compress your PDF files using Ghostscript"
)

interface.launch()