File size: 634 Bytes
c7f3bef
40c1877
 
c7f3bef
40c1877
 
 
 
 
 
 
 
 
 
 
de759fe
3e75990
40c1877
 
 
 
b215e79
40c1877
 
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
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()