Spaces:
Running
on
Zero
Running
on
Zero
do it normally
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import os
|
|
5 |
import base64
|
6 |
import spaces
|
7 |
import io
|
8 |
-
import numpy as np
|
9 |
from PIL import Image
|
10 |
import io
|
11 |
|
@@ -49,11 +49,13 @@ 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 |
def process_input_image(image):
|
53 |
-
if isinstance(image,
|
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 |
|
@@ -63,6 +65,7 @@ def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None):
|
|
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:
|
@@ -127,7 +130,7 @@ with gr.Blocks() as demo:
|
|
127 |
gr.Markdown(description)
|
128 |
with gr.Row():
|
129 |
with gr.Column():
|
130 |
-
image_input = gr.Image(type="
|
131 |
task_dropdown = gr.Dropdown(
|
132 |
choices=[
|
133 |
"Plain Text OCR",
|
|
|
5 |
import base64
|
6 |
import spaces
|
7 |
import io
|
8 |
+
# import numpy as np
|
9 |
from PIL import Image
|
10 |
import io
|
11 |
|
|
|
49 |
model = model.eval().cuda()
|
50 |
model.config.pad_token_id = tokenizer.eos_token_id
|
51 |
|
52 |
+
|
53 |
+
|
54 |
def process_input_image(image):
|
55 |
+
if isinstance(image, str):
|
|
|
|
|
56 |
return Image.open(image)
|
57 |
+
elif isinstance(image, Image.Image):
|
58 |
+
return image
|
59 |
else:
|
60 |
raise ValueError("Unsupported image type")
|
61 |
|
|
|
65 |
if image is None:
|
66 |
return "No image provided", None
|
67 |
|
68 |
+
# Process the input image
|
69 |
pil_image = process_input_image(image)
|
70 |
|
71 |
with io.BytesIO() as buffer:
|
|
|
130 |
gr.Markdown(description)
|
131 |
with gr.Row():
|
132 |
with gr.Column():
|
133 |
+
image_input = gr.Image(type="pil", label="Input Image")
|
134 |
task_dropdown = gr.Dropdown(
|
135 |
choices=[
|
136 |
"Plain Text OCR",
|