import gradio as gr import os import cv2 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') def find_layout(name): save_folder = './output' img_path = '0.png' img = cv2.imread(img_path) result = table_engine(img) save_structure_res(result, save_folder, os.path.basename(img_path).split('.')[0]) final_text = "" for line in result: line.pop('img') print(line) final_text += "\n" + line h, w, _ = img.shape res = sorted_layout_boxes(result, w) convert_info_docx(img, res, save_folder, os.path.basename(img_path).split('.')[0]) return final_text iface = gr.Interface(fn=find_layout, inputs="text", outputs="text") iface.launch()