Spaces:
Running
on
Zero
Running
on
Zero
add image editor
Browse files
app.py
CHANGED
@@ -14,6 +14,7 @@ import uuid
|
|
14 |
import tempfile
|
15 |
import time
|
16 |
import shutil
|
|
|
17 |
|
18 |
|
19 |
model_name = 'ucaslcl/GOT-OCR2_0'
|
@@ -38,6 +39,9 @@ def image_to_base64(image):
|
|
38 |
|
39 |
|
40 |
|
|
|
|
|
|
|
41 |
@spaces.GPU()
|
42 |
def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
|
43 |
if image is None:
|
@@ -52,15 +56,13 @@ def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
|
|
52 |
composite_image = image.get("composite")
|
53 |
if composite_image is not None:
|
54 |
if isinstance(composite_image, np.ndarray):
|
55 |
-
|
56 |
-
elif isinstance(composite_image, str):
|
57 |
-
shutil.copy(composite_image, image_path)
|
58 |
else:
|
59 |
return "Error: Unsupported image format from ImageEditor", None, None
|
60 |
else:
|
61 |
return "Error: No composite image found in ImageEditor output", None, None
|
62 |
elif isinstance(image, np.ndarray):
|
63 |
-
|
64 |
elif isinstance(image, str):
|
65 |
shutil.copy(image, image_path)
|
66 |
else:
|
@@ -92,6 +94,7 @@ def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
|
|
92 |
finally:
|
93 |
if os.path.exists(image_path):
|
94 |
os.remove(image_path)
|
|
|
95 |
def update_image_input(task):
|
96 |
if task == "Fine-grained OCR (Color)":
|
97 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
|
|
|
14 |
import tempfile
|
15 |
import time
|
16 |
import shutil
|
17 |
+
import cv2
|
18 |
|
19 |
|
20 |
model_name = 'ucaslcl/GOT-OCR2_0'
|
|
|
39 |
|
40 |
|
41 |
|
42 |
+
@spaces.GPU()
|
43 |
+
import cv2
|
44 |
+
|
45 |
@spaces.GPU()
|
46 |
def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
|
47 |
if image is None:
|
|
|
56 |
composite_image = image.get("composite")
|
57 |
if composite_image is not None:
|
58 |
if isinstance(composite_image, np.ndarray):
|
59 |
+
cv2.imwrite(image_path, cv2.cvtColor(composite_image, cv2.COLOR_RGB2BGR))
|
|
|
|
|
60 |
else:
|
61 |
return "Error: Unsupported image format from ImageEditor", None, None
|
62 |
else:
|
63 |
return "Error: No composite image found in ImageEditor output", None, None
|
64 |
elif isinstance(image, np.ndarray):
|
65 |
+
cv2.imwrite(image_path, cv2.cvtColor(image, cv2.COLOR_RGB2BGR))
|
66 |
elif isinstance(image, str):
|
67 |
shutil.copy(image, image_path)
|
68 |
else:
|
|
|
94 |
finally:
|
95 |
if os.path.exists(image_path):
|
96 |
os.remove(image_path)
|
97 |
+
|
98 |
def update_image_input(task):
|
99 |
if task == "Fine-grained OCR (Color)":
|
100 |
return gr.update(visible=False), gr.update(visible=True), gr.update(visible=True)
|