Spaces:
Runtime error
Runtime error
Commit
·
a8cf8ca
1
Parent(s):
c9da7b7
Update app.py
Browse files
app.py
CHANGED
@@ -6,22 +6,31 @@ from paddleocr import PPStructure,save_structure_res
|
|
6 |
from paddleocr.ppstructure.recovery.recovery_to_doc import sorted_layout_boxes, convert_info_docx
|
7 |
|
8 |
# Chinese image
|
9 |
-
table_engine = PPStructure(recovery=True)
|
10 |
|
11 |
# English image
|
12 |
# table_engine = PPStructure(recovery=True, lang='en')
|
13 |
|
14 |
examples = ['0.png']
|
15 |
|
16 |
-
def find_layout(image):
|
17 |
save_folder = './output'
|
18 |
# img = cv2.imread(image)
|
19 |
img = np.array(image)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
result = table_engine(img)
|
21 |
save_structure_res(result, save_folder, os.path.basename("result").split('.')[0])
|
22 |
|
23 |
-
|
24 |
-
|
|
|
25 |
|
26 |
final_text = []
|
27 |
for line in result:
|
@@ -31,7 +40,15 @@ def find_layout(image):
|
|
31 |
|
32 |
# convert_info_docx(img, res, save_folder, os.path.basename("result").split('.')[0])
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
iface = gr.Interface(fn=find_layout, inputs=[
|
|
|
|
|
|
|
37 |
iface.launch()
|
|
|
6 |
from paddleocr.ppstructure.recovery.recovery_to_doc import sorted_layout_boxes, convert_info_docx
|
7 |
|
8 |
# Chinese image
|
9 |
+
# table_engine = PPStructure(recovery=True)
|
10 |
|
11 |
# English image
|
12 |
# table_engine = PPStructure(recovery=True, lang='en')
|
13 |
|
14 |
examples = ['0.png']
|
15 |
|
16 |
+
def find_layout(image, mode):
|
17 |
save_folder = './output'
|
18 |
# img = cv2.imread(image)
|
19 |
img = np.array(image)
|
20 |
+
|
21 |
+
if mode=="LayoutAnalysis":
|
22 |
+
table_engine = PPStructure(table=False, ocr=False, show_log=True)
|
23 |
+
elif mode=="TableRecognition":
|
24 |
+
table_engine = PPStructure(layout=False, show_log=True)
|
25 |
+
elif mode=="LayoutReccovery":
|
26 |
+
table_engine = PPStructure(recovery=True)
|
27 |
+
|
28 |
result = table_engine(img)
|
29 |
save_structure_res(result, save_folder, os.path.basename("result").split('.')[0])
|
30 |
|
31 |
+
if mode=="LayoutReccovery":
|
32 |
+
h, w, _ = img.shape
|
33 |
+
res = sorted_layout_boxes(result, w)
|
34 |
|
35 |
final_text = []
|
36 |
for line in result:
|
|
|
40 |
|
41 |
# convert_info_docx(img, res, save_folder, os.path.basename("result").split('.')[0])
|
42 |
|
43 |
+
image = Image.open(img).convert('RGB')
|
44 |
+
im_show = draw_structure_result(image, result)
|
45 |
+
im_show = Image.fromarray(im_show)
|
46 |
+
im_show.save('result.jpg')
|
47 |
+
|
48 |
+
return final_text, im_show
|
49 |
|
50 |
+
iface = gr.Interface(fn=find_layout, inputs=[
|
51 |
+
gr.Image(type="pil"),
|
52 |
+
gr.CheckboxGroup(["LayoutAnalysis", "TableRecognition", "LayoutRecovery"], label="mode"),
|
53 |
+
], outputs=["text", "image"], examples=examples)
|
54 |
iface.launch()
|