SWHL commited on
Commit
d3a7100
1 Parent(s): c9ad304

Update files

Browse files
app.py CHANGED
@@ -1,9 +1,44 @@
1
  # -*- encoding: utf-8 -*-
2
  # @Author: SWHL
3
  # @Contact: liekkaskono@163.com
 
 
 
4
  import numpy as np
5
  import streamlit as st
6
  from PIL import Image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
 
9
  if __name__ == '__main__':
@@ -20,16 +55,55 @@ if __name__ == '__main__':
20
 
21
  img_suffix = ["png", "jpg", "jpeg"]
22
 
23
- st.markdown('##### rapid-orientation (文档图像分类) demo')
24
- img_empty = st.empty()
25
- img_file_buffer = st.file_uploader("Upload an image",
26
- type=img_suffix,
27
- label_visibility='hidden')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  if img_file_buffer:
29
  image = Image.open(img_file_buffer)
30
- img_array = np.array(image)
31
- if image:
32
- img_empty.image(image, use_column_width=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
- st.markdown('##### rapid-layout (版面分析) demo')
35
- st.markdown('##### rapid-table (表格还原) demo')
 
1
  # -*- encoding: utf-8 -*-
2
  # @Author: SWHL
3
  # @Contact: liekkaskono@163.com
4
+ import copy
5
+
6
+ import cv2
7
  import numpy as np
8
  import streamlit as st
9
  from PIL import Image
10
+ from rapid_layout import RapidLayout
11
+ from rapid_orientation import RapidOrientation
12
+ from rapid_table import RapidTable
13
+
14
+ orientation_engine = RapidOrientation()
15
+ layout_engine = RapidLayout()
16
+ table_engine = RapidTable()
17
+
18
+
19
+ def vis_layout(img: np.ndarray, layout_res: list) -> None:
20
+ tmp_img = copy.deepcopy(img)
21
+ for v in layout_res:
22
+ bbox = np.round(v['bbox']).astype(np.int32)
23
+ label = v['label']
24
+
25
+ start_point = (bbox[0], bbox[1])
26
+ end_point = (bbox[2], bbox[3])
27
+
28
+ cv2.rectangle(tmp_img, start_point, end_point, (0, 255, 0), 2)
29
+ cv2.putText(tmp_img, label, start_point,
30
+ cv2.FONT_HERSHEY_COMPLEX, 1, (0, 0, 255), 2)
31
+ return tmp_img
32
+
33
+
34
+ def vis_table(table_res) -> str:
35
+ style_res = '''<style>td {border-left: 1px solid;border-bottom:1px solid;}
36
+ table, th {border-top:1px solid;font-size: 10px;
37
+ border-collapse: collapse;border-right: 1px solid;}
38
+ </style>'''
39
+ prefix_table, suffix_table = table_res.split('<body>')
40
+ new_table_res = f'{prefix_table}{style_res}<body>{suffix_table}'
41
+ return new_table_res
42
 
43
 
44
  if __name__ == '__main__':
 
55
 
56
  img_suffix = ["png", "jpg", "jpeg"]
57
 
58
+ st.markdown('##### 文档图像方向分类')
59
+
60
+ img_file_buffer = st.file_uploader("Upload an image", type=img_suffix,
61
+ key='orientation',
62
+ label_visibility='collapsed')
63
+ col1, col2 = st.columns([5, 5])
64
+
65
+ img_empty = col1.empty()
66
+ if img_file_buffer:
67
+ image = Image.open(img_file_buffer)
68
+ img = np.array(image)
69
+ img_empty.image(image, use_column_width=True)
70
+
71
+ img_array = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
72
+ orientation_res, elapse = orientation_engine(img)
73
+
74
+ col2.markdown(f'- 方向分类结果:{orientation_res}° \n - 耗费时间:{elapse:.4f}s')
75
+
76
+ st.markdown('##### 文档图像版面分析')
77
+ img_file_buffer = st.file_uploader("Upload an image", type=img_suffix,
78
+ key='layout',
79
+ label_visibility='collapsed')
80
+ layout_col1, layout_col2 = st.columns([5, 5])
81
+
82
+ img_empty = layout_col1.empty()
83
  if img_file_buffer:
84
  image = Image.open(img_file_buffer)
85
+ img = np.array(image)
86
+ img_empty.image(image, use_column_width=True)
87
+
88
+ img_array = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
89
+ layout_res, _ = layout_engine(img)
90
+ drawed_img = vis_layout(img, layout_res)
91
+ layout_col2.image(drawed_img, use_column_width=True)
92
+
93
+ st.markdown('##### 表格还原')
94
+ img_file_buffer = st.file_uploader("Upload an image", type=img_suffix,
95
+ key='table',
96
+ label_visibility='collapsed')
97
+ table_col1, table_col2 = st.columns([5, 5])
98
+
99
+ img_empty = table_col1.empty()
100
+ if img_file_buffer:
101
+ image = Image.open(img_file_buffer)
102
+ img = np.array(image)
103
+ img_empty.image(image, use_column_width=True)
104
+
105
+ img_array = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
106
+ table_html_str, _ = table_engine(img)
107
 
108
+ table_html_str = vis_table(table_html_str)
109
+ table_col2.markdown(table_html_str, unsafe_allow_html=True)
pages/1_rapid_orientation.py DELETED
@@ -1,46 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # @Author: SWHL
3
- # @Contact: liekkaskono@163.com
4
- import cv2
5
- import numpy as np
6
- import streamlit as st
7
- from PIL import Image
8
- from rapid_orientation import RapidOrientation
9
-
10
- orientation_engine = RapidOrientation()
11
-
12
-
13
- if __name__ == '__main__':
14
- st.markdown("<h1 style='text-align: center;'><a href='https://github.com/RapidAI/RapidStructure/blob/main/docs/README_Orientation.md' style='text-decoration: none'>rapid-orientation</a></h1>", unsafe_allow_html=True)
15
- st.markdown("""
16
- <p align="left">
17
- <a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a>
18
- <a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
19
- <a href="https://pepy.tech/project/rapid-orientation"><img src="https://static.pepy.tech/personalized-badge/rapid-orientation?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=rapid-orientation"></a>
20
- </p>
21
-
22
- #### 简介
23
- - 该部分主要是做含文字图像方向分类模型。模型来源:[PaddleClas 含文字图像方向分类模型](https://github.com/PaddlePaddle/PaddleClas/blob/177e4be74639c0960efeae2c5166d3226c9a02eb/docs/zh_CN/models/PULC/PULC_text_image_orientation.md)
24
-
25
- | 模型类型 | 模型名称 | 模型大小 | 支持种类 |
26
- |:---:|:---:|:---:|:---:|
27
- | 四方向分类 | `rapid_orientation.onnx` | 6.5M | `0 90 180 270`|
28
-
29
- #### 试一下
30
- """, unsafe_allow_html=True)
31
-
32
- img_suffix = ["png", "jpg", "jpeg"]
33
-
34
- img_file_buffer = st.file_uploader("Upload an image", type=img_suffix)
35
- col1, col2 = st.columns([5, 5])
36
-
37
- img_empty = col1.empty()
38
- if img_file_buffer:
39
- image = Image.open(img_file_buffer)
40
- img = np.array(image)
41
- img_empty.image(image, use_column_width=True)
42
-
43
- img_array = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
44
- orientation_res, elapse = orientation_engine(img)
45
-
46
- col2.markdown(f'- 方向分类结果:{orientation_res}° \n - 耗费时间:{elapse:.4f}s')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/2_rapid_layout.py DELETED
@@ -1,35 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # @Author: SWHL
3
- # @Contact: liekkaskono@163.com
4
- import numpy as np
5
- import streamlit as st
6
- from PIL import Image
7
-
8
-
9
- if __name__ == '__main__':
10
- st.markdown("<h1 style='text-align: center;'><a href='https://github.com/RapidAI/RapidStructure' style='text-decoration: none'>Rapid Structure</a></h1>", unsafe_allow_html=True)
11
- st.markdown("""
12
- <p align="left">
13
- <a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a>
14
- <a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
15
- <a href="https://pepy.tech/project/rapid-layout"><img src="https://static.pepy.tech/personalized-badge/rapid-layout?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=rapid-layout"></a>
16
- <a href="https://pepy.tech/project/rapid-orientation"><img src="https://static.pepy.tech/personalized-badge/rapid-orientation?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=rapid-orientation"></a>
17
- <a href="https://pepy.tech/project/rapid-table"><img src="https://static.pepy.tech/personalized-badge/rapid-table?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=rapid-table"></a>
18
- </p>
19
- """, unsafe_allow_html=True)
20
-
21
- img_suffix = ["png", "jpg", "jpeg"]
22
-
23
- st.markdown('##### rapid-orientation (文档图像分类) demo')
24
- img_empty = st.empty()
25
- img_file_buffer = st.file_uploader("Upload an image",
26
- type=img_suffix,
27
- label_visibility='hidden')
28
- if img_file_buffer:
29
- image = Image.open(img_file_buffer)
30
- img_array = np.array(image)
31
- if image:
32
- img_empty.image(image, use_column_width=True)
33
-
34
- st.markdown('##### rapid-layout (版面分析) demo')
35
- st.markdown('##### rapid-table (表格还原) demo')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
pages/3_rapid_table.py DELETED
@@ -1,35 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # @Author: SWHL
3
- # @Contact: liekkaskono@163.com
4
- import numpy as np
5
- import streamlit as st
6
- from PIL import Image
7
-
8
-
9
- if __name__ == '__main__':
10
- st.markdown("<h1 style='text-align: center;'><a href='https://github.com/RapidAI/RapidStructure' style='text-decoration: none'>Rapid Structure</a></h1>", unsafe_allow_html=True)
11
- st.markdown("""
12
- <p align="left">
13
- <a href=""><img src="https://img.shields.io/badge/Python->=3.7,<=3.10-aff.svg"></a>
14
- <a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Win%2C%20Mac-pink.svg"></a>
15
- <a href="https://pepy.tech/project/rapid-layout"><img src="https://static.pepy.tech/personalized-badge/rapid-layout?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=rapid-layout"></a>
16
- <a href="https://pepy.tech/project/rapid-orientation"><img src="https://static.pepy.tech/personalized-badge/rapid-orientation?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=rapid-orientation"></a>
17
- <a href="https://pepy.tech/project/rapid-table"><img src="https://static.pepy.tech/personalized-badge/rapid-table?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=rapid-table"></a>
18
- </p>
19
- """, unsafe_allow_html=True)
20
-
21
- img_suffix = ["png", "jpg", "jpeg"]
22
-
23
- st.markdown('##### rapid-orientation (文档图像分类) demo')
24
- img_empty = st.empty()
25
- img_file_buffer = st.file_uploader("Upload an image",
26
- type=img_suffix,
27
- label_visibility='hidden')
28
- if img_file_buffer:
29
- image = Image.open(img_file_buffer)
30
- img_array = np.array(image)
31
- if image:
32
- img_empty.image(image, use_column_width=True)
33
-
34
- st.markdown('##### rapid-layout (版面分析) demo')
35
- st.markdown('##### rapid-table (表格还原) demo')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
requirements.txt CHANGED
@@ -3,4 +3,5 @@ rapid-layout
3
  rapid-table
4
  rapid-orientation
5
  Pillow
6
- numpy
 
 
3
  rapid-table
4
  rapid-orientation
5
  Pillow
6
+ numpy
7
+ opencv-python