Sonu Prasad
Update app.py
aa2ee61 verified
raw
history blame contribute delete
950 Bytes
import gradio as gr
from pdf2image import convert_from_path
from io import BytesIO
def pdf_to_images(pdf_file):
images = convert_from_path(pdf_file.name) # Use the name to read the file
img_list = []
for i, image in enumerate(images):
img_buffer = BytesIO()
image.save(img_buffer, format="PNG") # Save image as PNG
img_buffer.seek(0) # Go to the start of the BytesIO buffer
img_list.append(img_buffer.getvalue()) # Append the byte data of the image
return img_list
with gr.Blocks() as demo:
gr.Markdown("# PDF to Image Converter")
pdf_input = gr.File(label="Upload PDF", type="file") # Correctly specify 'file'
output_gallery = gr.Gallery(label="Converted Images", scale=1.0, show_label=True, elem_id="gallery") # Removed the .style() method
pdf_input.change(fn=pdf_to_images, inputs=pdf_input, outputs=output_gallery) # Update output when the PDF is uploaded
demo.launch()