Spaces:
Running
on
Zero
Running
on
Zero
do it normally
Browse files
app.py
CHANGED
@@ -49,25 +49,24 @@ model = AutoModel.from_pretrained('ucaslcl/GOT-OCR2_0', trust_remote_code=True,
|
|
49 |
model = model.eval().cuda()
|
50 |
model.config.pad_token_id = tokenizer.eos_token_id
|
51 |
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
return Image.fromarray(image_np.astype('uint8'), 'RGB')
|
60 |
|
61 |
@spaces.GPU
|
62 |
-
def process_image(
|
63 |
try:
|
64 |
-
if
|
65 |
return "No image provided", None
|
66 |
|
67 |
-
|
68 |
|
69 |
with io.BytesIO() as buffer:
|
70 |
-
|
71 |
image_path = "/tmp/temp_image.png"
|
72 |
with open(image_path, "wb") as f:
|
73 |
f.write(buffer.getvalue())
|
|
|
49 |
model = model.eval().cuda()
|
50 |
model.config.pad_token_id = tokenizer.eos_token_id
|
51 |
|
52 |
+
def process_input_image(image):
|
53 |
+
if isinstance(image, np.ndarray):
|
54 |
+
return Image.fromarray(image.astype('uint8'), 'RGB')
|
55 |
+
elif isinstance(image, str):
|
56 |
+
return Image.open(image)
|
57 |
+
else:
|
58 |
+
raise ValueError("Unsupported image type")
|
|
|
59 |
|
60 |
@spaces.GPU
|
61 |
+
def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
|
62 |
try:
|
63 |
+
if image is None:
|
64 |
return "No image provided", None
|
65 |
|
66 |
+
pil_image = process_input_image(image)
|
67 |
|
68 |
with io.BytesIO() as buffer:
|
69 |
+
pil_image.save(buffer, format="PNG")
|
70 |
image_path = "/tmp/temp_image.png"
|
71 |
with open(image_path, "wb") as f:
|
72 |
f.write(buffer.getvalue())
|