simplified
Browse files- handler.py +8 -19
- requirements.txt +0 -1
handler.py
CHANGED
|
@@ -3,22 +3,10 @@ import base64
|
|
| 3 |
import io
|
| 4 |
import tempfile
|
| 5 |
from PIL import Image
|
| 6 |
-
from pdf2image import convert_from_path
|
| 7 |
import logging
|
| 8 |
|
| 9 |
-
def process_image(
|
| 10 |
-
|
| 11 |
-
# PDF input -> convert to images -> find crash diagram
|
| 12 |
-
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
| 13 |
-
temp_file.write(pdfdata)
|
| 14 |
-
temp_file.flush()
|
| 15 |
-
print("temporary name:", temp_file.name)
|
| 16 |
-
images = convert_from_path(temp_file.name)
|
| 17 |
-
|
| 18 |
-
crash_img = None
|
| 19 |
-
for img in images:
|
| 20 |
-
crash_img = img.crop((0,0, 200, 200))
|
| 21 |
-
break
|
| 22 |
|
| 23 |
if crash_img:
|
| 24 |
img_io = io.BytesIO()
|
|
@@ -43,9 +31,10 @@ class EndpointHandler:
|
|
| 43 |
def __call__(self, data: Any) -> List[List[Dict[str, str]]]:
|
| 44 |
logging.warning("inside __call__")
|
| 45 |
inputs = data.pop("inputs", data)
|
| 46 |
-
|
| 47 |
-
if isinstance(
|
| 48 |
-
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
-
|
|
|
|
| 3 |
import io
|
| 4 |
import tempfile
|
| 5 |
from PIL import Image
|
|
|
|
| 6 |
import logging
|
| 7 |
|
| 8 |
+
def process_image(img):
|
| 9 |
+
crash_img = img.crop((0,0, 200, 200))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
if crash_img:
|
| 12 |
img_io = io.BytesIO()
|
|
|
|
| 31 |
def __call__(self, data: Any) -> List[List[Dict[str, str]]]:
|
| 32 |
logging.warning("inside __call__")
|
| 33 |
inputs = data.pop("inputs", data)
|
| 34 |
+
imagedata = inputs.pop("imagedata", inputs)
|
| 35 |
+
if isinstance(imagedata, str):
|
| 36 |
+
logging.warning("decoding pdfdata")
|
| 37 |
+
image_bytes = base64.b64decode(imagedata)
|
| 38 |
+
img = Image.open(io.BytesIO(image_bytes))
|
| 39 |
|
| 40 |
+
return process_image(img)
|
requirements.txt
CHANGED
|
@@ -1,2 +1 @@
|
|
| 1 |
-
pdf2image==1.17.0
|
| 2 |
pillow==10.4.0
|
|
|
|
|
|
|
| 1 |
pillow==10.4.0
|