Spaces:
Running
on
Zero
Running
on
Zero
Revert "initial commit"
Browse filesThis reverts commit 6c3c1e89b3ab981b79a13afc00dc7e6ddc3f7fe0.
app.py
CHANGED
@@ -54,36 +54,24 @@ def image_to_base64(image):
|
|
54 |
|
55 |
@spaces.GPU
|
56 |
def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None, render=False):
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
elif task == "Multi-crop OCR":
|
73 |
-
res = model.chat_crop(tokenizer, image_file=image_base64)
|
74 |
-
elif task == "Render Formatted OCR":
|
75 |
-
res = model.chat(tokenizer, image_base64, ocr_type='format', render=True, save_render_file='./results/demo.html')
|
76 |
-
with open('./results/demo.html', 'r') as f:
|
77 |
-
html_content = f.read()
|
78 |
-
return res, html_content
|
79 |
-
|
80 |
-
# Clean up
|
81 |
-
os.remove(img_path)
|
82 |
-
|
83 |
-
return res, None
|
84 |
-
except Exception as e:
|
85 |
-
return str(e), None
|
86 |
|
|
|
|
|
87 |
def update_inputs(task):
|
88 |
if task == "Plain Text OCR" or task == "Format Text OCR" or task == "Multi-crop OCR":
|
89 |
return [gr.update(visible=False)] * 4
|
|
|
54 |
|
55 |
@spaces.GPU
|
56 |
def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None, render=False):
|
57 |
+
if task == "Plain Text OCR":
|
58 |
+
res = model.chat(tokenizer, image, ocr_type='ocr')
|
59 |
+
elif task == "Format Text OCR":
|
60 |
+
res = model.chat(tokenizer, image, ocr_type='format')
|
61 |
+
elif task == "Fine-grained OCR (Box)":
|
62 |
+
res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_box=ocr_box)
|
63 |
+
elif task == "Fine-grained OCR (Color)":
|
64 |
+
res = model.chat(tokenizer, image, ocr_type=ocr_type, ocr_color=ocr_color)
|
65 |
+
elif task == "Multi-crop OCR":
|
66 |
+
res = model.chat_crop(tokenizer, image_file=image)
|
67 |
+
elif task == "Render Formatted OCR":
|
68 |
+
res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file='./demo.html')
|
69 |
+
with open('./demo.html', 'r') as f:
|
70 |
+
html_content = f.read()
|
71 |
+
return res, html_content
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
72 |
|
73 |
+
return res, None
|
74 |
+
|
75 |
def update_inputs(task):
|
76 |
if task == "Plain Text OCR" or task == "Format Text OCR" or task == "Multi-crop OCR":
|
77 |
return [gr.update(visible=False)] * 4
|