Spaces:
Running
on
Zero
Running
on
Zero
do it normally
Browse files
app.py
CHANGED
@@ -51,13 +51,10 @@ model.config.pad_token_id = tokenizer.eos_token_id
|
|
51 |
|
52 |
|
53 |
|
54 |
-
def
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
return image
|
59 |
-
else:
|
60 |
-
raise ValueError("Unsupported image type")
|
61 |
|
62 |
@spaces.GPU
|
63 |
def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
|
@@ -65,8 +62,8 @@ def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
|
|
65 |
if image is None:
|
66 |
return "No image provided", None
|
67 |
|
68 |
-
#
|
69 |
-
|
70 |
|
71 |
with io.BytesIO() as buffer:
|
72 |
pil_image.save(buffer, format="PNG")
|
|
|
51 |
|
52 |
|
53 |
|
54 |
+
def save_image_to_temp_file(image):
|
55 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
|
56 |
+
image.save(temp_file, format="PNG")
|
57 |
+
return temp_file.name
|
|
|
|
|
|
|
58 |
|
59 |
@spaces.GPU
|
60 |
def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
|
|
|
62 |
if image is None:
|
63 |
return "No image provided", None
|
64 |
|
65 |
+
# Save the PIL Image to a temporary file
|
66 |
+
temp_image_path = save_image_to_temp_file(image)
|
67 |
|
68 |
with io.BytesIO() as buffer:
|
69 |
pil_image.save(buffer, format="PNG")
|