Spaces:
Runtime error
Runtime error
add back loadimg
Browse files
app.py
CHANGED
@@ -50,10 +50,12 @@ model.config.pad_token_id = tokenizer.eos_token_id
|
|
50 |
def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None, render=False):
|
51 |
if isinstance(image, str):
|
52 |
img_path = image
|
|
|
53 |
else:
|
54 |
img = Image.open(image)
|
55 |
img_path = "/tmp/temp_image.png"
|
56 |
img.save(img_path)
|
|
|
57 |
if task == "Plain Text OCR":
|
58 |
res = model.chat(tokenizer, img, ocr_type='ocr')
|
59 |
elif task == "Format Text OCR":
|
@@ -63,7 +65,7 @@ def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None, rend
|
|
63 |
elif task == "Fine-grained OCR (Color)":
|
64 |
res = model.chat(tokenizer, img, ocr_type=ocr_type, ocr_color=ocr_color)
|
65 |
elif task == "Multi-crop OCR":
|
66 |
-
res = model.chat_crop(tokenizer, image_file=
|
67 |
elif task == "Render Formatted OCR":
|
68 |
res = model.chat(tokenizer, img, ocr_type='format', render=True, save_render_file='./results/demo.html')
|
69 |
with open('./results/demo.html', 'r') as f:
|
|
|
50 |
def process_image(image, task, ocr_type=None, ocr_box=None, ocr_color=None, render=False):
|
51 |
if isinstance(image, str):
|
52 |
img_path = image
|
53 |
+
img = Image.open(img_path)
|
54 |
else:
|
55 |
img = Image.open(image)
|
56 |
img_path = "/tmp/temp_image.png"
|
57 |
img.save(img_path)
|
58 |
+
|
59 |
if task == "Plain Text OCR":
|
60 |
res = model.chat(tokenizer, img, ocr_type='ocr')
|
61 |
elif task == "Format Text OCR":
|
|
|
65 |
elif task == "Fine-grained OCR (Color)":
|
66 |
res = model.chat(tokenizer, img, ocr_type=ocr_type, ocr_color=ocr_color)
|
67 |
elif task == "Multi-crop OCR":
|
68 |
+
res = model.chat_crop(tokenizer, image_file=img_path)
|
69 |
elif task == "Render Formatted OCR":
|
70 |
res = model.chat(tokenizer, img, ocr_type='format', render=True, save_render_file='./results/demo.html')
|
71 |
with open('./results/demo.html', 'r') as f:
|