#import os | |
import requests | |
from pdf2image import convert_from_bytes | |
def download_pdf(url): | |
response = requests.get(url) | |
return response.content | |
def convert_pdf_to_images(pdf_bytes): | |
images = convert_from_bytes(pdf_bytes) | |
#if not os.path.exists(output_folder): | |
#os.makedirs(output_folder) | |
for i, image in enumerate(images): | |
image.save(f'image{i}.png') | |
# Use the functions | |
#url = 'http://example.com/path_to_your_pdf.pdf' | |
#pdf_bytes = download_pdf(url) | |
#output_folder = os.environ.get('HUGGINGFACE_CACHE', 'images') | |
convert_pdf_to_images('hoor.pdf', output_folder) | |