-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat<table model>: add tablemaster with paddleocr to detect and recog…
…nize table (#493) * Update cla.yml * Update bug_report.yml * Update README_zh-CN.md (#404) correct FAQ url * Update README_zh-CN.md (#404) (#409) (#410) correct FAQ url Co-authored-by: sfk <[email protected]> * Update FAQ_zh_cn.md add new issue * Update FAQ_en_us.md * Update README_Windows_CUDA_Acceleration_zh_CN.md * Update README_zh-CN.md * @Thepathakarpit has signed the CLA in #418 * Update cla.yml * feat: add tablemaster_paddle (#463) * Update README_zh-CN.md (#404) (#409) correct FAQ url Co-authored-by: sfk <[email protected]> * add dockerfile (#189) Co-authored-by: drunkpig <[email protected]> * Update cla.yml * Update cla.yml --------- Co-authored-by: drunkpig <[email protected]> Co-authored-by: sfk <[email protected]> Co-authored-by: Aoyang Fang <[email protected]> Co-authored-by: Xiaomeng Zhao <[email protected]> * <fix>(para_split_v2): index out of range issue of span_text first char (#396) Co-authored-by: liukaiwen <[email protected]> * @Matthijz98 has signed the CLA in #467 * Create download_models.py * Create requirements-docker.txt * feat<table model>: add tablemaster with paddleocr to detect and recognize table * @strongerfly has signed the CLA in #487 * feat<table model>: add tablemaster with paddleocr to detect and recognize table * feat<table model>: add tablemaster with paddleocr to detect and recognize table * feat<table model>: add tablemaster with paddleocr to detect and recognize table * feat<table model>: add tablemaster with paddleocr to detect and recognize table --------- Co-authored-by: Xiaomeng Zhao <[email protected]> Co-authored-by: sfk <[email protected]> Co-authored-by: drunkpig <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Aoyang Fang <[email protected]> Co-authored-by: liukaiwen <[email protected]>
- Loading branch information
1 parent
f4316f0
commit cd64b81
Showing
22 changed files
with
306 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# use modelscope sdk download models | ||
from modelscope import snapshot_download | ||
model_dir = snapshot_download('wanderkid/PDF-Extract-Kit') | ||
print(f"model dir is: {model_dir}/models") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
from paddleocr.ppstructure.table.predict_table import TableSystem | ||
from paddleocr.ppstructure.utility import init_args | ||
from magic_pdf.libs.Constants import * | ||
import os | ||
from PIL import Image | ||
import numpy as np | ||
|
||
|
||
class ppTableModel(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.array(image) | ||
pred_res, _ = self.table_sys(image) | ||
pred_html = pred_res["html"] | ||
res = '<td><table border="1">' + pred_html.replace("<html><body><table>", "").replace("</table></body></html>", | ||
"") + "</table></td>\n" | ||
return res | ||
|
||
def parse_args(self, **kwargs): | ||
parser = init_args() | ||
model_dir = kwargs.get("model_dir") | ||
table_model_dir = os.path.join(model_dir, TABLE_MASTER_DIR) | ||
table_char_dict_path = os.path.join(model_dir, TABLE_MASTER_DICT) | ||
det_model_dir = os.path.join(model_dir, DETECT_MODEL_DIR) | ||
rec_model_dir = os.path.join(model_dir, REC_MODEL_DIR) | ||
rec_char_dict_path = os.path.join(model_dir, REC_CHAR_DICT) | ||
device = kwargs.get("device", "cpu") | ||
use_gpu = True if device == "cuda" else False | ||
config = { | ||
"use_gpu": use_gpu, | ||
"table_max_len": kwargs.get("table_max_len", TABLE_MAX_LEN), | ||
"table_algorithm": TABLE_MASTER, | ||
"table_model_dir": table_model_dir, | ||
"table_char_dict_path": table_char_dict_path, | ||
"det_model_dir": det_model_dir, | ||
"rec_model_dir": rec_model_dir, | ||
"rec_char_dict_path": rec_char_dict_path, | ||
} | ||
parser.set_defaults(**config) | ||
return parser.parse_args([]) |
Oops, something went wrong.