Danieldu
commited on
Commit
•
5e7197d
1
Parent(s):
17e862b
update requirement
Browse files- app.py +5 -15
- paddleocr.py +5 -4
- ppocr/postprocess/picodet_postprocess.py +1 -0
- ppstructure/utility.py +2 -2
- requirements.txt +5 -3
- ser_clinical/inference.pdiparams +0 -3
- ser_clinical/inference.pdiparams.info +0 -3
- ser_clinical/inference.pdmodel +0 -3
- test.json +0 -1
- tools/__pycache__/__init__.cpython-310.pyc +0 -0
app.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import os, io
|
2 |
from paddleocr import PaddleOCR, draw_ocr,PPStructure
|
|
|
3 |
from PIL import Image, ImageDraw
|
4 |
import gradio as gr
|
5 |
|
@@ -38,21 +39,10 @@ def inference__ppstructure(img_path):
|
|
38 |
ser_dict_path='ppocr/utils/dict/kie/clinical_class_list.txt'
|
39 |
)
|
40 |
|
41 |
-
result = ppsutructure.__call__(img_path)
|
42 |
-
|
43 |
-
for
|
44 |
-
|
45 |
-
for line in res:
|
46 |
-
print(line)
|
47 |
-
|
48 |
-
result = result[0]
|
49 |
-
image = Image.open(img_path).convert('RGB')
|
50 |
-
boxes = [line[0] for line in result]
|
51 |
-
txts = [line[1][0] if line[1] else '' for line in result] # 確保在無文字時 txts 還是個空字串
|
52 |
-
scores = [line[1][1] for line in result]
|
53 |
-
im_show_pil = draw_ocr(image, boxes, txts, scores, font_path="./simfang.ttf")
|
54 |
-
|
55 |
-
return im_show_pil, "\n".join(txts)
|
56 |
|
57 |
|
58 |
gr.Interface(
|
|
|
1 |
import os, io
|
2 |
from paddleocr import PaddleOCR, draw_ocr,PPStructure
|
3 |
+
from ppocr.utils.visual import draw_ser_results
|
4 |
from PIL import Image, ImageDraw
|
5 |
import gradio as gr
|
6 |
|
|
|
39 |
ser_dict_path='ppocr/utils/dict/kie/clinical_class_list.txt'
|
40 |
)
|
41 |
|
42 |
+
result,res2 = ppsutructure.__call__(img_path)
|
43 |
+
image = draw_ser_results(img_path,result,font_path='./simfang.ttf')
|
44 |
+
result = [''.join(f"{element['pred']}:{element['transcription']}") for element in result if element['pred']!='O']
|
45 |
+
return image, "\n".join(result)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
|
48 |
gr.Interface(
|
paddleocr.py
CHANGED
@@ -289,7 +289,7 @@ MODEL_URLS = {
|
|
289 |
'kie': {
|
290 |
'en': {
|
291 |
'url':
|
292 |
-
'https://huggingface.co/spaces/CallMeMrFern/ocr/ppstructure/models/kie/ser_clinical.tar',
|
293 |
'dict_path':
|
294 |
'ppocr/utils/dict/kie/clinical_class_list.txt'
|
295 |
},
|
@@ -571,7 +571,7 @@ class PPStructure(StructureSystem):
|
|
571 |
assert params.structure_version in SUPPORT_STRUCTURE_MODEL_VERSION, "structure_version must in {}, but get {}".format(
|
572 |
SUPPORT_STRUCTURE_MODEL_VERSION, params.structure_version)
|
573 |
params.use_gpu = check_gpu(params.use_gpu)
|
574 |
-
params.mode = '
|
575 |
|
576 |
if not params.show_log:
|
577 |
logger.setLevel(logging.INFO)
|
@@ -634,13 +634,14 @@ class PPStructure(StructureSystem):
|
|
634 |
params.ser_dict_path = str(
|
635 |
Path(__file__).parent / ser_model_config['dict_path'])
|
636 |
logger.debug(params)
|
|
|
637 |
super().__init__(params)
|
638 |
|
639 |
def __call__(self, img, return_ocr_result_in_table=False, img_idx=0):
|
640 |
img = check_img(img)
|
641 |
-
res,
|
642 |
img, return_ocr_result_in_table, img_idx=img_idx)
|
643 |
-
return res
|
644 |
|
645 |
|
646 |
def main():
|
|
|
289 |
'kie': {
|
290 |
'en': {
|
291 |
'url':
|
292 |
+
'https://huggingface.co/spaces/CallMeMrFern/ocr/resolve/main/ppstructure/models/kie/ser_clinical.tar',
|
293 |
'dict_path':
|
294 |
'ppocr/utils/dict/kie/clinical_class_list.txt'
|
295 |
},
|
|
|
571 |
assert params.structure_version in SUPPORT_STRUCTURE_MODEL_VERSION, "structure_version must in {}, but get {}".format(
|
572 |
SUPPORT_STRUCTURE_MODEL_VERSION, params.structure_version)
|
573 |
params.use_gpu = check_gpu(params.use_gpu)
|
574 |
+
params.mode = 'kie'
|
575 |
|
576 |
if not params.show_log:
|
577 |
logger.setLevel(logging.INFO)
|
|
|
634 |
params.ser_dict_path = str(
|
635 |
Path(__file__).parent / ser_model_config['dict_path'])
|
636 |
logger.debug(params)
|
637 |
+
print(params)
|
638 |
super().__init__(params)
|
639 |
|
640 |
def __call__(self, img, return_ocr_result_in_table=False, img_idx=0):
|
641 |
img = check_img(img)
|
642 |
+
res, res2 = super().__call__(
|
643 |
img, return_ocr_result_in_table, img_idx=img_idx)
|
644 |
+
return res, res2
|
645 |
|
646 |
|
647 |
def main():
|
ppocr/postprocess/picodet_postprocess.py
CHANGED
@@ -102,6 +102,7 @@ class PicoDetPostProcess(object):
|
|
102 |
self.keep_top_k = keep_top_k
|
103 |
|
104 |
def load_layout_dict(self, layout_dict_path):
|
|
|
105 |
with open(layout_dict_path, 'r', encoding='utf-8') as fp:
|
106 |
labels = fp.readlines()
|
107 |
return [label.strip('\n') for label in labels]
|
|
|
102 |
self.keep_top_k = keep_top_k
|
103 |
|
104 |
def load_layout_dict(self, layout_dict_path):
|
105 |
+
print(layout_dict_path)
|
106 |
with open(layout_dict_path, 'r', encoding='utf-8') as fp:
|
107 |
labels = fp.readlines()
|
108 |
return [label.strip('\n') for label in labels]
|
ppstructure/utility.py
CHANGED
@@ -75,12 +75,12 @@ def init_args():
|
|
75 |
parser.add_argument(
|
76 |
"--layout",
|
77 |
type=str2bool,
|
78 |
-
default=
|
79 |
help='Whether to enable layout analysis')
|
80 |
parser.add_argument(
|
81 |
"--table",
|
82 |
type=str2bool,
|
83 |
-
default=
|
84 |
help='In the forward, whether the table area uses table recognition')
|
85 |
parser.add_argument(
|
86 |
"--ocr",
|
|
|
75 |
parser.add_argument(
|
76 |
"--layout",
|
77 |
type=str2bool,
|
78 |
+
default=False,
|
79 |
help='Whether to enable layout analysis')
|
80 |
parser.add_argument(
|
81 |
"--table",
|
82 |
type=str2bool,
|
83 |
+
default=False,
|
84 |
help='In the forward, whether the table area uses table recognition')
|
85 |
parser.add_argument(
|
86 |
"--ocr",
|
requirements.txt
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
-
paddlepaddle==2.4.2 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/noavx/stable.html --no-index
|
|
|
2 |
paddleocr>=2.6
|
3 |
-
Pillow
|
4 |
Gradio
|
5 |
Polygon3 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
6 |
-
lanms-neo==1.0.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
|
|
|
1 |
+
# paddlepaddle==2.4.2 -f https://www.paddlepaddle.org.cn/whl/linux/mkl/noavx/stable.html --no-index
|
2 |
+
paddlepaddle==2.5.2
|
3 |
paddleocr>=2.6
|
4 |
+
Pillow==9.5.0
|
5 |
Gradio
|
6 |
Polygon3 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
7 |
+
lanms-neo==1.0.2 -i https://pypi.tuna.tsinghua.edu.cn/simple
|
8 |
+
paddlenlp==2.5.2
|
ser_clinical/inference.pdiparams
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:04651c7fd3c8c70109c0cebfc9469341b5d53bd04931256faee571a5fa41aac4
|
3 |
-
size 1112005019
|
|
|
|
|
|
|
|
ser_clinical/inference.pdiparams.info
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:6f7c104c03a2783f214b202d1295202b272fed7f79de5ddad00843b033c764fd
|
3 |
-
size 23316
|
|
|
|
|
|
|
|
ser_clinical/inference.pdmodel
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:555c2329497dc20fa71caf81c386122e376501660571ab13e5e3e0ba483e5304
|
3 |
-
size 1068499
|
|
|
|
|
|
|
|
test.json
DELETED
@@ -1 +0,0 @@
|
|
1 |
-
{"table": {"en": {"url": "https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/en_ppstructure_mobile_v2.0_SLANet_infer.tar", "dict_path": "ppocr/utils/dict/table_structure_dict.txt"}, "ch": {"url": "https://paddleocr.bj.bcebos.com/ppstructure/models/slanet/ch_ppstructure_mobile_v2.0_SLANet_infer.tar", "dict_path": "ppocr/utils/dict/table_structure_dict_ch.txt"}}, "layout": {"en": {"url": "https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_fgd_layout_infer.tar", "dict_path": "ppocr/utils/dict/layout_dict/layout_publaynet_dict.txt"}, "ch": {"url": "https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_fgd_layout_cdla_infer.tar", "dict_path": "ppocr/utils/dict/layout_dict/layout_cdla_dict.txt"}}, "kie": {"en": {"url": "https://paddleocr.bj.bcebos.com/ppstructure/models/layout/picodet_lcnet_x1_0_fgd_layout_infer.tar", "dict_path": "ppocr/utils/dict/kie/clinical_class_list.txt"}, "ch": {"url": "https://huggingface.co/spaces/CallMeMrFern/ocr/ppstructure/models/kie/ser_clinical.tar", "dict_path": "ppocr/utils/dict/kie/clinical_class_list.txt"}}}
|
|
|
|
tools/__pycache__/__init__.cpython-310.pyc
DELETED
Binary file (129 Bytes)
|
|