Robin Chiu
commited on
Commit
β’
9633a4f
1
Parent(s):
8af2372
Add application file
Browse files- README.md +5 -5
- app.py +93 -0
- images/img_10.jpg +0 -0
- images/img_11.jpg +0 -0
- images/img_12.jpg +0 -0
- images/img_195.jpg +0 -0
- packages.txt +0 -0
- requirements.txt +8 -0
README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
---
|
2 |
-
title:
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
-
sdk_version: 3.
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
|
|
1 |
---
|
2 |
+
title: Mmocr Demo
|
3 |
+
emoji: π
|
4 |
+
colorFrom: indigo
|
5 |
+
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
sdk_version: 3.0.25
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
license: apache-2.0
|
app.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
+
|
4 |
+
print(torch.__version__)
|
5 |
+
# torch_ver, cuda_ver = torch.__version__.split('+')
|
6 |
+
# os.system('pip list')
|
7 |
+
# os.system(f'pip install opencv-contrib-python==4.5.5.62 --no-cache-dir')
|
8 |
+
# os.system('pip list')
|
9 |
+
# os.system(f'pip install pycocotools==2.0.0 mmdet mmcv-full==1.5.0 -f https://download.openmmlab.com/mmcv/dist/{cuda_ver}/torch1.10.0/index.html --no-cache-dir')
|
10 |
+
# os.system('wget -nv -c https://download.openmmlab.com/mmocr/data/wildreceipt.tar; mkdir -p data; tar -xf wildreceipt.tar --directory data; rm -f wildreceipt.tar')
|
11 |
+
|
12 |
+
import datetime
|
13 |
+
import gradio as gr
|
14 |
+
import pandas as pd
|
15 |
+
from mmocr.utils.ocr import MMOCR
|
16 |
+
import os
|
17 |
+
|
18 |
+
def inference(img, det, recog):
|
19 |
+
print(datetime.datetime.now(), 'start')
|
20 |
+
# ocr = MMOCR(det='PS_CTW', recog='SAR', kie='SDMGR')
|
21 |
+
# ocr = MMOCR(det=det, recog=recog, kie='SDMGR')
|
22 |
+
if det == 'None':
|
23 |
+
det = None
|
24 |
+
if recog == 'None':
|
25 |
+
recog = None
|
26 |
+
ocr = MMOCR(det=det, recog=recog)
|
27 |
+
print(datetime.datetime.now(), 'start read')
|
28 |
+
results = ocr.readtext(img.name, details=True, output='output')
|
29 |
+
result_file = 'output/out_{}.png'.format(os.path.splitext(os.path.basename(img.name))[0])
|
30 |
+
print(datetime.datetime.now(), results)
|
31 |
+
# return result_file, pd.DataFrame(results[0]['result']).iloc[: , 2:]
|
32 |
+
return result_file, results
|
33 |
+
|
34 |
+
description = 'Gradio demo for MMOCR. MMOCR is an open-source toolbox based on PyTorch and mmdetection for text detection, text recognition, and the corresponding downstream tasks including key information extraction. To use it, simply upload your image or click one of the examples to load them. Read more at the links below.'
|
35 |
+
article = "<p style='text-align: center'><a href='https://mmocr.readthedocs.io/en/latest/'>MMOCR is an open-source toolbox based on PyTorch and mmdetection for text detection, text recognition, and the corresponding downstream tasks including key information extraction.</a> | <a href='https://github.com/open-mmlab/mmocr'>Github Repo</a></p>"
|
36 |
+
|
37 |
+
|
38 |
+
examples = []
|
39 |
+
path = './images'
|
40 |
+
|
41 |
+
files = os.listdir(path)
|
42 |
+
files.sort()
|
43 |
+
for f in files:
|
44 |
+
file = os.path.join(path, f)
|
45 |
+
if os.path.isfile(file):
|
46 |
+
examples.append([file, 'PS_CTW', 'SAR'])
|
47 |
+
|
48 |
+
det = gr.inputs.Dropdown(choices=[
|
49 |
+
'DB_r18',
|
50 |
+
'DB_r50',
|
51 |
+
'DBPP_r50',
|
52 |
+
'DRRG',
|
53 |
+
'FCE_IC15',
|
54 |
+
'FCE_CTW_DCNv2',
|
55 |
+
'MaskRCNN_CTW',
|
56 |
+
'MaskRCNN_IC15',
|
57 |
+
'MaskRCNN_IC17',
|
58 |
+
'PANet_CTW',
|
59 |
+
'PANet_IC15',
|
60 |
+
'PS_CTW',
|
61 |
+
'PS_IC15',
|
62 |
+
'TextSnake',
|
63 |
+
'None'
|
64 |
+
], type="value", default='PS_CTW', label='det')
|
65 |
+
|
66 |
+
recog = gr.inputs.Dropdown(choices=[
|
67 |
+
'CRNN',
|
68 |
+
'SAR',
|
69 |
+
'SAR_CN',
|
70 |
+
'NRTR_1/16-1/8',
|
71 |
+
'NRTR_1/8-1/4',
|
72 |
+
'RobustScanner',
|
73 |
+
'SATRN',
|
74 |
+
'SATRN_sm',
|
75 |
+
'ABINet',
|
76 |
+
'ABINet_Vision',
|
77 |
+
'SEG',
|
78 |
+
'CRNN_TPS',
|
79 |
+
'MASTER',
|
80 |
+
'None'
|
81 |
+
], type="value", default='SAR', label='recog')
|
82 |
+
|
83 |
+
gr.Interface(inference,
|
84 |
+
[gr.inputs.Image(type='file', label='Input'), det, recog ],
|
85 |
+
# [gr.outputs.Image(type='pil', label='Output'), gr.outputs.Dataframe(headers=['text', 'text_score', 'label', 'label_score'])],
|
86 |
+
[gr.outputs.Image(type='pil', label='Output'), gr.outputs.Textbox(type='str', label='Prediction')],
|
87 |
+
title='MMOCR',
|
88 |
+
description=description,
|
89 |
+
article=article,
|
90 |
+
examples=examples,
|
91 |
+
css=".output_image, .input_image {height: 40rem !important; width: 100% !important;}",
|
92 |
+
enable_queue=True
|
93 |
+
).launch(debug=True, server_name='0.0.0.0', server_port=7860)
|
images/img_10.jpg
ADDED
images/img_11.jpg
ADDED
images/img_12.jpg
ADDED
images/img_195.jpg
ADDED
packages.txt
ADDED
File without changes
|
requirements.txt
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
--find-links https://download.pytorch.org/whl/torch_stable.html
|
2 |
+
torch==1.12.0+cpu
|
3 |
+
torchvision
|
4 |
+
--find-links https://download.openmmlab.com/mmcv/dist/cpu/torch1.12.0/index.html
|
5 |
+
mmcv-full==1.6.0
|
6 |
+
mmdet==2.25.0
|
7 |
+
gradio
|
8 |
+
git+https://github.com/xianbaoqian/mmocr.git
|