Transforms complex documents like PDFs and Office docs into LLM-ready markdown/JSON for your Agentic workflows.
Python ai4sciencedocument-analysisdocxextract-datalayout-analysisocrparserpdfpdf-converterpdf-extractor-llmpdf-extractor-pretrainpdf-extractor-ragpdf-parserpptxpythonxlsx
feat: enhance image handling in document processing for charts and tables
myhloli99c0fbb537b6
diff --git a/mineru/backend/office/model_output_to_middle_json.py b/mineru/backend/office/model_output_to_middle_json.pyindex 0a4f4982..a351f4eb 100644--- a/mineru/backend/office/model_output_to_middle_json.py+++ b/mineru/backend/office/model_output_to_middle_json.py@@ -73,9 +73,12 @@ def blocks_to_page_info(page_blocks, image_writer, page_index) -> dict:magic_model = MagicModel(page_blocks)image_blocks = magic_model.get_image_blocks()+ table_blocks = magic_model.get_table_blocks()+ chart_blocks = magic_model.get_chart_blocks()- # Write embedded images to local storage via image_writerif image_writer:++ # Write embedded images to local storage via image_writerfor img_block in image_blocks:for sub_block in img_block.get("blocks", []):if sub_block.get("type") != "image_body":@@ -84,11 +87,7 @@ def blocks_to_page_info(page_blocks, image_writer, page_index) -> dict:for span in line.get("spans", []):_save_span_image_if_needed(span, image_writer, page_index)- table_blocks = magic_model.get_table_blocks()- chart_blocks = magic_model.get_chart_blocks()-- # Replace inline base64 images inside table HTML with local paths- if image_writer:+ # Replace inline base64 images inside table HTML with local pathsfor tbl_block in table_blocks:for sub_block in tbl_block.get("blocks", []):if sub_block.get("type") != "table_body":@@ -103,6 +102,7 @@ def blocks_to_page_info(page_blocks, image_writer, page_index) -> dict:page_index,)+ # Replace inline base64 images inside chart content with local pathsfor chart_block in chart_blocks:for sub_block in chart_block.get("blocks", []):if sub_block.get("type") != "chart_body":@@ -112,20 +112,6 @@ def blocks_to_page_info(page_blocks, image_writer, page_index) -> dict:if span.get("type") != "chart":continue_save_span_image_if_needed(span, image_writer, page_index)- span["content"] = _replace_inline_base64_img_src(- span.get("content", ""),- image_writer,- page_index,- )- else:- for chart_block in chart_blocks:- for sub_block in chart_block.get("blocks", []):- if sub_block.get("type") != "chart_body":- continue- for line in sub_block.get("lines", []):- for span in line.get("spans", []):- if span.get("type") == "chart":- span.setdefault("image_path", "")title_blocks = magic_model.get_title_blocks()discarded_blocks = magic_model.get_discarded_blocks()diff --git a/mineru/backend/office/office_magic_model.py b/mineru/backend/office/office_magic_model.pyindex cd0141a7..ce161f4d 100644--- a/mineru/backend/office/office_magic_model.py+++ b/mineru/backend/office/office_magic_model.py@@ -14,7 +14,7 @@ class MagicModel:blocks = []self.all_spans = []- # 对caption块进行分类,将其分类为image_caption或table_caption+ # 对caption块进行分类,将其分类为image_caption, table_caption, chart_captionpage_blocks = classify_caption_blocks(page_blocks)# 解析每个块@@ -53,7 +53,6 @@ class MagicModel:span = {"type": ContentType.CHART,"content": block_content,- "image_path": block_info.get("image_path", ""),}if block_info.get("image_base64"):span["image_base64"] = block_info["image_base64"]@@ -117,10 +116,7 @@ class MagicModel:self.interline_equation_blocks = []self.text_blocks = []self.title_blocks = []- self.code_blocks = []self.discarded_blocks = []- self.ref_text_blocks = []- self.phonetic_blocks = []self.list_blocks = []self.index_blocks = []for block in blocks:@@ -130,8 +126,6 @@ class MagicModel:self.table_blocks.append(block)elif block["type"] in [BlockType.CHART_BODY, BlockType.CHART_CAPTION]:self.chart_blocks.append(block)- elif block["type"] in [BlockType.CODE_BODY, BlockType.CODE_CAPTION]:- self.code_blocks.append(block)elif block["type"] == BlockType.INTERLINE_EQUATION:self.interline_equation_blocks.append(block)elif block["type"] == BlockType.TEXT: