Spaces:
Configuration error
Configuration error
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,7 +15,7 @@ def run_GOT(image_array, got_mode, ocr_box="", ocr_color=""):
|
|
| 15 |
# image = Image.fromarray(np.uint8(image_array))
|
| 16 |
image = image_array
|
| 17 |
if got_mode == "plain texts OCR":
|
| 18 |
-
res = model.chat(tokenizer, image, ocr_type='ocr')
|
| 19 |
elif got_mode == "format texts OCR":
|
| 20 |
res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file='./demo.html')
|
| 21 |
elif got_mode == "plain multi-crop OCR":
|
|
@@ -31,8 +31,8 @@ def run_GOT(image_array, got_mode, ocr_box="", ocr_color=""):
|
|
| 31 |
if "format" in got_mode:
|
| 32 |
with open('./demo.html', 'r') as f:
|
| 33 |
demo_html = f.read()
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
def task_update(task):
|
| 38 |
if "fine-grained" in task:
|
|
@@ -63,7 +63,7 @@ def fine_grained_update(task):
|
|
| 63 |
|
| 64 |
with gr.Blocks() as demo:
|
| 65 |
gr.Markdown("""
|
| 66 |
-
#
|
| 67 |
|
| 68 |
"🔥🔥🔥This is the official online demo of GOT-OCR-2.0 model!!!"
|
| 69 |
|
|
@@ -106,7 +106,8 @@ with gr.Blocks() as demo:
|
|
| 106 |
submit_button = gr.Button("Submit")
|
| 107 |
|
| 108 |
with gr.Column():
|
| 109 |
-
|
|
|
|
| 110 |
html_result = gr.HTML(label="rendered html")
|
| 111 |
|
| 112 |
gr.Examples(
|
|
@@ -120,7 +121,7 @@ with gr.Blocks() as demo:
|
|
| 120 |
["assets/color.png", "plain fine-grained OCR", "color", "red", ""],
|
| 121 |
],
|
| 122 |
inputs=[image_input, task_dropdown, fine_grained_dropdown, color_dropdown, box_input],
|
| 123 |
-
outputs=[
|
| 124 |
label="examples",
|
| 125 |
)
|
| 126 |
|
|
@@ -138,7 +139,7 @@ with gr.Blocks() as demo:
|
|
| 138 |
submit_button.click(
|
| 139 |
run_GOT,
|
| 140 |
inputs=[image_input, task_dropdown, box_input, color_dropdown],
|
| 141 |
-
outputs=[
|
| 142 |
)
|
| 143 |
|
| 144 |
demo.launch(share=True)
|
|
|
|
| 15 |
# image = Image.fromarray(np.uint8(image_array))
|
| 16 |
image = image_array
|
| 17 |
if got_mode == "plain texts OCR":
|
| 18 |
+
res = model.chat(tokenizer, image, ocr_type='ocr', stream_flag = True)
|
| 19 |
elif got_mode == "format texts OCR":
|
| 20 |
res = model.chat(tokenizer, image, ocr_type='format', render=True, save_render_file='./demo.html')
|
| 21 |
elif got_mode == "plain multi-crop OCR":
|
|
|
|
| 31 |
if "format" in got_mode:
|
| 32 |
with open('./demo.html', 'r') as f:
|
| 33 |
demo_html = f.read()
|
| 34 |
+
yield res, demo_html
|
| 35 |
+
yield res, None
|
| 36 |
|
| 37 |
def task_update(task):
|
| 38 |
if "fine-grained" in task:
|
|
|
|
| 63 |
|
| 64 |
with gr.Blocks() as demo:
|
| 65 |
gr.Markdown("""
|
| 66 |
+
# General OCR Theory: Towards OCR-2.0 via a Unified End-to-end Model
|
| 67 |
|
| 68 |
"🔥🔥🔥This is the official online demo of GOT-OCR-2.0 model!!!"
|
| 69 |
|
|
|
|
| 106 |
submit_button = gr.Button("Submit")
|
| 107 |
|
| 108 |
with gr.Column():
|
| 109 |
+
chatbot = gr.Chatbot(label="GOT output")
|
| 110 |
+
# ocr_result = gr.Textbox(label="GOT output")
|
| 111 |
html_result = gr.HTML(label="rendered html")
|
| 112 |
|
| 113 |
gr.Examples(
|
|
|
|
| 121 |
["assets/color.png", "plain fine-grained OCR", "color", "red", ""],
|
| 122 |
],
|
| 123 |
inputs=[image_input, task_dropdown, fine_grained_dropdown, color_dropdown, box_input],
|
| 124 |
+
outputs=[chatbot, html_result],
|
| 125 |
label="examples",
|
| 126 |
)
|
| 127 |
|
|
|
|
| 139 |
submit_button.click(
|
| 140 |
run_GOT,
|
| 141 |
inputs=[image_input, task_dropdown, box_input, color_dropdown],
|
| 142 |
+
outputs=[chatbot, html_result]
|
| 143 |
)
|
| 144 |
|
| 145 |
demo.launch(share=True)
|