Spaces:
Running
Running
Add the function of adjusting parameters
Browse files- app.py +15 -3
- rapidocr_onnxruntime/rapid_ocr_api.py +13 -1
- requirements.txt +1 -1
app.py
CHANGED
@@ -93,20 +93,32 @@ def visualize(image_path, boxes, rec_res, font_path="resources/fonts/FZYTK.TTF")
|
|
93 |
return image_save
|
94 |
|
95 |
|
96 |
-
def inference(img):
|
97 |
img_path = img.name
|
98 |
img = cv2.imread(img_path)
|
99 |
-
dt_boxes, rec_res = text_sys(img
|
|
|
|
|
|
|
100 |
img_save_path = visualize(img_path, dt_boxes, rec_res)
|
101 |
return img_save_path, rec_res
|
102 |
|
|
|
103 |
title = 'Rapid🗲OCR Demo (捷智OCR)'
|
104 |
description = 'Gradio demo for RapidOCR. Github Repo: https://github.com/RapidAI/RapidOCR'
|
105 |
article = "<p style='text-align: center'> Completely open source, free and support offline deployment of multi-platform and multi-language OCR SDK <a href='https://github.com/RapidAI/RapidOCR'>Github Repo</a></p>"
|
106 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
107 |
gr.Interface(
|
108 |
inference,
|
109 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
outputs=[
|
111 |
gr.outputs.Image(type='file', label='Output_image'),
|
112 |
gr.outputs.Textbox(type='text', label='Output_text')
|
|
|
93 |
return image_save
|
94 |
|
95 |
|
96 |
+
def inference(img, box_thresh, unclip_ratio, text_score):
|
97 |
img_path = img.name
|
98 |
img = cv2.imread(img_path)
|
99 |
+
dt_boxes, rec_res = text_sys(img,
|
100 |
+
box_thresh=box_thresh,
|
101 |
+
unclip_ratio=unclip_ratio,
|
102 |
+
text_score=text_score)
|
103 |
img_save_path = visualize(img_path, dt_boxes, rec_res)
|
104 |
return img_save_path, rec_res
|
105 |
|
106 |
+
|
107 |
title = 'Rapid🗲OCR Demo (捷智OCR)'
|
108 |
description = 'Gradio demo for RapidOCR. Github Repo: https://github.com/RapidAI/RapidOCR'
|
109 |
article = "<p style='text-align: center'> Completely open source, free and support offline deployment of multi-platform and multi-language OCR SDK <a href='https://github.com/RapidAI/RapidOCR'>Github Repo</a></p>"
|
110 |
css = ".output_image, .input_image {height: 40rem !important; width: 100% !important;}"
|
111 |
gr.Interface(
|
112 |
inference,
|
113 |
+
inputs=[
|
114 |
+
gr.inputs.Image(type='file', label='Input'),
|
115 |
+
gr.Slider(minimum=0, maximum=1.0, value=0.5,
|
116 |
+
label='box_thresh', step=0.1),
|
117 |
+
gr.Slider(minimum=1.5, maximum=2.0, value=1.6,
|
118 |
+
label='unclip_ratio', step=0.1),
|
119 |
+
gr.Slider(minimum=0, maximum=1.0, value=0.5,
|
120 |
+
label='text_score', step=0.1),
|
121 |
+
],
|
122 |
outputs=[
|
123 |
gr.outputs.Image(type='file', label='Output_image'),
|
124 |
gr.outputs.Textbox(type='text', label='Output_text')
|
rapidocr_onnxruntime/rapid_ocr_api.py
CHANGED
@@ -42,7 +42,19 @@ class TextSystem(object):
|
|
42 |
config['Cls']['class_name'])
|
43 |
self.text_cls = TextClassifier(config['Cls'])
|
44 |
|
45 |
-
def __call__(self, img: np.ndarray):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
h, w = img.shape[:2]
|
47 |
if self.width_height_ratio == -1:
|
48 |
use_limit_ratio = False
|
|
|
42 |
config['Cls']['class_name'])
|
43 |
self.text_cls = TextClassifier(config['Cls'])
|
44 |
|
45 |
+
def __call__(self, img: np.ndarray, **kwargs):
|
46 |
+
# 这里更改几个超参数的值
|
47 |
+
if kwargs:
|
48 |
+
# 获得超参数
|
49 |
+
box_thresh = kwargs.get('box_thresh', 0.5)
|
50 |
+
unclip_ratio = kwargs.get('unclip_ratio', 1.6)
|
51 |
+
text_score = kwargs.get('text_score', 0.5)
|
52 |
+
|
53 |
+
# 更新超参数
|
54 |
+
self.text_detector.postprocess_op.box_thresh = box_thresh
|
55 |
+
self.text_detector.postprocess_op.unclip_ratio = unclip_ratio
|
56 |
+
self.text_score = text_score
|
57 |
+
|
58 |
h, w = img.shape[:2]
|
59 |
if self.width_height_ratio == -1:
|
60 |
use_limit_ratio = False
|
requirements.txt
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
Gradio
|
2 |
pyclipper>=1.2.0
|
3 |
Shapely>=1.7.1
|
4 |
-
opencv_python
|
5 |
six>=1.15.0
|
6 |
numpy>=1.19.5
|
7 |
Pillow
|
|
|
1 |
Gradio
|
2 |
pyclipper>=1.2.0
|
3 |
Shapely>=1.7.1
|
4 |
+
opencv_python>=4.5.1.48
|
5 |
six>=1.15.0
|
6 |
numpy>=1.19.5
|
7 |
Pillow
|