uartimcs's picture
Update app.py
40c1877 verified
raw
history blame
634 Bytes
import gradio as gr
import fitz # PyMuPDF
from PIL import Image
def pdf_to_jpg(pdf_file):
# Open the PDF file
document = fitz.open(pdf_file.name)
# Get the first page
page = document.load_page(0)
# Render the page to a pixmap
pix = page.get_pixmap()
# Save the pixmap as an image
image = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
image_path = "first_page.jpg"
image.save(image_path)
return image_path
interface = gr.Interface(
fn=pdf_to_jpg,
inputs=gr.inputs.File(label="Upload PDF"),
outputs=gr.outputs.Image(label="First Page JPG")
)
interface.launch()