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: 添加xlsx_analyze和pptx_analyze
Sidney233194ff842559e
diff --git a/mineru/backend/office/pptx_analyze.py b/mineru/backend/office/pptx_analyze.pynew file mode 100644index 00000000..0930850c--- /dev/null+++ b/mineru/backend/office/pptx_analyze.py@@ -0,0 +1,71 @@+# Copyright (c) Opendatalab. All rights reserved.+import time+from io import BytesIO++from loguru import logger+from mineru.backend.office.model_output_to_middle_json import result_to_middle_json++from mineru.model.pptx.main import convert_binary+++def office_pptx_analyze(file_bytes, image_writer=None):+ infer_start = time.time()++ file_stream = BytesIO(file_bytes)+ results = convert_binary(file_stream)++ infer_time = round(time.time() - infer_start, 2)+ 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,+ )++ return middle_json, results+++if __name__ == "__main__":+ # Resolve a default docx file relative to this script so the example+ # works no matter what the current working directory is when the+ # module is executed. Allow the user to override the path via a+ # command-line argument for even greater flexibility.+ from pathlib import Path+ import argparse++ script_root = Path(__file__).resolve().parent.parent.parent.parent+ default_pptx = script_root / "demo" / "pptx" / "powerpoint_sample.pptx"++ parser = argparse.ArgumentParser(+ description="Quick demo runner for office_pptx_analyze"+ )+ parser.add_argument(+ "pptx",+ nargs="?",+ default=str(default_pptx),+ help="path to docx file (defaults to demo/docx/demo1.docx relative to project root)",+ )+ parser.add_argument(+ "--output-images",+ help="directory to write image outputs",+ default="./output_images",+ )+ args = parser.parse_args()++ pptx_path = Path(args.pptx)+ from mineru.data.data_reader_writer import FileBasedDataWriter++ with open(pptx_path, "rb") as f:+ file_bytes = f.read()+ image_writer = FileBasedDataWriter(args.output_images)+ middle_json, results = office_pptx_analyze(+ file_bytes,+ image_writer=image_writer,+ )++ import json++ logger.info(json.dumps(middle_json, indent=2, ensure_ascii=False))diff --git a/mineru/backend/office/xlsx_analyze.py b/mineru/backend/office/xlsx_analyze.pynew file mode 100644index 00000000..84d242c9--- /dev/null+++ b/mineru/backend/office/xlsx_analyze.py@@ -0,0 +1,71 @@+# Copyright (c) Opendatalab. All rights reserved.+import time+from io import BytesIO++from loguru import logger+from mineru.backend.office.model_output_to_middle_json import result_to_middle_json++from mineru.model.xlsx.main import convert_binary+++def office_xlsx_analyze(file_bytes, image_writer=None):+ infer_start = time.time()++ file_stream = BytesIO(file_bytes)+ results = convert_binary(file_stream)++ infer_time = round(time.time() - infer_start, 2)+ 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,+ )++ return middle_json, results+++if __name__ == "__main__":+ # Resolve a default docx file relative to this script so the example+ # works no matter what the current working directory is when the+ # module is executed. Allow the user to override the path via a+ # command-line argument for even greater flexibility.+ from pathlib import Path+ import argparse++ script_root = Path(__file__).resolve().parent.parent.parent.parent+ default_xlsx = script_root / "demo" / "xlsx" / "xlsx_01.xlsx"++ parser = argparse.ArgumentParser(+ description="Quick demo runner for office_xlsx_analyze"+ )+ parser.add_argument(+ "xlsx",+ nargs="?",+ default=str(default_xlsx),+ help="path to docx file (defaults to demo/docx/demo1.docx relative to project root)",+ )+ parser.add_argument(+ "--output-images",+ help="directory to write image outputs",+ default="./output_images",+ )+ args = parser.parse_args()++ xlsx_path = Path(args.xlsx)+ from mineru.data.data_reader_writer import FileBasedDataWriter++ with open(xlsx_path, "rb") as f:+ file_bytes = f.read()+ image_writer = FileBasedDataWriter(args.output_images)+ middle_json, results = office_xlsx_analyze(+ file_bytes,+ image_writer=image_writer,+ )++ import json++ logger.info(json.dumps(middle_json, indent=2, ensure_ascii=False))diff --git a/mineru/model/pptx/pptx_converter.py b/mineru/model/pptx/pptx_converter.pyindex 8175811e..90d0d7dc 100644--- a/mineru/model/pptx/pptx_converter.py+++ b/mineru/model/pptx/pptx_converter.py@@ -25,6 +25,7 @@ class PptxConverter:self.pages = []self.cur_page = []self.list_block_stack: list = [] # 列表块堆栈+ self.equation_bookends: str = "<eq>{EQ}</eq>" # 公式标记格式def convert(self,