Spaces:
Paused
Paused
File size: 797 Bytes
175f30a b17ed36 ee67380 b17ed36 c048a67 b17ed36 c048a67 b17ed36 | 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 26 27 | from PIL import Image
import fitz
# def load_input(file_path): # past code
# if file_path.lower().endswith(".pdf"):
# doc = fitz.open(file_path)
# page = doc[0]
# pix = page.get_pixmap()
# img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
# return img
# else:
# return Image.open(file_path).convert("RGB")
def load_input(file_path):
if file_path.lower().endswith(".pdf"):
doc = fitz.open(file_path)
images = []
for page in doc:
pix = page.get_pixmap()
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
images.append(img)
return images # 🔥 return list
else:
return [Image.open(file_path).convert("RGB")] |