import os import cv2 import numpy as np from ppstructure.table.predict_table import TableSystem from ppstructure.utility import init_args from PIL import Image from magic_pdf.config.constants import * # noqa: F403 class TableMasterPaddleModel(object): """This class is responsible for converting image of table into HTML format using a pre-trained model. Attributes: - table_sys: An instance of TableSystem initialized with parsed arguments. Methods: - __init__(config): Initializes the model with configuration parameters. - img2html(image): Converts a PIL Image or NumPy array to HTML string. - parse_args(**kwargs): Parses configuration arguments. """ def __init__(self, config): """ Parameters: - config (dict): Configuration dictionary containing model_dir and device. """ args = self.parse_args(**config) self.table_sys = TableSystem(args) def img2html(self, image): """ Parameters: - image (PIL.Image or np.ndarray): The image of the table to be converted. Return: - HTML (str): A string representing the HTML structure with content of the table. """ if isinstance(image, Image.Image): image = np.asarray(image) image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) pred_res, _ = self.table_sys(image) pred_html = pred_res['html'] # res = '