breezedeus commited on
Commit
d0b122c
1 Parent(s): fde8e63

upgrade the interface; use cnocr >= 2.3

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. app.py +65 -41
  3. requirements.txt +1 -1
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🎡
4
  colorFrom: indigo
5
  colorTo: yellow
6
  sdk: gradio
7
- sdk_version: 3.44.4
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
4
  colorFrom: indigo
5
  colorTo: yellow
6
  sdk: gradio
7
+ sdk_version: 4.11.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
app.py CHANGED
@@ -189,10 +189,14 @@ def main():
189
  det_models = [f'{m}::{b}' for m, b in det_models]
190
 
191
  all_models = list(REC_AVAILABLE_MODELS.all_models())
192
- all_models.sort()
193
  all_models = [f'{m}' for m, b in all_models if b == 'onnx']
 
 
 
 
 
194
 
195
- title = '开源Python OCR工具:'
196
  desc = (
197
  '<p style="text-align: center">详细说明参见:<a href="https://github.com/breezedeus/CnOCR" target="_blank">Github</a>;'
198
  '<a href="https://cnocr.readthedocs.io" target="_blank">在线文档</a>;'
@@ -261,13 +265,30 @@ def main():
261
  ],
262
  ]
263
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
264
  with gr.Blocks() as demo:
265
- gr.Markdown(
266
- f'<h1 style="text-align: center; margin-bottom: 1rem;">{title} <a href="https://github.com/breezedeus/cnocr" target="_blank">CnOCR</a></h1>'
267
  )
268
- gr.Markdown(desc)
269
  with gr.Row(equal_height=False):
270
- with gr.Column(min_width=200, variant='panel', scale=1):
271
  gr.Markdown('### 模型设置')
272
  det_model_name = gr.Dropdown(
273
  label='选择检测模型', choices=det_models, value='ch_PP-OCRv3_det::onnx',
@@ -277,48 +298,51 @@ def main():
277
  rec_model_name = gr.Dropdown(
278
  label='选择识别模型',
279
  choices=all_models,
280
- value='densenet_lite_136-fc',
281
  )
282
 
283
  gr.Markdown('### 检测参数')
284
  rotated_bbox = gr.Checkbox(label='检测带角度文本框', value=True)
285
  use_angle_clf = gr.Checkbox(label='使用角度预测模型校正文本框', value=False)
286
- new_size = gr.Slider(
287
- label='resize 后图片(长边)大小', minimum=124, maximum=4096, value=768
288
- )
289
- box_score_thresh = gr.Slider(
290
- label='得分阈值(低于阈值的结果会被过滤掉)', minimum=0.05, maximum=0.95, value=0.3
291
- )
292
- min_box_size = gr.Slider(
293
- label='框大小阈值(更小的文本框会被过滤掉)', minimum=4, maximum=50, value=10
294
- )
295
-
296
- with gr.Column(scale=3, variant='compact'):
 
297
  gr.Markdown('### 选择待识别图片')
298
  image_file = gr.Image(label='待识别图片', type="pil", image_mode='RGB')
299
  sub_btn = gr.Button("Submit", variant="primary")
300
- out_image = gr.Image(label='识别结果', interactive=False, visible=False)
301
- naive_warn = gr.Markdown(
302
- '**⚠️ Warning**: "naive_det" 检测模型不返回文本框位置!', visible=False
303
- )
304
- out_texts = gr.Dataframe(
305
- headers=['得分', '文本'], label='识别结果', interactive=False, visible=False
306
- )
307
- sub_btn.click(
308
- recognize,
309
- inputs=[
310
- det_model_name,
311
- is_single_line,
312
- rec_model_name,
313
- rotated_bbox,
314
- use_angle_clf,
315
- new_size,
316
- box_score_thresh,
317
- min_box_size,
318
- image_file,
319
- ],
320
- outputs=[out_image, naive_warn, out_texts],
321
- )
 
 
322
 
323
  gr.Examples(
324
  label='示例',
@@ -335,7 +359,7 @@ def main():
335
  cache_examples=os.getenv('CACHE_EXAMPLES') == '1',
336
  )
337
 
338
- demo.queue(concurrency_count=4)
339
  demo.launch()
340
 
341
 
 
189
  det_models = [f'{m}::{b}' for m, b in det_models]
190
 
191
  all_models = list(REC_AVAILABLE_MODELS.all_models())
 
192
  all_models = [f'{m}' for m, b in all_models if b == 'onnx']
193
+ cnocr_models = [name for name in all_models if 'densenet' in name]
194
+ cnocr_models.sort()
195
+ other_models = [name for name in all_models if 'densenet' not in name]
196
+ other_models.sort()
197
+ all_models = cnocr_models + other_models
198
 
199
+ title = 'Python 开源中英 OCR 工具:'
200
  desc = (
201
  '<p style="text-align: center">详细说明参见:<a href="https://github.com/breezedeus/CnOCR" target="_blank">Github</a>;'
202
  '<a href="https://cnocr.readthedocs.io" target="_blank">在线文档</a>;'
 
265
  ],
266
  ]
267
 
268
+ table_desc = """
269
+ <div align="center">
270
+ <img src="https://www.notion.so/image/https%3A%2F%2Fprod-files-secure.s3.us-west-2.amazonaws.com%2F9341931a-53f0-48e1-b026-0f1ad17b457c%2Fc41e0b1d-4869-4e39-93db-631569e6a38d%2FUntitled.png?table=block&id=3d0819ca-2e1a-46a7-b6f3-b4cf89cd045c" width="120px"/>
271
+
272
+ [![Visitors](https://api.visitorbadge.io/api/visitors?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2Fbreezedeus%2FCnOCR-Demo&labelColor=%23697689&countColor=%23f5c791&style=flat&labelStyle=upper)](https://visitorbadge.io/status?path=https%3A%2F%2Fhuggingface.co%2Fspaces%2Fbreezedeus%2FCnOCR-Demo)
273
+
274
+ | | |
275
+ | ------------------------------- | --------------------------------------- |
276
+ | 📀 **Code** | [Github](https://github.com/breezedeus/cnocr) |
277
+ | 📖 **Doc** | [在线文档](https://cnocr.readthedocs.io) |
278
+ | 🧳 **Models** | [可用模型](https://cnocr.readthedocs.io/zh/latest/models/) |
279
+ | 💬 **Contact** | [交流群](https://www.breezedeus.com/join-group) |
280
+ | 👨🏻‍💻 **Author** | [Breezedeus](https://www.breezedeus.com) |
281
+
282
+ 有用还请帮忙 **star 🌟 [CnOCR](https://github.com/breezedeus/cnocr)** 🙏
283
+ </div>
284
+ """
285
+
286
  with gr.Blocks() as demo:
287
+ gr.HTML(
288
+ f'<h1 style="text-align: center; margin-bottom: 1rem;">{title} <a href="https://github.com/breezedeus/cnocr" target="_blank">CnOCR V2.3</a></h1>'
289
  )
 
290
  with gr.Row(equal_height=False):
291
+ with gr.Column(min_width=200, variant='panel', scale=3):
292
  gr.Markdown('### 模型设置')
293
  det_model_name = gr.Dropdown(
294
  label='选择检测模型', choices=det_models, value='ch_PP-OCRv3_det::onnx',
 
298
  rec_model_name = gr.Dropdown(
299
  label='选择识别模型',
300
  choices=all_models,
301
+ value='densenet_lite_136-gru',
302
  )
303
 
304
  gr.Markdown('### 检测参数')
305
  rotated_bbox = gr.Checkbox(label='检测带角度文本框', value=True)
306
  use_angle_clf = gr.Checkbox(label='使用角度预测模型校正文本框', value=False)
307
+ with gr.Accordion('更多选项', open=False):
308
+ new_size = gr.Slider(
309
+ label='resize 后图片(长边)大小', minimum=124, maximum=4096, value=768
310
+ )
311
+ box_score_thresh = gr.Slider(
312
+ label='得分阈值(低于阈值的结果会被过滤掉)', minimum=0.05, maximum=0.95, value=0.3
313
+ )
314
+ min_box_size = gr.Slider(
315
+ label='框大小阈值(更小的文本框会被过滤掉)', minimum=4, maximum=50, value=10
316
+ )
317
+
318
+ with gr.Column(scale=5, variant='compact'):
319
  gr.Markdown('### 选择待识别图片')
320
  image_file = gr.Image(label='待识别图片', type="pil", image_mode='RGB')
321
  sub_btn = gr.Button("Submit", variant="primary")
322
+ with gr.Column(scale=2, variant='compact'):
323
+ gr.Markdown(table_desc)
324
+ out_image = gr.Image(label='识别结果', interactive=False, visible=False)
325
+ naive_warn = gr.Markdown(
326
+ '**⚠️ Warning**: "naive_det" 检测模型不返回文本框位置!', visible=False
327
+ )
328
+ out_texts = gr.Dataframe(
329
+ headers=['得分', '文本'], label='识别结果', interactive=False, visible=False
330
+ )
331
+ sub_btn.click(
332
+ recognize,
333
+ inputs=[
334
+ det_model_name,
335
+ is_single_line,
336
+ rec_model_name,
337
+ rotated_bbox,
338
+ use_angle_clf,
339
+ new_size,
340
+ box_score_thresh,
341
+ min_box_size,
342
+ image_file,
343
+ ],
344
+ outputs=[out_image, naive_warn, out_texts],
345
+ )
346
 
347
  gr.Examples(
348
  label='示例',
 
359
  cache_examples=os.getenv('CACHE_EXAMPLES') == '1',
360
  )
361
 
362
+ demo.queue(max_size=10)
363
  demo.launch()
364
 
365
 
requirements.txt CHANGED
@@ -277,7 +277,7 @@ yarl==1.9.2
277
  zipp==3.15.0
278
  # via importlib-resources
279
 
280
- cnocr==2.2.4.1
281
 
282
  # The following packages are considered to be unsafe in a requirements file:
283
  # setuptools
 
277
  zipp==3.15.0
278
  # via importlib-resources
279
 
280
+ cnocr==2.3
281
 
282
  # The following packages are considered to be unsafe in a requirements file:
283
  # setuptools