Spaces:
Paused
Paused
Update processor_utils.py
Browse files- processor_utils.py +20 -5
processor_utils.py
CHANGED
|
@@ -1,12 +1,27 @@
|
|
| 1 |
from PIL import Image
|
| 2 |
import fitz
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
def load_input(file_path):
|
| 5 |
if file_path.lower().endswith(".pdf"):
|
| 6 |
doc = fitz.open(file_path)
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
else:
|
| 12 |
-
return Image.open(file_path).convert("RGB")
|
|
|
|
| 1 |
from PIL import Image
|
| 2 |
import fitz
|
| 3 |
|
| 4 |
+
# def load_input(file_path): # past code
|
| 5 |
+
# if file_path.lower().endswith(".pdf"):
|
| 6 |
+
# doc = fitz.open(file_path)
|
| 7 |
+
# page = doc[0]
|
| 8 |
+
# pix = page.get_pixmap()
|
| 9 |
+
# img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
|
| 10 |
+
# return img
|
| 11 |
+
# else:
|
| 12 |
+
# return Image.open(file_path).convert("RGB")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
def load_input(file_path):
|
| 16 |
if file_path.lower().endswith(".pdf"):
|
| 17 |
doc = fitz.open(file_path)
|
| 18 |
+
|
| 19 |
+
images = []
|
| 20 |
+
for page in doc:
|
| 21 |
+
pix = page.get_pixmap()
|
| 22 |
+
img = Image.frombytes("RGB", [pix.width, pix.height], pix.samples)
|
| 23 |
+
images.append(img)
|
| 24 |
+
|
| 25 |
+
return images # 🔥 return list
|
| 26 |
else:
|
| 27 |
+
return [Image.open(file_path).convert("RGB")]
|