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 DOCX processing by refining image handling and improving logging for inference timing
myhloliad175df3d216
diff --git a/demo/demo.py b/demo/demo.pyindex 02668f17..4926d6b0 100644--- a/demo/demo.py+++ b/demo/demo.py@@ -218,7 +218,7 @@ def _process_output(make_func = pipeline_union_makeelif process_mode == "vlm":make_func = vlm_union_make- elif process_mode == "office":+ elif process_mode in office_suffixes:make_func = office_union_makeelse:raise Exception(f"Unknown process_mode: {process_mode}")diff --git a/mineru/backend/office/docx_analyze.py b/mineru/backend/office/docx_analyze.pyindex 3a4a1ee9..d405b2e6 100644--- a/mineru/backend/office/docx_analyze.py+++ b/mineru/backend/office/docx_analyze.py@@ -17,12 +17,13 @@ def office_docx_analyze(results = convert_binary(file_stream)infer_time = round(time.time() - infer_start, 2)- logger.debug(f"infer finished, cost: {infer_time}, speed: {round(len(results) / infer_time, 3)} page/s")+ safe_time = max(infer_time, 0.01)+ logger.debug(f"infer finished, cost: {infer_time}, speed: {round(len(results) / safe_time, 3)} page/s")# middle_json = result_to_middle_json(# results,# image_writer,# )- middle_json= []+ middle_json= {"pdf_info": results}return middle_json, results\ No newline at end of filediff --git a/mineru/model/docx/docx_converter.py b/mineru/model/docx/docx_converter.pyindex 2439a86f..237ba2b6 100644--- a/mineru/model/docx/docx_converter.py+++ b/mineru/model/docx/docx_converter.py@@ -5,7 +5,7 @@ from pathlib import Pathfrom typing import BinaryIO, Optional, Union, Any, Finalimport logging-from PIL import Image+from PIL import Image, WmfImagePluginfrom loguru import loggerfrom docx import Documentfrom docx.oxml.xmlchemy import BaseOxmlElement@@ -466,7 +466,14 @@ class DocxConverter:else:image_bytes = BytesIO(image_data)pil_image = Image.open(image_bytes)- img_base64 = image_to_b64str(pil_image)+ if isinstance(pil_image, WmfImagePlugin.WmfStubImageFile):+ logger.warning(f"Skipping WMF image, size: {pil_image.size}")+ placeholder = Image.new('RGB', pil_image.size, (240, 240, 240))+ img_base64 = image_to_b64str(placeholder)+ else:+ if pil_image.mode != "RGB":+ pil_image = pil_image.convert("RGB")+ img_base64 = image_to_b64str(pil_image)image_block = {"type": BlockType.IMAGE,"bbox": [0, 0, 0, 0],