File size: 1,041 Bytes
efe1e83
 
 
e88e4ee
efe1e83
 
 
918e972
efe1e83
 
5105295
efe1e83
 
73a2704
24da6e7
73a2704
513b66c
c7f2632
e88e4ee
 
6afb5fb
c7f2632
efe1e83
7bc6ea7
6afb5fb
 
 
0f7947c
7bc6ea7
c7f2632
 
 
efe1e83
0f7947c
efe1e83
24da6e7
efe1e83
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gradio as gr
import os
import cv2
import numpy as np
from paddleocr import PPStructure,save_structure_res
from paddleocr.ppstructure.recovery.recovery_to_doc import sorted_layout_boxes, convert_info_docx


# Chinese image
table_engine = PPStructure(recovery=True)

# English image
# table_engine = PPStructure(recovery=True, lang='en')

examples = ['0.png']

def find_layout(image):
    # save_folder = './output'
    # img = cv2.imread(image)
    img = np.array(image)
    result = table_engine(img)
    # save_structure_res(result, save_folder, os.path.basename("result").split('.')[0])

    final_text = []
    for line in result:
        line.pop('img')
        print(line)
        final_text.append(line["res"][0]["text"])

    # h, w, _ = img.shape
    # res = sorted_layout_boxes(result, w)
    # convert_info_docx(img, res, save_folder, os.path.basename("result").split('.')[0])

    return str(final_text)

iface = gr.Interface(fn=find_layout, inputs=[gr.Image(type="pil")], outputs="text", examples=examples)
iface.launch()