Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ from typing import List, Union
|
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
import numpy as np
|
|
|
|
| 10 |
from rapidocr import RapidOCR
|
| 11 |
|
| 12 |
|
|
@@ -43,13 +44,21 @@ def get_ocr_result(
|
|
| 43 |
lang_rec,
|
| 44 |
infer_engine,
|
| 45 |
is_word: str,
|
|
|
|
| 46 |
):
|
| 47 |
-
return_word_box =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
ocr_engine = get_ocr_engine(infer_engine, lang_det=lang_det, lang_rec=lang_rec)
|
| 50 |
|
| 51 |
ocr_result = ocr_engine(
|
| 52 |
img,
|
|
|
|
|
|
|
|
|
|
| 53 |
text_score=text_score,
|
| 54 |
box_thresh=box_thresh,
|
| 55 |
unclip_ratio=unclip_ratio,
|
|
@@ -61,10 +70,19 @@ def get_ocr_result(
|
|
| 61 |
ocr_txts = [[i, txt, score] for i, (txt, score) in enumerate(zip(txts, scores))]
|
| 62 |
return vis_img, ocr_txts, ocr_result.elapse
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
return vis_img, ocr_txts, ocr_result.elapse
|
| 69 |
|
| 70 |
|
|
@@ -128,7 +146,7 @@ with gr.Blocks(
|
|
| 128 |
gr.HTML(
|
| 129 |
"""
|
| 130 |
<h1 style='text-align: center;font-size:40px'>Rapid⚡OCR</h1>
|
| 131 |
-
|
| 132 |
<div style="display: flex; justify-content: center; gap: 10px;">
|
| 133 |
<a href=""><img src="https://img.shields.io/badge/Python->=3.6-aff.svg"></a>
|
| 134 |
<a href="https://rapidai.github.io/RapidOCRDocs"><img src="https://img.shields.io/badge/Docs-link-aff.svg"></a>
|
|
@@ -166,6 +184,12 @@ with gr.Blocks(
|
|
| 166 |
)
|
| 167 |
|
| 168 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
select_infer_engine = gr.Dropdown(
|
| 170 |
choices=infer_engine_list,
|
| 171 |
label="Infer Engine (推理引擎)",
|
|
@@ -210,6 +234,7 @@ with gr.Blocks(
|
|
| 210 |
lang_rec,
|
| 211 |
select_infer_engine,
|
| 212 |
is_word,
|
|
|
|
| 213 |
]
|
| 214 |
run_btn.click(
|
| 215 |
get_ocr_result, inputs=ocr_inputs, outputs=[img_output, ocr_results, elapse]
|
|
|
|
| 7 |
|
| 8 |
import gradio as gr
|
| 9 |
import numpy as np
|
| 10 |
+
|
| 11 |
from rapidocr import RapidOCR
|
| 12 |
|
| 13 |
|
|
|
|
| 44 |
lang_rec,
|
| 45 |
infer_engine,
|
| 46 |
is_word: str,
|
| 47 |
+
use_module: List[str],
|
| 48 |
):
|
| 49 |
+
return_word_box = "Yes" in is_word
|
| 50 |
+
|
| 51 |
+
use_det = "use_det" in use_module
|
| 52 |
+
use_cls = "use_cls" in use_module
|
| 53 |
+
use_rec = "use_rec" in use_module
|
| 54 |
|
| 55 |
ocr_engine = get_ocr_engine(infer_engine, lang_det=lang_det, lang_rec=lang_rec)
|
| 56 |
|
| 57 |
ocr_result = ocr_engine(
|
| 58 |
img,
|
| 59 |
+
use_det=use_det,
|
| 60 |
+
use_cls=use_cls,
|
| 61 |
+
use_rec=use_rec,
|
| 62 |
text_score=text_score,
|
| 63 |
box_thresh=box_thresh,
|
| 64 |
unclip_ratio=unclip_ratio,
|
|
|
|
| 70 |
ocr_txts = [[i, txt, score] for i, (txt, score) in enumerate(zip(txts, scores))]
|
| 71 |
return vis_img, ocr_txts, ocr_result.elapse
|
| 72 |
|
| 73 |
+
if use_det and use_rec:
|
| 74 |
+
ocr_txts = [
|
| 75 |
+
[i, txt, score]
|
| 76 |
+
for i, (txt, score) in enumerate(zip(ocr_result.txts, ocr_result.scores))
|
| 77 |
+
]
|
| 78 |
+
elif use_det and not use_cls and not use_rec:
|
| 79 |
+
ocr_txts = []
|
| 80 |
+
else not use_det and not use_cls and use_rec:
|
| 81 |
+
ocr_txts = [
|
| 82 |
+
[i, txt, score]
|
| 83 |
+
for i, (txt, score) in enumerate(zip(ocr_result.txts, ocr_result.scores))
|
| 84 |
+
]
|
| 85 |
+
|
| 86 |
return vis_img, ocr_txts, ocr_result.elapse
|
| 87 |
|
| 88 |
|
|
|
|
| 146 |
gr.HTML(
|
| 147 |
"""
|
| 148 |
<h1 style='text-align: center;font-size:40px'>Rapid⚡OCR</h1>
|
| 149 |
+
|
| 150 |
<div style="display: flex; justify-content: center; gap: 10px;">
|
| 151 |
<a href=""><img src="https://img.shields.io/badge/Python->=3.6-aff.svg"></a>
|
| 152 |
<a href="https://rapidai.github.io/RapidOCRDocs"><img src="https://img.shields.io/badge/Docs-link-aff.svg"></a>
|
|
|
|
| 184 |
)
|
| 185 |
|
| 186 |
with gr.Row():
|
| 187 |
+
use_module = gr.CheckboxGroup(
|
| 188 |
+
["use_det", "use_cls", "use_rec"],
|
| 189 |
+
label="Use module (使用哪些模块)",
|
| 190 |
+
value=["use_det", "use_cls", "use_rec"],
|
| 191 |
+
interactive=True,
|
| 192 |
+
)
|
| 193 |
select_infer_engine = gr.Dropdown(
|
| 194 |
choices=infer_engine_list,
|
| 195 |
label="Infer Engine (推理引擎)",
|
|
|
|
| 234 |
lang_rec,
|
| 235 |
select_infer_engine,
|
| 236 |
is_word,
|
| 237 |
+
use_module,
|
| 238 |
]
|
| 239 |
run_btn.click(
|
| 240 |
get_ocr_result, inputs=ocr_inputs, outputs=[img_output, ocr_results, elapse]
|