Spaces:
Runtime error
Runtime error
upadate model
Browse files11236 unmodified lines1011121314151622 unmodified lines394041424342434445464746 unmodified lines9495969697989910015 unmodified lines11611711811912012112212312412512612712812913015 unmodified lines14614714814915015115215315415515615715815916016116216316416516616716816917017117217317417514317617717817918018118218318415118518618718818919019119219319419519613 unmodified lines2102112121752132142152161 unmodified line218219220183221import threadingimport time
import cv26 unmodified linesfrom wired_table_rec import WiredTableRecognition
from utils import plot_rec_box, LoadImage, format_html, box_4_2_poly_to_box_4_1
img_loader = LoadImage()table_rec_path = "models/table_rec/ch_ppstructure_mobile_v2_SLANet.onnx"det_model_dir = {22 unmodified lines "images/wired4.jpg", "images/lineless2.png", "images/wired5.jpg", "images/lineless3.jpg", "images/wired6.jpg", "images/lineless4.jpg", "images/wired7.jpg", "images/wired9.jpg",]rapid_table_engine = RapidTable(model_path=table_rec_path)SLANet_plus_table_Engine = RapidTable()46 unmodified lines return lineless_table_engine, "lineless_table"
def process_image(img, table_engine_type, det_model, rec_model):def process_image(img, table_engine_type, det_model, rec_model, small_box_cut_enhance): img = img_loader(img) start = time.time() table_engine, talbe_type = select_table_model(img, table_engine_type, det_model, rec_model)15 unmodified lines polygons = [[polygon[0], polygon[1], polygon[4], polygon[5]] for polygon in polygons] elif isinstance(table_engine, (WiredTableRecognition, LinelessTableRecognition)): html, table_rec_elapse, polygons, _, _ = table_engine(img, ocr_result=ocr_res) if not small_box_cut_enhance: html, table_rec_elapse, polygons, logic_points, ocr_res = table_engine( img, ocr_result=ocr_res, morph_close=False, more_h_lines=False, more_v_lines=False, extend_line=False ) else: html, table_rec_elapse, polygons, logic_points, ocr_res = table_engine( img, ocr_result=ocr_res )
sum_elapse = time.time() - start all_elapse = f"- table_type: {talbe_type}\n table all cost: {sum_elapse:.5f}\n - table rec cost: {table_rec_elapse:.5f}\n - ocr cost: {det_cost + cls_cost + rec_cost:.5f}"15 unmodified lines overflow-x: auto; white-space: nowrap; } .header-links { text-align: center; } .header-links a { display: inline-block; text-align: center; margin-right: 10px; /* 调整间距 */ } """) as demo: gr.HTML( "<h1 style='text-align: center;'><a href='https://github.com/RapidAI/TableStructureRec?tab=readme-ov-file'>TableStructureRec</a></h1>" ) gr.HTML(''' <div class="header-links"> <a href=""><img src="https://img.shields.io/badge/Python->=3.6,<3.12-aff.svg"></a> <a href=""><img src="https://img.shields.io/badge/OS-Linux%2C%20Mac%2C%20Win-pink.svg"></a> <a href="https://pypi.org/project/lineless-table-rec/"><img alt="PyPI" src="https://img.shields.io/pypi/v/lineless-table-rec"></a> <a href="https://pepy.tech/project/lineless-table-rec"><img src="https://static.pepy.tech/personalized-badge/lineless-table-rec?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads%20Lineless"></a> <a href="https://pepy.tech/project/wired-table-rec"><img src="https://static.pepy.tech/personalized-badge/wired-table-rec?period=total&units=abbreviation&left_color=grey&right_color=blue&left_text=Downloads%20Wired"></a> <a href="https://semver.org/"><img alt="SemVer2.0" src="https://img.shields.io/badge/SemVer-2.0-brightgreen"></a> <a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg"></a> <a href="https://github.com/RapidAI/TableStructureRec/blob/c41bbd23898cb27a957ed962b0ffee3c74dfeff1/LICENSE"><img alt="GitHub" src="https://img.shields.io/badge/license-Apache 2.0-blue"></a> </div> ''') with gr.Row(): # 两列布局 with gr.Tab("Options"): with gr.Column(variant="panel", scale=1): # 侧边栏,宽度比例为1 img_input = gr.Image(label="Upload or Select Image", sources="upload", value="images/lineless3.jpg") img_input = gr.Image(label="Upload or Select Image", sources="upload", value="images/lineless3.jpg")
# 示例图片选择器 examples = gr.Examples( examples=example_images, examples_per_page=len(example_images), inputs=img_input, fn=lambda x: x, # 简单返回图片路径 outputs=img_input, cache_examples=True cache_examples=False )
table_engine_type = gr.Dropdown(table_engine_list, label="Select Recognition Table Engine", value=table_engine_list[0]) small_box_cut_enhance = gr.Checkbox( label="Box Cutting Enhancement (Disable to avoid excessive cutting, Enable to reduce missed cutting)", value=True ) det_model = gr.Dropdown(det_models_labels, label="Select OCR Detection Model", value=det_models_labels[0]) rec_model = gr.Dropdown(rec_models_labels, label="Select OCR Recognition Model",13 unmodified lines
run_button.click( fn=process_image, inputs=[img_input, table_engine_type, det_model, rec_model], inputs=[img_input, table_engine_type, det_model, rec_model, small_box_cut_enhance], outputs=[html_output, table_boxes_output, ocr_boxes_output, elapse_text] )
1 unmodified line
if __name__ == '__main__': main() main()app.py+46-8