From e7b0f8beed57429eeabd06e5c6601686d792f69d Mon Sep 17 00:00:00 2001 From: xuchao Date: Fri, 9 Aug 2024 19:44:38 +0800 Subject: [PATCH] docs: update to 0.7.0b1 --- README.md | 451 +++++++++++++++++++++++++------------------- README.md.bak | 328 ++++++++++++++++++++++++++++++++ README_v2.md | 387 ------------------------------------- README_zh-CN.md | 440 ++++++++++++++++++++++++------------------ README_zh-CN.md.bak | 322 +++++++++++++++++++++++++++++++ README_zh-CN_v2.md | 398 -------------------------------------- 6 files changed, 1163 insertions(+), 1163 deletions(-) create mode 100644 README.md.bak delete mode 100644 README_v2.md create mode 100644 README_zh-CN.md.bak delete mode 100644 README_zh-CN_v2.md diff --git a/README.md b/README.md index 85ab991d..a67849f8 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,10 @@ -
- +
+

-
-
- + [![stars](https://img.shields.io/github/stars/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) [![forks](https://img.shields.io/github/forks/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) [![open issues](https://img.shields.io/github/issues-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues) @@ -14,211 +12,266 @@ [![PyPI version](https://badge.fury.io/py/magic-pdf.svg)](https://badge.fury.io/py/magic-pdf) [![Downloads](https://static.pepy.tech/badge/magic-pdf)](https://pepy.tech/project/magic-pdf) [![Downloads](https://static.pepy.tech/badge/magic-pdf/month)](https://pepy.tech/project/magic-pdf) +opendatalab%2FMinerU | Trendshift -opendatalab%2FMinerU | Trendshift - - - + +[English](README.md) | [简体中文](README_zh-CN.md) -[English](README.md) | [简体中文](README_zh-CN.md) | [日本語](README_ja-JP.md) - -
- -
+

-MinerU: An end-to-end PDF parsing tool based on PDF-Extract-Kit, supporting conversion from PDF to Markdown.🚀🚀🚀
-PDF-Extract-Kit: A Comprehensive Toolkit for High-Quality PDF Content Extraction🔥🔥🔥 +PDF-Extract-Kit: High-Quality PDF Extraction Toolkit🔥🔥🔥

+

- 👋 join us on Discord and WeChat + 👋 join us on Discord and WeChat

-
- -# MinerU - -## Introduction - -MinerU is a one-stop, open-source, high-quality data extraction tool, includes the following primary features: - -- [Magic-PDF](#Magic-PDF) PDF Document Extraction -- [Magic-Doc](#Magic-Doc) Webpage & E-book Extraction - - -# Magic-PDF - - -## Introduction - -Magic-PDF is a tool designed to convert PDF documents into Markdown format, capable of processing files stored locally or on object storage supporting S3 protocol. - -Key features include: - -- Support for multiple front-end model inputs -- Removal of headers, footers, footnotes, and page numbers -- Human-readable layout formatting -- Retains the original document's structure and formatting, including headings, paragraphs, lists, and more -- Extraction and display of images and tables within markdown -- Conversion of equations into LaTeX format -- Automatic detection and conversion of garbled PDFs -- Compatibility with CPU and GPU environments -- Available for Windows, Linux and macOS platforms +
+# Changelog +- 2024/08/09: Version 0.7.0b1 released, simplified installation process, added table recognition functionality +- 2024/08/01: Version 0.6.2b1 released, optimized dependency conflict issues and installation documentation +- 2024/07/05: Initial open-source release + + +
+

Table of Contents

+
    +
  1. + MinerU + +
  2. +
  3. TODO
  4. +
  5. Known Issues
  6. +
  7. FAQ
  8. +
  9. All Thanks To Our Contributors
  10. +
  11. License Information
  12. +
  13. Acknowledgments
  14. +
  15. Citation
  16. +
  17. Star History
  18. +
  19. Magic-doc
  20. +
  21. Magic-html
  22. +
  23. Links
  24. +
+
+ + + +# MinerU +## Project Introduction +MinerU is a tool that converts PDFs into machine-readable formats (e.g., markdown, JSON), allowing for easy extraction into any format. +MinerU was born during the pre-training process of [InternLM](https://github.com/InternLM/InternLM). We focus on solving symbol conversion issues in scientific literature and hope to contribute to technological development in the era of large models. +Compared to well-known commercial products, MinerU is still young. If you encounter any issues or if the results are not as expected, please submit an issue on [issue](https://github.com/opendatalab/MinerU/issues) and **attach the relevant PDF**. https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c - - -## Project Panorama - -![Project Panorama](docs/images/project_panorama_en.png) - - -## Flowchart - -![Flowchart](docs/images/flowchart_en.png) - -### Dependency repositorys - -- [PDF-Extract-Kit : A Comprehensive Toolkit for High-Quality PDF Content Extraction](https://github.com/opendatalab/PDF-Extract-Kit) 🚀🚀🚀 - -## Getting Started - -### Requirements - -- Python >= 3.9 - -Using a virtual environment is recommended to avoid potential dependency conflicts; both venv and conda are suitable. -For example: +## Key Features + +- Removes elements such as headers, footers, footnotes, and page numbers while maintaining semantic continuity +- Outputs text in a human-readable order from multi-column documents +- Retains the original structure of the document, including titles, paragraphs, and lists +- Extracts images, image captions, tables, and table captions +- Automatically recognizes formulas in the document and converts them to LaTeX +- Automatically recognizes tables in the document and converts them to LaTeX +- Automatically detects and enables OCR for corrupted PDFs +- Supports both CPU and GPU environments +- Supports Windows, Linux, and Mac platforms + +## Quick Start + +If you encounter any installation issues, please first consult the FAQ.
+If the parsing results are not as expected, refer to the Known Issues.
+There are three different ways to experience MinerU: +- [Online Demo (No Installation Required)](#online-demo) +- [Quick CPU Demo (Windows, Linux, Mac)](#quick-cpu-demo) +- [Linux/Windows + CUDA](#Using-GPU) + +**⚠️ Pre-installation Notice—Hardware and Software Environment Support** + +To ensure the stability and reliability of the project, we only optimize and test for specific hardware and software environments during development. This ensures that users deploying and running the project on recommended system configurations will get the best performance with the fewest compatibility issues. + +By focusing resources on the mainline environment, our team can more efficiently resolve potential bugs and develop new features. + +In non-mainline environments, due to the diversity of hardware and software configurations, as well as third-party dependency compatibility issues, we cannot guarantee 100% project availability. Therefore, for users who wish to use this project in non-recommended environments, we suggest carefully reading the documentation and FAQ first. Most issues already have corresponding solutions in the FAQ. We also encourage community feedback to help us gradually expand support. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Operating System
Ubuntu 22.04 LTSWindows 10 / 11macOS 11+
CPUx86_64x86_64x86_64 / arm64
Memory16GB or more, recommended 32GB+
Python Version3.10
Nvidia Driver Versionlatest (Proprietary Driver)latestNone
CUDA EnvironmentAutomatic installation [12.1 (pytorch) + 11.8 (paddle)]11.8 (manual installation) + cuDNN v8.7.0 (manual installation)None
GPU Hardware Support ListMinimum Requirement 8G+ VRAM3060ti/3070/3080/3080ti/4060/4070/4070ti
+ 8G VRAM only enables layout and formula recognition acceleration
None
Recommended Configuration 16G+ VRAM3090/3090ti/4070ti super/4080/4090
+ 16G or more can enable layout, formula recognition, and OCR acceleration simultaneously
+ +### Online Demo + +[Click here for the online demo](https://opendatalab.com/OpenSourceTools/Extractor/PDF) + +### Quick CPU Demo + +#### 1. Install magic-pdf ```bash conda create -n MinerU python=3.10 conda activate MinerU +pip install magic-pdf[full]==0.7.0b1 --extra-index-url https://wheels.myhloli.com ``` - -### Installation and Configuration - -#### 1. Install Magic-PDF - -**1.Install dependencies** - -The full-feature package depends on detectron2, which requires a compilation installation. -If you need to compile it yourself, please refer to https://github.com/facebookresearch/detectron2/issues/5114 -Alternatively, you can directly use our precompiled whl package (limited to Python 3.10): - -```bash -pip install detectron2 --extra-index-url https://wheels.myhloli.com -``` - -**2.Install the full-feature package with pip** ->Note: The pip-installed package supports CPU-only and is ideal for quick tests. -> ->For CUDA/MPS acceleration in production, see [Acceleration Using CUDA or MPS](#4-Acceleration-Using-CUDA-or-MPS). - -```bash -pip install magic-pdf[full]==0.6.2b1 -``` -> ❗️❗️❗️ -> We have pre-released the 0.6.2 beta version, addressing numerous issues mentioned in our logs. However, this build has not undergone full QA testing and does not represent the final release quality. Should you encounter any problems, please promptly report them to us via issues or revert to using version 0.6.1. -> ```bash -> pip install magic-pdf[full-cpu]==0.6.1 -> ``` - - - -#### 2. Downloading model weights files - -For detailed references, please see below [how_to_download_models](docs/how_to_download_models_en.md) - -After downloading the model weights, move the 'models' directory to a directory on a larger disk space, preferably an SSD. - - -#### 3. Copy the Configuration File and Make Configurations -You can get the [magic-pdf.template.json](magic-pdf.template.json) file in the repository root directory. +#### 2. Download model weight files + +Refer to [How to Download Model Files](docs/how_to_download_models_en.md) for detailed instructions. +> ❗️After downloading the models, please make sure to verify the completeness of the model files. +> +> Check if the model file sizes match the description on the webpage. If possible, use sha256 to verify the integrity of the files. + +#### 3. Copy and configure the template file +You can find the `magic-pdf.template.json` template configuration file in the root directory of the repository. +> ❗️Make sure to execute the following command to copy the configuration file to your **user directory**; otherwise, the program will not run. +> +> The user directory for Windows is `C:\Users\YourUsername`, for Linux it is `/home/YourUsername`, and for macOS it is `/Users/YourUsername`. ```bash cp magic-pdf.template.json ~/magic-pdf.json ``` -In magic-pdf.json, configure "models-dir" to point to the directory where the model weights files are located. - -```json -{ - "models-dir": "/tmp/models" -} -``` - - -#### 4. Acceleration Using CUDA or MPS -If you have an available Nvidia GPU or are using a Mac with Apple Silicon, you can leverage acceleration with CUDA or MPS respectively. -##### CUDA - -You need to install the corresponding PyTorch version according to your CUDA version. -This example installs the CUDA 11.8 version.More information https://pytorch.org/get-started/locally/ -```bash -pip install --force-reinstall torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu118 -``` -> ❗ ️Make sure to specify version -> ```bash -> torch==2.3.1 torchvision==0.18.1 -> ``` -> in the command, as these are the highest versions we support. Failing to specify the versions may result in automatically installing higher versions which can cause the program to fail. -Also, you need to modify the value of "device-mode" in the configuration file magic-pdf.json. +Find the `magic-pdf.json` file in your user directory and configure the "models-dir" path to point to the directory where the model weight files were downloaded in [Step 2](#2-download-model-weight-files). +> ❗️Make sure to correctly configure the **absolute path** to the model weight files directory, otherwise the program will not run because it can't find the model files. +> +> On Windows, this path should include the drive letter and all backslashes (`\`) in the path should be replaced with forward slashes (`/`) to avoid syntax errors in the JSON file due to escape sequences. +> +> For example: If the models are stored in the "models" directory at the root of the D drive, the "model-dir" value should be `D:/models`. ```json { - "device-mode":"cuda" + // other config + "models-dir": "D:/models", + "table-config": { + "is_table_recog_enable": false, // Table recognition is disabled by default, modify this value to enable it + "max_time": 400 + } } ``` -##### MPS -For macOS users with M-series chip devices, you can use MPS for inference acceleration. -You also need to modify the value of "device-mode" in the configuration file magic-pdf.json. -```json -{ - "device-mode":"mps" -} -``` +### Using GPU +If your device supports CUDA and meets the GPU requirements of the mainline environment, you can use GPU acceleration. Please select the appropriate guide based on your system: +- [Ubuntu 22.04 LTS + GPU](docs/README_Ubuntu_CUDA_Acceleration_en_US.md) +- [Windows 10/11 + GPU](docs/README_Windows_CUDA_Acceleration_en_US.md) -### Usage -#### 1.Usage via Command Line +## Usage -###### simple +### Command Line ```bash -magic-pdf pdf-command --pdf "pdf_path" --inside_model true -``` -After the program has finished, you can find the generated markdown files under the directory "/tmp/magic-pdf". -You can find the corresponding xxx_model.json file in the markdown directory. -If you intend to do secondary development on the post-processing pipeline, you can use the command: -```bash -magic-pdf pdf-command --pdf "pdf_path" --model "model_json_path" +magic-pdf --help +Usage: magic-pdf [OPTIONS] + +Options: + -v, --version display the version and exit + -p, --path PATH local pdf filepath or directory [required] + -o, --output-dir TEXT output local directory + -m, --method [ocr|txt|auto] the method for parsing pdf. + ocr: using ocr technique to extract information from pdf, + txt: suitable for the text-based pdf only and outperform ocr, + auto: automatically choose the best method for parsing pdf + from ocr and txt. + without method specified, auto will be used by default. + --help Show this message and exit. + + +## show version +magic-pdf -v + +## command line example +magic-pdf -p {some_pdf} -o {some_output_dir} -m auto ``` -In this way, you won't need to re-run the model data, making debugging more convenient. - -###### more - -```bash -magic-pdf --help +`{some_pdf}` can be a single PDF file or a directory containing multiple PDFs. +The results will be saved in the `{some_output_dir}` directory. The output file list is as follows: + +```text +├── some_pdf.md # markdown file +├── images # directory for storing images +├── layout.pdf # layout diagram +├── middle.json # MinerU intermediate processing result +├── model.json # model inference result +├── origin.pdf # original PDF file +└── spans.pdf # smallest granularity bbox position information diagram ``` +For more information about the output files, please refer to the [Output File Description](docs/output_file_en_us.md). -#### 2. Usage via Api +### API -###### Local +Processing files from local disk ```python image_writer = DiskReaderWriter(local_image_dir) image_dir = str(os.path.basename(local_image_dir)) jso_useful_key = {"_pdf_type": "", "model_list": []} pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer) pipe.pipe_classify() +pipe.pipe_analyze() pipe.pipe_parse() md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") ``` -###### Object Storage +Processing files from object storage ```python s3pdf_cli = S3ReaderWriter(pdf_ak, pdf_sk, pdf_endpoint) image_dir = "s3://img_bucket/" @@ -227,48 +280,49 @@ pdf_bytes = s3pdf_cli.read(s3_pdf_path, mode=s3pdf_cli.MODE_BIN) jso_useful_key = {"_pdf_type": "", "model_list": []} pipe = UNIPipe(pdf_bytes, jso_useful_key, s3image_cli) pipe.pipe_classify() +pipe.pipe_analyze() pipe.pipe_parse() md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") ``` -Demo can be referred to [demo.py](demo/demo.py) - - -# Magic-Doc - - -## Introduction - -Magic-Doc is a tool designed to convert web pages or multi-format e-books into markdown format. - -Key Features Include: - -- Web Page Extraction - - Cross-modal precise parsing of text, images, tables, and formula information. - -- E-Book Document Extraction - - Supports various document formats including epub, mobi, with full adaptation for text and images. +For detailed implementation, refer to: +- [demo.py Simplest Processing Method](demo/demo.py) +- [magic_pdf_parse_main.py More Detailed Processing Workflow](demo/magic_pdf_parse_main.py) -- Language Type Identification - - Accurate recognition of 176 languages. -https://github.com/opendatalab/MinerU/assets/11393164/a5a650e9-f4c0-463e-acc3-960967f1a1ca +### Development Guide +TODO +# TODO -https://github.com/opendatalab/MinerU/assets/11393164/0f4a6fe9-6cca-4113-9fdc-a537749d764d +- [ ] Semantic-based reading order +- [ ] List recognition within the text +- [ ] Code block recognition within the text +- [ ] Table of contents recognition +- [x] Table recognition +- [ ] Chemical formula recognition +- [ ] Geometric shape recognition +# Known Issues +- Reading order is segmented based on rules, which can cause disordered sequences in some cases +- Vertical text is not supported +- Lists, code blocks, and table of contents are not yet supported in the layout model +- Comic books, art books, elementary school textbooks, and exercise books are not well-parsed yet +- Enabling OCR may produce better results in PDFs with a high density of formulas +- If you are processing PDFs with a large number of formulas, it is strongly recommended to enable the OCR function. When using PyMuPDF to extract text, overlapping text lines can occur, leading to inaccurate formula insertion positions. +- **Table Recognition** is currently in the testing phase; recognition speed is slow, and accuracy needs improvement. Below are some performance test results in an Ubuntu 22.04 LTS + Intel(R) Xeon(R) Platinum 8352V CPU @ 2.10GHz + NVIDIA GeForce RTX 4090 environment for reference. +| Table Size | Parsing Time | +|---------------|----------------------------| +| 6\*5 55kb | 37s | +| 16\*12 284kb | 3m18s | +| 44\*7 559kb | 4m12s | -https://github.com/opendatalab/MinerU/assets/11393164/20438a02-ce6c-4af8-9dde-d722a4e825b2 +# FAQ +[FAQ in Chinese](docs/FAQ_zh_cn.md) - - - -## Project Repository - -- [Magic-Doc](https://github.com/InternLM/magic-doc) - Outstanding Webpage and E-book Extraction Tool +[FAQ in English](docs/FAQ_en_us.md) # All Thanks To Our Contributors @@ -277,22 +331,21 @@ https://github.com/opendatalab/MinerU/assets/11393164/20438a02-ce6c-4af8-9dde-d7 - # License Information [LICENSE.md](LICENSE.md) -The project currently leverages PyMuPDF to deliver advanced functionalities; however, its adherence to the AGPL license may impose limitations on certain use cases. In upcoming iterations, we intend to explore and transition to a more permissively licensed PDF processing library to enhance user-friendliness and flexibility. +This project currently uses PyMuPDF to achieve advanced functionality. However, since it adheres to the AGPL license, it may impose restrictions on certain usage scenarios. In future iterations, we plan to explore and replace it with a more permissive PDF processing library to enhance user-friendliness and flexibility. # Acknowledgments - +- [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit) +- [StructEqTable](https://github.com/UniModal4Reasoning/StructEqTable-Deploy) - [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) - [PyMuPDF](https://github.com/pymupdf/PyMuPDF) - [fast-langdetect](https://github.com/LlmKira/fast-langdetect) - [pdfminer.six](https://github.com/pdfminer/pdfminer.six) - # Citation ```bibtex @@ -311,7 +364,6 @@ The project currently leverages PyMuPDF to deliver advanced functionalities; how } ``` - # Star History @@ -322,7 +374,14 @@ The project currently leverages PyMuPDF to deliver advanced functionalities; how +# Magic-doc +[Magic-Doc](https://github.com/InternLM/magic-doc) Fast speed ppt/pptx/doc/docx/pdf extraction tool + +# Magic-html +[Magic-HTML](https://github.com/opendatalab/magic-html) Mixed web page extraction tool + # Links + - [LabelU (A Lightweight Multi-modal Data Annotation Tool)](https://github.com/opendatalab/labelU) - [LabelLLM (An Open-source LLM Dialogue Annotation Platform)](https://github.com/opendatalab/LabelLLM) - [PDF-Extract-Kit (A Comprehensive Toolkit for High-Quality PDF Content Extraction)](https://github.com/opendatalab/PDF-Extract-Kit) diff --git a/README.md.bak b/README.md.bak new file mode 100644 index 00000000..85ab991d --- /dev/null +++ b/README.md.bak @@ -0,0 +1,328 @@ +
+ +

+ +

+ +
+
+ +[![stars](https://img.shields.io/github/stars/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) +[![forks](https://img.shields.io/github/forks/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) +[![open issues](https://img.shields.io/github/issues-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues) +[![issue resolution](https://img.shields.io/github/issues-closed-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues) +[![PyPI version](https://badge.fury.io/py/magic-pdf.svg)](https://badge.fury.io/py/magic-pdf) +[![Downloads](https://static.pepy.tech/badge/magic-pdf)](https://pepy.tech/project/magic-pdf) +[![Downloads](https://static.pepy.tech/badge/magic-pdf/month)](https://pepy.tech/project/magic-pdf) + +opendatalab%2FMinerU | Trendshift + + + + +[English](README.md) | [简体中文](README_zh-CN.md) | [日本語](README_ja-JP.md) + +
+ +
+

+MinerU: An end-to-end PDF parsing tool based on PDF-Extract-Kit, supporting conversion from PDF to Markdown.🚀🚀🚀
+PDF-Extract-Kit: A Comprehensive Toolkit for High-Quality PDF Content Extraction🔥🔥🔥 +

+ +

+ 👋 join us on Discord and WeChat +

+
+ +# MinerU + + +## Introduction + +MinerU is a one-stop, open-source, high-quality data extraction tool, includes the following primary features: + +- [Magic-PDF](#Magic-PDF) PDF Document Extraction +- [Magic-Doc](#Magic-Doc) Webpage & E-book Extraction + + +# Magic-PDF + + +## Introduction + +Magic-PDF is a tool designed to convert PDF documents into Markdown format, capable of processing files stored locally or on object storage supporting S3 protocol. + +Key features include: + +- Support for multiple front-end model inputs +- Removal of headers, footers, footnotes, and page numbers +- Human-readable layout formatting +- Retains the original document's structure and formatting, including headings, paragraphs, lists, and more +- Extraction and display of images and tables within markdown +- Conversion of equations into LaTeX format +- Automatic detection and conversion of garbled PDFs +- Compatibility with CPU and GPU environments +- Available for Windows, Linux and macOS platforms + + +https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c + + + +## Project Panorama + +![Project Panorama](docs/images/project_panorama_en.png) + + +## Flowchart + +![Flowchart](docs/images/flowchart_en.png) + +### Dependency repositorys + +- [PDF-Extract-Kit : A Comprehensive Toolkit for High-Quality PDF Content Extraction](https://github.com/opendatalab/PDF-Extract-Kit) 🚀🚀🚀 + +## Getting Started + +### Requirements + +- Python >= 3.9 + +Using a virtual environment is recommended to avoid potential dependency conflicts; both venv and conda are suitable. +For example: +```bash +conda create -n MinerU python=3.10 +conda activate MinerU +``` + +### Installation and Configuration + +#### 1. Install Magic-PDF + +**1.Install dependencies** + +The full-feature package depends on detectron2, which requires a compilation installation. +If you need to compile it yourself, please refer to https://github.com/facebookresearch/detectron2/issues/5114 +Alternatively, you can directly use our precompiled whl package (limited to Python 3.10): + +```bash +pip install detectron2 --extra-index-url https://wheels.myhloli.com +``` + +**2.Install the full-feature package with pip** +>Note: The pip-installed package supports CPU-only and is ideal for quick tests. +> +>For CUDA/MPS acceleration in production, see [Acceleration Using CUDA or MPS](#4-Acceleration-Using-CUDA-or-MPS). + +```bash +pip install magic-pdf[full]==0.6.2b1 +``` +> ❗️❗️❗️ +> We have pre-released the 0.6.2 beta version, addressing numerous issues mentioned in our logs. However, this build has not undergone full QA testing and does not represent the final release quality. Should you encounter any problems, please promptly report them to us via issues or revert to using version 0.6.1. +> ```bash +> pip install magic-pdf[full-cpu]==0.6.1 +> ``` + + + +#### 2. Downloading model weights files + +For detailed references, please see below [how_to_download_models](docs/how_to_download_models_en.md) + +After downloading the model weights, move the 'models' directory to a directory on a larger disk space, preferably an SSD. + + +#### 3. Copy the Configuration File and Make Configurations +You can get the [magic-pdf.template.json](magic-pdf.template.json) file in the repository root directory. +```bash +cp magic-pdf.template.json ~/magic-pdf.json +``` +In magic-pdf.json, configure "models-dir" to point to the directory where the model weights files are located. + +```json +{ + "models-dir": "/tmp/models" +} +``` + + +#### 4. Acceleration Using CUDA or MPS +If you have an available Nvidia GPU or are using a Mac with Apple Silicon, you can leverage acceleration with CUDA or MPS respectively. +##### CUDA + +You need to install the corresponding PyTorch version according to your CUDA version. +This example installs the CUDA 11.8 version.More information https://pytorch.org/get-started/locally/ +```bash +pip install --force-reinstall torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu118 +``` +> ❗ ️Make sure to specify version +> ```bash +> torch==2.3.1 torchvision==0.18.1 +> ``` +> in the command, as these are the highest versions we support. Failing to specify the versions may result in automatically installing higher versions which can cause the program to fail. + +Also, you need to modify the value of "device-mode" in the configuration file magic-pdf.json. +```json +{ + "device-mode":"cuda" +} +``` + +##### MPS + +For macOS users with M-series chip devices, you can use MPS for inference acceleration. +You also need to modify the value of "device-mode" in the configuration file magic-pdf.json. +```json +{ + "device-mode":"mps" +} +``` + + +### Usage + +#### 1.Usage via Command Line + +###### simple + +```bash +magic-pdf pdf-command --pdf "pdf_path" --inside_model true +``` +After the program has finished, you can find the generated markdown files under the directory "/tmp/magic-pdf". +You can find the corresponding xxx_model.json file in the markdown directory. +If you intend to do secondary development on the post-processing pipeline, you can use the command: +```bash +magic-pdf pdf-command --pdf "pdf_path" --model "model_json_path" +``` +In this way, you won't need to re-run the model data, making debugging more convenient. + + +###### more + +```bash +magic-pdf --help +``` + + +#### 2. Usage via Api + +###### Local +```python +image_writer = DiskReaderWriter(local_image_dir) +image_dir = str(os.path.basename(local_image_dir)) +jso_useful_key = {"_pdf_type": "", "model_list": []} +pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer) +pipe.pipe_classify() +pipe.pipe_parse() +md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") +``` + +###### Object Storage +```python +s3pdf_cli = S3ReaderWriter(pdf_ak, pdf_sk, pdf_endpoint) +image_dir = "s3://img_bucket/" +s3image_cli = S3ReaderWriter(img_ak, img_sk, img_endpoint, parent_path=image_dir) +pdf_bytes = s3pdf_cli.read(s3_pdf_path, mode=s3pdf_cli.MODE_BIN) +jso_useful_key = {"_pdf_type": "", "model_list": []} +pipe = UNIPipe(pdf_bytes, jso_useful_key, s3image_cli) +pipe.pipe_classify() +pipe.pipe_parse() +md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") +``` + +Demo can be referred to [demo.py](demo/demo.py) + + +# Magic-Doc + + +## Introduction + +Magic-Doc is a tool designed to convert web pages or multi-format e-books into markdown format. + +Key Features Include: + +- Web Page Extraction + - Cross-modal precise parsing of text, images, tables, and formula information. + +- E-Book Document Extraction + - Supports various document formats including epub, mobi, with full adaptation for text and images. + +- Language Type Identification + - Accurate recognition of 176 languages. + +https://github.com/opendatalab/MinerU/assets/11393164/a5a650e9-f4c0-463e-acc3-960967f1a1ca + + + +https://github.com/opendatalab/MinerU/assets/11393164/0f4a6fe9-6cca-4113-9fdc-a537749d764d + + + +https://github.com/opendatalab/MinerU/assets/11393164/20438a02-ce6c-4af8-9dde-d722a4e825b2 + + + + +## Project Repository + +- [Magic-Doc](https://github.com/InternLM/magic-doc) + Outstanding Webpage and E-book Extraction Tool + + +# All Thanks To Our Contributors + + + + + + +# License Information + +[LICENSE.md](LICENSE.md) + +The project currently leverages PyMuPDF to deliver advanced functionalities; however, its adherence to the AGPL license may impose limitations on certain use cases. In upcoming iterations, we intend to explore and transition to a more permissively licensed PDF processing library to enhance user-friendliness and flexibility. + + +# Acknowledgments + +- [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) +- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) +- [fast-langdetect](https://github.com/LlmKira/fast-langdetect) +- [pdfminer.six](https://github.com/pdfminer/pdfminer.six) + + +# Citation + +```bibtex +@article{he2024opendatalab, + title={Opendatalab: Empowering general artificial intelligence with open datasets}, + author={He, Conghui and Li, Wei and Jin, Zhenjiang and Xu, Chao and Wang, Bin and Lin, Dahua}, + journal={arXiv preprint arXiv:2407.13773}, + year={2024} +} + +@misc{2024mineru, + title={MinerU: A One-stop, Open-source, High-quality Data Extraction Tool}, + author={MinerU Contributors}, + howpublished = {\url{https://github.com/opendatalab/MinerU}}, + year={2024} +} +``` + + +# Star History + + + + + + Star History Chart + + + +# Links +- [LabelU (A Lightweight Multi-modal Data Annotation Tool)](https://github.com/opendatalab/labelU) +- [LabelLLM (An Open-source LLM Dialogue Annotation Platform)](https://github.com/opendatalab/LabelLLM) +- [PDF-Extract-Kit (A Comprehensive Toolkit for High-Quality PDF Content Extraction)](https://github.com/opendatalab/PDF-Extract-Kit) diff --git a/README_v2.md b/README_v2.md deleted file mode 100644 index a67849f8..00000000 --- a/README_v2.md +++ /dev/null @@ -1,387 +0,0 @@ -
- -

- -

- - -[![stars](https://img.shields.io/github/stars/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) -[![forks](https://img.shields.io/github/forks/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) -[![open issues](https://img.shields.io/github/issues-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues) -[![issue resolution](https://img.shields.io/github/issues-closed-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues) -[![PyPI version](https://badge.fury.io/py/magic-pdf.svg)](https://badge.fury.io/py/magic-pdf) -[![Downloads](https://static.pepy.tech/badge/magic-pdf)](https://pepy.tech/project/magic-pdf) -[![Downloads](https://static.pepy.tech/badge/magic-pdf/month)](https://pepy.tech/project/magic-pdf) -opendatalab%2FMinerU | Trendshift - - -[English](README.md) | [简体中文](README_zh-CN.md) - - -

-PDF-Extract-Kit: High-Quality PDF Extraction Toolkit🔥🔥🔥 -

- - -

- 👋 join us on Discord and WeChat -

- -
- -# Changelog -- 2024/08/09: Version 0.7.0b1 released, simplified installation process, added table recognition functionality -- 2024/08/01: Version 0.6.2b1 released, optimized dependency conflict issues and installation documentation -- 2024/07/05: Initial open-source release - - -
-

Table of Contents

-
    -
  1. - MinerU - -
  2. -
  3. TODO
  4. -
  5. Known Issues
  6. -
  7. FAQ
  8. -
  9. All Thanks To Our Contributors
  10. -
  11. License Information
  12. -
  13. Acknowledgments
  14. -
  15. Citation
  16. -
  17. Star History
  18. -
  19. Magic-doc
  20. -
  21. Magic-html
  22. -
  23. Links
  24. -
-
- - - -# MinerU -## Project Introduction -MinerU is a tool that converts PDFs into machine-readable formats (e.g., markdown, JSON), allowing for easy extraction into any format. -MinerU was born during the pre-training process of [InternLM](https://github.com/InternLM/InternLM). We focus on solving symbol conversion issues in scientific literature and hope to contribute to technological development in the era of large models. -Compared to well-known commercial products, MinerU is still young. If you encounter any issues or if the results are not as expected, please submit an issue on [issue](https://github.com/opendatalab/MinerU/issues) and **attach the relevant PDF**. - -https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c - -## Key Features - -- Removes elements such as headers, footers, footnotes, and page numbers while maintaining semantic continuity -- Outputs text in a human-readable order from multi-column documents -- Retains the original structure of the document, including titles, paragraphs, and lists -- Extracts images, image captions, tables, and table captions -- Automatically recognizes formulas in the document and converts them to LaTeX -- Automatically recognizes tables in the document and converts them to LaTeX -- Automatically detects and enables OCR for corrupted PDFs -- Supports both CPU and GPU environments -- Supports Windows, Linux, and Mac platforms - -## Quick Start - -If you encounter any installation issues, please first consult the FAQ.
-If the parsing results are not as expected, refer to the Known Issues.
-There are three different ways to experience MinerU: -- [Online Demo (No Installation Required)](#online-demo) -- [Quick CPU Demo (Windows, Linux, Mac)](#quick-cpu-demo) -- [Linux/Windows + CUDA](#Using-GPU) - -**⚠️ Pre-installation Notice—Hardware and Software Environment Support** - -To ensure the stability and reliability of the project, we only optimize and test for specific hardware and software environments during development. This ensures that users deploying and running the project on recommended system configurations will get the best performance with the fewest compatibility issues. - -By focusing resources on the mainline environment, our team can more efficiently resolve potential bugs and develop new features. - -In non-mainline environments, due to the diversity of hardware and software configurations, as well as third-party dependency compatibility issues, we cannot guarantee 100% project availability. Therefore, for users who wish to use this project in non-recommended environments, we suggest carefully reading the documentation and FAQ first. Most issues already have corresponding solutions in the FAQ. We also encourage community feedback to help us gradually expand support. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Operating System
Ubuntu 22.04 LTSWindows 10 / 11macOS 11+
CPUx86_64x86_64x86_64 / arm64
Memory16GB or more, recommended 32GB+
Python Version3.10
Nvidia Driver Versionlatest (Proprietary Driver)latestNone
CUDA EnvironmentAutomatic installation [12.1 (pytorch) + 11.8 (paddle)]11.8 (manual installation) + cuDNN v8.7.0 (manual installation)None
GPU Hardware Support ListMinimum Requirement 8G+ VRAM3060ti/3070/3080/3080ti/4060/4070/4070ti
- 8G VRAM only enables layout and formula recognition acceleration
None
Recommended Configuration 16G+ VRAM3090/3090ti/4070ti super/4080/4090
- 16G or more can enable layout, formula recognition, and OCR acceleration simultaneously
- -### Online Demo - -[Click here for the online demo](https://opendatalab.com/OpenSourceTools/Extractor/PDF) - -### Quick CPU Demo - -#### 1. Install magic-pdf -```bash -conda create -n MinerU python=3.10 -conda activate MinerU -pip install magic-pdf[full]==0.7.0b1 --extra-index-url https://wheels.myhloli.com -``` -#### 2. Download model weight files - -Refer to [How to Download Model Files](docs/how_to_download_models_en.md) for detailed instructions. -> ❗️After downloading the models, please make sure to verify the completeness of the model files. -> -> Check if the model file sizes match the description on the webpage. If possible, use sha256 to verify the integrity of the files. - -#### 3. Copy and configure the template file -You can find the `magic-pdf.template.json` template configuration file in the root directory of the repository. -> ❗️Make sure to execute the following command to copy the configuration file to your **user directory**; otherwise, the program will not run. -> -> The user directory for Windows is `C:\Users\YourUsername`, for Linux it is `/home/YourUsername`, and for macOS it is `/Users/YourUsername`. -```bash -cp magic-pdf.template.json ~/magic-pdf.json -``` - -Find the `magic-pdf.json` file in your user directory and configure the "models-dir" path to point to the directory where the model weight files were downloaded in [Step 2](#2-download-model-weight-files). -> ❗️Make sure to correctly configure the **absolute path** to the model weight files directory, otherwise the program will not run because it can't find the model files. -> -> On Windows, this path should include the drive letter and all backslashes (`\`) in the path should be replaced with forward slashes (`/`) to avoid syntax errors in the JSON file due to escape sequences. -> -> For example: If the models are stored in the "models" directory at the root of the D drive, the "model-dir" value should be `D:/models`. -```json -{ - // other config - "models-dir": "D:/models", - "table-config": { - "is_table_recog_enable": false, // Table recognition is disabled by default, modify this value to enable it - "max_time": 400 - } -} -``` - - -### Using GPU -If your device supports CUDA and meets the GPU requirements of the mainline environment, you can use GPU acceleration. Please select the appropriate guide based on your system: - -- [Ubuntu 22.04 LTS + GPU](docs/README_Ubuntu_CUDA_Acceleration_en_US.md) -- [Windows 10/11 + GPU](docs/README_Windows_CUDA_Acceleration_en_US.md) - - -## Usage - -### Command Line - -```bash -magic-pdf --help -Usage: magic-pdf [OPTIONS] - -Options: - -v, --version display the version and exit - -p, --path PATH local pdf filepath or directory [required] - -o, --output-dir TEXT output local directory - -m, --method [ocr|txt|auto] the method for parsing pdf. - ocr: using ocr technique to extract information from pdf, - txt: suitable for the text-based pdf only and outperform ocr, - auto: automatically choose the best method for parsing pdf - from ocr and txt. - without method specified, auto will be used by default. - --help Show this message and exit. - - -## show version -magic-pdf -v - -## command line example -magic-pdf -p {some_pdf} -o {some_output_dir} -m auto -``` - -`{some_pdf}` can be a single PDF file or a directory containing multiple PDFs. -The results will be saved in the `{some_output_dir}` directory. The output file list is as follows: - -```text -├── some_pdf.md # markdown file -├── images # directory for storing images -├── layout.pdf # layout diagram -├── middle.json # MinerU intermediate processing result -├── model.json # model inference result -├── origin.pdf # original PDF file -└── spans.pdf # smallest granularity bbox position information diagram -``` - -For more information about the output files, please refer to the [Output File Description](docs/output_file_en_us.md). - -### API - -Processing files from local disk -```python -image_writer = DiskReaderWriter(local_image_dir) -image_dir = str(os.path.basename(local_image_dir)) -jso_useful_key = {"_pdf_type": "", "model_list": []} -pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer) -pipe.pipe_classify() -pipe.pipe_analyze() -pipe.pipe_parse() -md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") -``` - -Processing files from object storage -```python -s3pdf_cli = S3ReaderWriter(pdf_ak, pdf_sk, pdf_endpoint) -image_dir = "s3://img_bucket/" -s3image_cli = S3ReaderWriter(img_ak, img_sk, img_endpoint, parent_path=image_dir) -pdf_bytes = s3pdf_cli.read(s3_pdf_path, mode=s3pdf_cli.MODE_BIN) -jso_useful_key = {"_pdf_type": "", "model_list": []} -pipe = UNIPipe(pdf_bytes, jso_useful_key, s3image_cli) -pipe.pipe_classify() -pipe.pipe_analyze() -pipe.pipe_parse() -md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") -``` - -For detailed implementation, refer to: -- [demo.py Simplest Processing Method](demo/demo.py) -- [magic_pdf_parse_main.py More Detailed Processing Workflow](demo/magic_pdf_parse_main.py) - - -### Development Guide - -TODO - -# TODO - -- [ ] Semantic-based reading order -- [ ] List recognition within the text -- [ ] Code block recognition within the text -- [ ] Table of contents recognition -- [x] Table recognition -- [ ] Chemical formula recognition -- [ ] Geometric shape recognition - -# Known Issues -- Reading order is segmented based on rules, which can cause disordered sequences in some cases -- Vertical text is not supported -- Lists, code blocks, and table of contents are not yet supported in the layout model -- Comic books, art books, elementary school textbooks, and exercise books are not well-parsed yet -- Enabling OCR may produce better results in PDFs with a high density of formulas -- If you are processing PDFs with a large number of formulas, it is strongly recommended to enable the OCR function. When using PyMuPDF to extract text, overlapping text lines can occur, leading to inaccurate formula insertion positions. -- **Table Recognition** is currently in the testing phase; recognition speed is slow, and accuracy needs improvement. Below are some performance test results in an Ubuntu 22.04 LTS + Intel(R) Xeon(R) Platinum 8352V CPU @ 2.10GHz + NVIDIA GeForce RTX 4090 environment for reference. - -| Table Size | Parsing Time | -|---------------|----------------------------| -| 6\*5 55kb | 37s | -| 16\*12 284kb | 3m18s | -| 44\*7 559kb | 4m12s | - -# FAQ -[FAQ in Chinese](docs/FAQ_zh_cn.md) - -[FAQ in English](docs/FAQ_en_us.md) - - -# All Thanks To Our Contributors - - - - - -# License Information - -[LICENSE.md](LICENSE.md) - -This project currently uses PyMuPDF to achieve advanced functionality. However, since it adheres to the AGPL license, it may impose restrictions on certain usage scenarios. In future iterations, we plan to explore and replace it with a more permissive PDF processing library to enhance user-friendliness and flexibility. - - -# Acknowledgments -- [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit) -- [StructEqTable](https://github.com/UniModal4Reasoning/StructEqTable-Deploy) -- [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) -- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) -- [fast-langdetect](https://github.com/LlmKira/fast-langdetect) -- [pdfminer.six](https://github.com/pdfminer/pdfminer.six) - -# Citation - -```bibtex -@article{he2024opendatalab, - title={Opendatalab: Empowering general artificial intelligence with open datasets}, - author={He, Conghui and Li, Wei and Jin, Zhenjiang and Xu, Chao and Wang, Bin and Lin, Dahua}, - journal={arXiv preprint arXiv:2407.13773}, - year={2024} -} - -@misc{2024mineru, - title={MinerU: A One-stop, Open-source, High-quality Data Extraction Tool}, - author={MinerU Contributors}, - howpublished = {\url{https://github.com/opendatalab/MinerU}}, - year={2024} -} -``` - -# Star History - - - - - - Star History Chart - - - -# Magic-doc -[Magic-Doc](https://github.com/InternLM/magic-doc) Fast speed ppt/pptx/doc/docx/pdf extraction tool - -# Magic-html -[Magic-HTML](https://github.com/opendatalab/magic-html) Mixed web page extraction tool - -# Links - -- [LabelU (A Lightweight Multi-modal Data Annotation Tool)](https://github.com/opendatalab/labelU) -- [LabelLLM (An Open-source LLM Dialogue Annotation Platform)](https://github.com/opendatalab/LabelLLM) -- [PDF-Extract-Kit (A Comprehensive Toolkit for High-Quality PDF Content Extraction)](https://github.com/opendatalab/PDF-Extract-Kit) diff --git a/README_zh-CN.md b/README_zh-CN.md index 708c140f..16aee115 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -1,10 +1,11 @@ -
+
+

- +

-
-
+ + [![stars](https://img.shields.io/github/stars/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) [![forks](https://img.shields.io/github/forks/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) [![open issues](https://img.shields.io/github/issues-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues) @@ -14,113 +15,175 @@ [![Downloads](https://static.pepy.tech/badge/magic-pdf/month)](https://pepy.tech/project/magic-pdf) opendatalab%2FMinerU | Trendshift -[English](README.md) | [简体中文](README_zh-CN.md) | [日本語](README_ja-JP.md) + +[English](README.md) | [简体中文](README_zh-CN.md) -
-
+

-MinerU: 端到端的PDF解析工具(基于PDF-Extract-Kit)支持PDF转Markdown🚀🚀🚀
PDF-Extract-Kit: 高质量PDF解析工具箱🔥🔥🔥

+

- 👋 join us on Discord and WeChat + 👋 join us on Discord and WeChat

-
- -# MinerU - - -## 简介 - -MinerU 是一款一站式、开源、高质量的数据提取工具,主要包含以下功能: - -- [Magic-PDF](#Magic-PDF) PDF文档提取 -- [Magic-Doc](#Magic-Doc) 网页与电子书提取 - -# Magic-PDF +
-## 简介 - -Magic-PDF 是一款将 PDF 转化为 markdown 格式的工具。支持转换本地文档或者位于支持S3协议对象存储上的文件。 - -主要功能包含 - -- 支持多种前端模型输入 -- 删除页眉、页脚、脚注、页码等元素 -- 符合人类阅读顺序的排版格式 -- 保留原文档的结构和格式,包括标题、段落、列表等 -- 提取图像和表格并在markdown中展示 -- 将公式转换成latex -- 乱码PDF自动识别并转换 -- 支持cpu和gpu环境 -- 支持windows/linux/mac平台 +# 更新记录 +- 2024/08/09 0.7.0b1发布,简化安装步骤提升易用性,加入表格识别功能 +- 2024/08/01 0.6.2b1发布,优化了依赖冲突问题和安装文档 +- 2024/07/05 首次开源 + + + +
+

文档目录

+
    +
  1. + MinerU + +
  2. +
  3. TODO
  4. +
  5. Known Issues
  6. +
  7. FAQ
  8. +
  9. Contributors
  10. +
  11. License Information
  12. +
  13. Acknowledgements
  14. +
  15. Citation
  16. +
  17. Star History
  18. +
  19. magic-doc快速提取PPT/DOC/PDF
  20. +
  21. magic-html提取混合网页内容
  22. +
  23. Links
  24. +
+
+ + + +# MinerU +## 项目简介 +MinerU是一款将PDF转化为机器可读格式的工具(如markdown、json),可以很方便地抽取为任意格式。 +MinerU诞生于[书生-浦语](https://github.com/InternLM/InternLM)的预训练过程中,我们将会集中精力解决科技文献中的符号转化问题,希望在大模型时代为科技发展做出贡献。 +相比国内外知名商用产品MinerU还很年轻,如果遇到问题或者结果不及预期请到[issue](https://github.com/opendatalab/MinerU/issues)提交问题,同时**附上相关PDF**。 https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c +## 主要功能 +- 删除页眉、页脚、脚注、页码等元素,保持语义连贯 +- 对多栏输出符合人类阅读顺序的文本 +- 保留原文档的结构,包括标题、段落、列表等 +- 提取图像、图片标题、表格、表格标题 +- 自动识别文档中的公式并将公式转换成latex +- 自动识别文档中的表格并将表格转换成latex +- 乱码PDF自动检测并启用OCR +- 支持CPU和GPU环境 +- 支持windows/linux/mac平台 -## 项目全景 - -![项目全景图](docs/images/project_panorama_zh_cn.png) - -## 流程图 - -![流程图](docs/images/flowchart_zh_cn.png) - -### 子模块仓库 - -- [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit) - - 高质量的PDF内容提取工具包 - -## 上手指南 - -### 配置要求 - -python >= 3.9 -推荐使用虚拟环境,以避免可能发生的依赖冲突,venv和conda均可使用。 -例如: +## 快速开始 + +如果遇到任何安装问题,请先查询 FAQ
+如果遇到解析效果不及预期,参考 Known Issues
+有3种不同方式可以体验MinerU的效果: +- [在线体验(无需任何安装)](#在线体验) +- [使用CPU快速体验(Windows,Linux,Mac)](#使用cpu快速体验) +- [Linux/Windows + CUDA](#使用gpu) + + +**⚠️安装前必看——软硬件环境支持说明** + +为了确保项目的稳定性和可靠性,我们在开发过程中仅对特定的软硬件环境进行优化和测试。这样当用户在推荐的系统配置上部署和运行项目时,能够获得最佳的性能表现和最少的兼容性问题。 + +通过集中资源和精力于主线环境,我们团队能够更高效地解决潜在的BUG,及时开发新功能。 + +在非主线环境中,由于硬件、软件配置的多样性,以及第三方依赖项的兼容性问题,我们无法100%保证项目的完全可用性。因此,对于希望在非推荐环境中使用本项目的用户,我们建议先仔细阅读文档以及FAQ,大多数问题已经在FAQ中有对应的解决方案,除此之外我们鼓励社区反馈问题,以便我们能够逐步扩大支持范围。 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
操作系统
Ubuntu 22.04 LTSWindows 10 / 11macOS 11+
CPUx86_64x86_64x86_64 / arm64
内存大于等于16GB,推荐32G以上
python版本3.10
Nvidia Driver 版本latest(专有驱动)latestNone
CUDA环境自动安装[12.1(pytorch)+11.8(paddle)]11.8(手动安装)+cuDNN v8.7.0(手动安装)None
GPU硬件支持列表最低要求 8G+显存3060ti/3070/3080/3080ti/4060/4070/4070ti
+ 8G显存仅可开启lavout和公式识别加速
None
推荐配置 16G+显存3090/3090ti/4070tisuper/4080/4090
+ 16G及以上可以同时开启layout,公式识别和ocr加速
+ +### 在线体验 + +[在线体验点击这里](https://opendatalab.com/OpenSourceTools/Extractor/PDF) + + +### 使用CPU快速体验 + +#### 1. 安装magic-pdf +最新版本国内镜像源同步可能会有延迟,请耐心等待 ```bash conda create -n MinerU python=3.10 conda activate MinerU +pip install magic-pdf[full]==0.7.0b1 --extra-index-url https://wheels.myhloli.com -i https://pypi.tuna.tsinghua.edu.cn/simple ``` -开发基于python 3.10,如果在其他版本python出现问题请切换至3.10。 - -### 安装配置 - -#### 1. 安装Magic-PDF - -**1.安装依赖** - -完整功能包依赖detectron2,该库需要编译安装,如需自行编译,请参考 https://github.com/facebookresearch/detectron2/issues/5114 -或是直接使用我们预编译的whl包: -> ❗️预编译版本仅支持64位系统(windows/linux/macOS)+pyton 3.10平台;不支持任何32位系统和非mac的arm平台,如系统不支持请自行编译安装。 -```bash -pip install detectron2 --extra-index-url https://wheels.myhloli.com -i https://pypi.tuna.tsinghua.edu.cn/simple -``` - -**2.使用pip安装完整功能包** -> 受pypi限制,pip安装的完整功能包仅支持cpu推理,建议只用于快速测试解析能力。 -> -> 如需在生产环境使用CUDA/MPS加速请参考[使用CUDA或MPS加速推理](#4-使用CUDA或MPS加速推理) -```bash -pip install magic-pdf[full]==0.6.2b1 -i https://pypi.tuna.tsinghua.edu.cn/simple -``` -> ❗️❗️❗️ -> 我们预发布了0.6.2beta版本,该版本解决了很多issue中提出的问题,同时提高了安装成功率。但是该版本未经过完整的QA测试,不代表最终正式发布的质量水平。如果你遇到任何问题,请通过提交issue的方式及时向我们反馈,或者回退到使用0.6.1版本。 -> ```bash -> pip install magic-pdf[full-cpu]==0.6.1 -> ``` - - - #### 2. 下载模型权重文件 -详细参考 [如何下载模型文件](docs/how_to_download_models_zh_cn.md) +详细参考 [如何下载模型文件](docs/how_to_download_models_zh_cn.md) > ❗️模型下载后请务必检查模型文件是否下载完整 > > 请检查目录下的模型文件大小与网页上描述是否一致,如果可以的话,最好通过sha256校验模型是否下载完整 @@ -136,167 +199,174 @@ cp magic-pdf.template.json ~/magic-pdf.json 在用户目录中找到magic-pdf.json文件并配置"models-dir"为[2. 下载模型权重文件](#2-下载模型权重文件)中下载的模型权重文件所在目录 > ❗️务必正确配置模型权重文件所在目录的【绝对路径】,否则会因为找不到模型文件而导致程序无法运行 -> +> > windows系统中此路径应包含盘符,且需把路径中所有的"\"替换为"/",否则会因为转义原因导致json文件语法错误。 > > 例如:模型放在D盘根目录的models目录,则model-dir的值应为"D:/models" ```json { - "models-dir": "/tmp/models" + // other config + "models-dir": "D:/models", + "table-config": { + "is_table_recog_enable": false, // 表格识别功能默认是关闭的,如果需要修改此处的值 + "max_time": 400 + } } ``` -#### 4. 使用CUDA或MPS加速推理 -如您有可用的Nvidia显卡或在使用Apple Silicon的Mac,可以使用CUDA或MPS进行加速 -##### CUDA -需要根据自己的CUDA版本安装对应的pytorch版本 -以下是对应CUDA 11.8版本的安装命令,更多信息请参考 https://pytorch.org/get-started/locally/ -```bash -pip install --force-reinstall torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu118 -``` -> ❗️务必在命令中指定以下版本 -> ```bash -> torch==2.3.1 torchvision==0.18.1 -> ``` -> 这是我们支持的最高版本,如果不指定版本会自动安装更高版本导致程序无法运行 - - -同时需要修改【用户目录】中配置文件magic-pdf.json中"device-mode"的值 -```json -{ - "device-mode":"cuda" -} -``` - -##### MPS -使用macOS(M系列芯片设备)可以使用MPS进行推理加速 -需要修改配置文件magic-pdf.json中"device-mode"的值 -```json -{ - "device-mode":"mps" -} -``` +### 使用GPU +如果您的设备支持CUDA,且满足主线环境中的显卡要求,则可以使用GPU加速,请根据自己的系统选择适合的教程: +- [Ubuntu22.04LTS + GPU](docs/README_Ubuntu_CUDA_Acceleration_zh_CN.md) +- [Windows10/11 + GPU](docs/README_Windows_CUDA_Acceleration_zh_CN.md) -### 使用说明 -#### 1. 通过命令行使用 +## 使用 -###### 直接使用 +### 命令行 ```bash -magic-pdf pdf-command --pdf "pdf_path" --inside_model true -``` -程序运行完成后,你可以在"/tmp/magic-pdf"目录下看到生成的markdown文件,markdown目录中可以找到对应的xxx_model.json文件 -如果您有意对后处理pipeline进行二次开发,可以使用命令 -```bash -magic-pdf pdf-command --pdf "pdf_path" --model "model_json_path" +magic-pdf --help +Usage: magic-pdf [OPTIONS] + +Options: + -v, --version display the version and exit + -p, --path PATH local pdf filepath or directory [required] + -o, --output-dir TEXT output local directory + -m, --method [ocr|txt|auto] the method for parsing pdf. + ocr: using ocr technique to extract information from pdf, + txt: suitable for the text-based pdf only and outperform ocr, + auto: automatically choose the best method for parsing pdf + from ocr and txt. + without method specified, auto will be used by default. + --help Show this message and exit. + + +## show version +magic-pdf -v + +## command line example +magic-pdf -p {some_pdf} -o {some_output_dir} -m auto ``` -这样就不需要重跑模型数据,调试起来更方便 -###### 更多用法 - -```bash -magic-pdf --help +其中 `{some_pdf}` 可以是单个pdf文件,也可以是一个包含多个pdf文件的目录。 +运行完命令后输出的结果会保存在`{some_output_dir}`目录下, 输出的文件列表如下 + +```text +├── some_pdf.md # markdown 文件 +├── images # 存放图片目录 +├── layout.pdf # layout 绘图 +├── middle.json # minerU 中间处理结果 +├── model.json # 模型推理结果 +├── origin.pdf # 原 pdf 文件 +└── spans.pdf # 最小粒度的bbox位置信息绘图 ``` +更多有关输出文件的信息,请参考[输出文件说明](docs/output_file_zh_cn.md) -#### 2. 通过接口调用 -###### 本地使用 +### API + +处理本地磁盘上的文件 ```python image_writer = DiskReaderWriter(local_image_dir) image_dir = str(os.path.basename(local_image_dir)) -jso_useful_key = {"_pdf_type": "", "model_list": model_json} +jso_useful_key = {"_pdf_type": "", "model_list": []} pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer) pipe.pipe_classify() +pipe.pipe_analyze() pipe.pipe_parse() md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") ``` -###### 在对象存储上使用 +处理对象存储上的文件 ```python s3pdf_cli = S3ReaderWriter(pdf_ak, pdf_sk, pdf_endpoint) image_dir = "s3://img_bucket/" s3image_cli = S3ReaderWriter(img_ak, img_sk, img_endpoint, parent_path=image_dir) pdf_bytes = s3pdf_cli.read(s3_pdf_path, mode=s3pdf_cli.MODE_BIN) -jso_useful_key = {"_pdf_type": "", "model_list": model_json} +jso_useful_key = {"_pdf_type": "", "model_list": []} pipe = UNIPipe(pdf_bytes, jso_useful_key, s3image_cli) pipe.pipe_classify() +pipe.pipe_analyze() pipe.pipe_parse() md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") ``` -详细实现可参考 [demo.py](demo/demo.py) - +详细实现可参考 +- [demo.py 最简单的处理方式](demo/demo.py) +- [magic_pdf_parse_main.py 能够更清晰看到处理流程](demo/magic_pdf_parse_main.py) -### 常见问题处理解答 -参考 [FAQ](docs/FAQ_zh_cn.md) +### 二次开发 +TODO -# Magic-Doc +# TODO +- [ ] 基于语义的阅读顺序 +- [ ] 正文中列表识别 +- [ ] 正文中代码块识别 +- [ ] 目录识别 +- [x] 表格识别 +- [ ] 化学式识别 +- [ ] 几何图形识别 -## 简介 -Magic-Doc 是一款支持将网页或多格式电子书转换为 markdown 格式的工具。 +# Known Issues +- 阅读顺序基于规则的分割,在一些情况下会乱序 +- 不支持竖排文字 +- 列表、代码块、目录在layout模型里还没有支持 +- 漫画书、艺术图册、小学教材、习题尚不能很好解析 +- 在一些公式密集的PDF上强制启用OCR效果会更好 +- 如果您要处理包含大量公式的pdf,强烈建议开启OCR功能。使用pymuPDF提取文字的时候会出现文本行互相重叠的情况导致公式插入位置不准确。 +- **表格识别**目前处于测试阶段,识别速度较慢,识别准确度有待提升。以下是我们在Ubuntu 22.04 LTS + Intel(R) Xeon(R) Platinum 8352V CPU @ 2.10GHz + NVIDIA GeForce RTX 4090环境下的一些性能测试结果,可供参考。 -主要功能包含 +| 表格大小 | 解析耗时 | +|---------------|----------------------------| +| 6\*5 55kb | 37s | +| 16\*12 284kb | 3m18s | +| 44\*7 559kb | 4m12s | -- Web网页提取 - - 跨模态精准解析图文、表格、公式信息 -- 电子书文献提取 - - 支持 epub,mobi等多格式文献,文本图片全适配 -- 语言类型鉴定 - - 支持176种语言的准确识别 +# FAQ +[常见问题](docs/FAQ_zh_cn.md) -https://github.com/opendatalab/MinerU/assets/11393164/a5a650e9-f4c0-463e-acc3-960967f1a1ca +[FAQ](docs/FAQ.md) - -https://github.com/opendatalab/MinerU/assets/11393164/0f4a6fe9-6cca-4113-9fdc-a537749d764d - - - -https://github.com/opendatalab/MinerU/assets/11393164/20438a02-ce6c-4af8-9dde-d722a4e825b2 - - - - -## 项目仓库 - -- [Magic-Doc](https://github.com/InternLM/magic-doc) - 优秀的网页与电子书提取工具 - - -## 感谢我们的贡献者 +# All Thanks To Our Contributors - -## 版权说明 +# License Information [LICENSE.md](LICENSE.md) 本项目目前采用PyMuPDF以实现高级功能,但因其遵循AGPL协议,可能对某些使用场景构成限制。未来版本迭代中,我们计划探索并替换为许可条款更为宽松的PDF处理库,以提升用户友好度及灵活性。 - -## 致谢 +# Acknowledgments +- [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit) +- [StructEqTable](https://github.com/UniModal4Reasoning/StructEqTable-Deploy) - [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) - [PyMuPDF](https://github.com/pymupdf/PyMuPDF) - [fast-langdetect](https://github.com/LlmKira/fast-langdetect) - [pdfminer.six](https://github.com/pdfminer/pdfminer.six) - -# 引用 +# Citation ```bibtex +@article{he2024opendatalab, + title={Opendatalab: Empowering general artificial intelligence with open datasets}, + author={He, Conghui and Li, Wei and Jin, Zhenjiang and Xu, Chao and Wang, Bin and Lin, Dahua}, + journal={arXiv preprint arXiv:2407.13773}, + year={2024} +} + @misc{2024mineru, title={MinerU: A One-stop, Open-source, High-quality Data Extraction Tool}, author={MinerU Contributors}, @@ -305,7 +375,6 @@ https://github.com/opendatalab/MinerU/assets/11393164/20438a02-ce6c-4af8-9dde-d7 } ``` - # Star History @@ -316,7 +385,14 @@ https://github.com/opendatalab/MinerU/assets/11393164/20438a02-ce6c-4af8-9dde-d7 -## 友情链接 -- [LabelU (轻量级多模态标注工具)](https://github.com/opendatalab/labelU) -- [LabelLLM (开源LLM对话标注平台)](https://github.com/opendatalab/LabelLLM) -- [PDF-Extract-Kit (用于高质量PDF内容提取的综合工具包)](https://github.com/opendatalab/PDF-Extract-Kit)) +# Magic-doc +[Magic-Doc](https://github.com/InternLM/magic-doc) Fast speed ppt/pptx/doc/docx/pdf extraction tool + +# Magic-html +[Magic-HTML](https://github.com/opendatalab/magic-html) Mixed web page extraction tool + +# Links + +- [LabelU (A Lightweight Multi-modal Data Annotation Tool)](https://github.com/opendatalab/labelU) +- [LabelLLM (An Open-source LLM Dialogue Annotation Platform)](https://github.com/opendatalab/LabelLLM) +- [PDF-Extract-Kit (A Comprehensive Toolkit for High-Quality PDF Content Extraction)](https://github.com/opendatalab/PDF-Extract-Kit) diff --git a/README_zh-CN.md.bak b/README_zh-CN.md.bak new file mode 100644 index 00000000..708c140f --- /dev/null +++ b/README_zh-CN.md.bak @@ -0,0 +1,322 @@ +
+

+ +

+
+
+ +[![stars](https://img.shields.io/github/stars/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) +[![forks](https://img.shields.io/github/forks/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) +[![open issues](https://img.shields.io/github/issues-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues) +[![issue resolution](https://img.shields.io/github/issues-closed-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues) +[![PyPI version](https://badge.fury.io/py/magic-pdf.svg)](https://badge.fury.io/py/magic-pdf) +[![Downloads](https://static.pepy.tech/badge/magic-pdf)](https://pepy.tech/project/magic-pdf) +[![Downloads](https://static.pepy.tech/badge/magic-pdf/month)](https://pepy.tech/project/magic-pdf) +opendatalab%2FMinerU | Trendshift + +[English](README.md) | [简体中文](README_zh-CN.md) | [日本語](README_ja-JP.md) + +
+ +
+

+MinerU: 端到端的PDF解析工具(基于PDF-Extract-Kit)支持PDF转Markdown🚀🚀🚀
+PDF-Extract-Kit: 高质量PDF解析工具箱🔥🔥🔥 +

+ +

+ 👋 join us on Discord and WeChat +

+
+ +# MinerU + + +## 简介 + +MinerU 是一款一站式、开源、高质量的数据提取工具,主要包含以下功能: + +- [Magic-PDF](#Magic-PDF) PDF文档提取 +- [Magic-Doc](#Magic-Doc) 网页与电子书提取 + +# Magic-PDF + + +## 简介 + +Magic-PDF 是一款将 PDF 转化为 markdown 格式的工具。支持转换本地文档或者位于支持S3协议对象存储上的文件。 + +主要功能包含 + +- 支持多种前端模型输入 +- 删除页眉、页脚、脚注、页码等元素 +- 符合人类阅读顺序的排版格式 +- 保留原文档的结构和格式,包括标题、段落、列表等 +- 提取图像和表格并在markdown中展示 +- 将公式转换成latex +- 乱码PDF自动识别并转换 +- 支持cpu和gpu环境 +- 支持windows/linux/mac平台 + + +https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c + + + +## 项目全景 + +![项目全景图](docs/images/project_panorama_zh_cn.png) + +## 流程图 + +![流程图](docs/images/flowchart_zh_cn.png) + +### 子模块仓库 + +- [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit) + - 高质量的PDF内容提取工具包 + +## 上手指南 + +### 配置要求 + +python >= 3.9 + +推荐使用虚拟环境,以避免可能发生的依赖冲突,venv和conda均可使用。 +例如: +```bash +conda create -n MinerU python=3.10 +conda activate MinerU +``` +开发基于python 3.10,如果在其他版本python出现问题请切换至3.10。 + +### 安装配置 + +#### 1. 安装Magic-PDF + +**1.安装依赖** + +完整功能包依赖detectron2,该库需要编译安装,如需自行编译,请参考 https://github.com/facebookresearch/detectron2/issues/5114 +或是直接使用我们预编译的whl包: +> ❗️预编译版本仅支持64位系统(windows/linux/macOS)+pyton 3.10平台;不支持任何32位系统和非mac的arm平台,如系统不支持请自行编译安装。 +```bash +pip install detectron2 --extra-index-url https://wheels.myhloli.com -i https://pypi.tuna.tsinghua.edu.cn/simple +``` + +**2.使用pip安装完整功能包** +> 受pypi限制,pip安装的完整功能包仅支持cpu推理,建议只用于快速测试解析能力。 +> +> 如需在生产环境使用CUDA/MPS加速请参考[使用CUDA或MPS加速推理](#4-使用CUDA或MPS加速推理) +```bash +pip install magic-pdf[full]==0.6.2b1 -i https://pypi.tuna.tsinghua.edu.cn/simple +``` +> ❗️❗️❗️ +> 我们预发布了0.6.2beta版本,该版本解决了很多issue中提出的问题,同时提高了安装成功率。但是该版本未经过完整的QA测试,不代表最终正式发布的质量水平。如果你遇到任何问题,请通过提交issue的方式及时向我们反馈,或者回退到使用0.6.1版本。 +> ```bash +> pip install magic-pdf[full-cpu]==0.6.1 +> ``` + + + +#### 2. 下载模型权重文件 + +详细参考 [如何下载模型文件](docs/how_to_download_models_zh_cn.md) +> ❗️模型下载后请务必检查模型文件是否下载完整 +> +> 请检查目录下的模型文件大小与网页上描述是否一致,如果可以的话,最好通过sha256校验模型是否下载完整 + +#### 3. 拷贝配置文件并进行配置 +在仓库根目录可以获得 [magic-pdf.template.json](magic-pdf.template.json) 配置模版文件 +> ❗️务必执行以下命令将配置文件拷贝到【用户目录】下,否则程序将无法运行 +> +> windows的用户目录为 "C:\Users\用户名", linux用户目录为 "/home/用户名", macOS用户目录为 "/Users/用户名" +```bash +cp magic-pdf.template.json ~/magic-pdf.json +``` + +在用户目录中找到magic-pdf.json文件并配置"models-dir"为[2. 下载模型权重文件](#2-下载模型权重文件)中下载的模型权重文件所在目录 +> ❗️务必正确配置模型权重文件所在目录的【绝对路径】,否则会因为找不到模型文件而导致程序无法运行 +> +> windows系统中此路径应包含盘符,且需把路径中所有的"\"替换为"/",否则会因为转义原因导致json文件语法错误。 +> +> 例如:模型放在D盘根目录的models目录,则model-dir的值应为"D:/models" +```json +{ + "models-dir": "/tmp/models" +} +``` + +#### 4. 使用CUDA或MPS加速推理 +如您有可用的Nvidia显卡或在使用Apple Silicon的Mac,可以使用CUDA或MPS进行加速 +##### CUDA + +需要根据自己的CUDA版本安装对应的pytorch版本 +以下是对应CUDA 11.8版本的安装命令,更多信息请参考 https://pytorch.org/get-started/locally/ +```bash +pip install --force-reinstall torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu118 +``` +> ❗️务必在命令中指定以下版本 +> ```bash +> torch==2.3.1 torchvision==0.18.1 +> ``` +> 这是我们支持的最高版本,如果不指定版本会自动安装更高版本导致程序无法运行 + + +同时需要修改【用户目录】中配置文件magic-pdf.json中"device-mode"的值 +```json +{ + "device-mode":"cuda" +} +``` + +##### MPS +使用macOS(M系列芯片设备)可以使用MPS进行推理加速 +需要修改配置文件magic-pdf.json中"device-mode"的值 +```json +{ + "device-mode":"mps" +} +``` + + +### 使用说明 + +#### 1. 通过命令行使用 + +###### 直接使用 + +```bash +magic-pdf pdf-command --pdf "pdf_path" --inside_model true +``` +程序运行完成后,你可以在"/tmp/magic-pdf"目录下看到生成的markdown文件,markdown目录中可以找到对应的xxx_model.json文件 +如果您有意对后处理pipeline进行二次开发,可以使用命令 +```bash +magic-pdf pdf-command --pdf "pdf_path" --model "model_json_path" +``` +这样就不需要重跑模型数据,调试起来更方便 + +###### 更多用法 + +```bash +magic-pdf --help +``` + + +#### 2. 通过接口调用 + +###### 本地使用 +```python +image_writer = DiskReaderWriter(local_image_dir) +image_dir = str(os.path.basename(local_image_dir)) +jso_useful_key = {"_pdf_type": "", "model_list": model_json} +pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer) +pipe.pipe_classify() +pipe.pipe_parse() +md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") +``` + +###### 在对象存储上使用 +```python +s3pdf_cli = S3ReaderWriter(pdf_ak, pdf_sk, pdf_endpoint) +image_dir = "s3://img_bucket/" +s3image_cli = S3ReaderWriter(img_ak, img_sk, img_endpoint, parent_path=image_dir) +pdf_bytes = s3pdf_cli.read(s3_pdf_path, mode=s3pdf_cli.MODE_BIN) +jso_useful_key = {"_pdf_type": "", "model_list": model_json} +pipe = UNIPipe(pdf_bytes, jso_useful_key, s3image_cli) +pipe.pipe_classify() +pipe.pipe_parse() +md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") +``` + +详细实现可参考 [demo.py](demo/demo.py) + + +### 常见问题处理解答 + +参考 [FAQ](docs/FAQ_zh_cn.md) + + +# Magic-Doc + + +## 简介 + +Magic-Doc 是一款支持将网页或多格式电子书转换为 markdown 格式的工具。 + +主要功能包含 + +- Web网页提取 + - 跨模态精准解析图文、表格、公式信息 + +- 电子书文献提取 + - 支持 epub,mobi等多格式文献,文本图片全适配 + +- 语言类型鉴定 + - 支持176种语言的准确识别 + +https://github.com/opendatalab/MinerU/assets/11393164/a5a650e9-f4c0-463e-acc3-960967f1a1ca + + + +https://github.com/opendatalab/MinerU/assets/11393164/0f4a6fe9-6cca-4113-9fdc-a537749d764d + + + +https://github.com/opendatalab/MinerU/assets/11393164/20438a02-ce6c-4af8-9dde-d722a4e825b2 + + + + +## 项目仓库 + +- [Magic-Doc](https://github.com/InternLM/magic-doc) + 优秀的网页与电子书提取工具 + + +## 感谢我们的贡献者 + + + + + + +## 版权说明 + +[LICENSE.md](LICENSE.md) + +本项目目前采用PyMuPDF以实现高级功能,但因其遵循AGPL协议,可能对某些使用场景构成限制。未来版本迭代中,我们计划探索并替换为许可条款更为宽松的PDF处理库,以提升用户友好度及灵活性。 + + +## 致谢 +- [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) +- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) +- [fast-langdetect](https://github.com/LlmKira/fast-langdetect) +- [pdfminer.six](https://github.com/pdfminer/pdfminer.six) + + +# 引用 + +```bibtex +@misc{2024mineru, + title={MinerU: A One-stop, Open-source, High-quality Data Extraction Tool}, + author={MinerU Contributors}, + howpublished = {\url{https://github.com/opendatalab/MinerU}}, + year={2024} +} +``` + + +# Star History + + + + + + Star History Chart + + + +## 友情链接 +- [LabelU (轻量级多模态标注工具)](https://github.com/opendatalab/labelU) +- [LabelLLM (开源LLM对话标注平台)](https://github.com/opendatalab/LabelLLM) +- [PDF-Extract-Kit (用于高质量PDF内容提取的综合工具包)](https://github.com/opendatalab/PDF-Extract-Kit)) diff --git a/README_zh-CN_v2.md b/README_zh-CN_v2.md deleted file mode 100644 index 16aee115..00000000 --- a/README_zh-CN_v2.md +++ /dev/null @@ -1,398 +0,0 @@ -
- -

- -

- - - -[![stars](https://img.shields.io/github/stars/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) -[![forks](https://img.shields.io/github/forks/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU) -[![open issues](https://img.shields.io/github/issues-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues) -[![issue resolution](https://img.shields.io/github/issues-closed-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues) -[![PyPI version](https://badge.fury.io/py/magic-pdf.svg)](https://badge.fury.io/py/magic-pdf) -[![Downloads](https://static.pepy.tech/badge/magic-pdf)](https://pepy.tech/project/magic-pdf) -[![Downloads](https://static.pepy.tech/badge/magic-pdf/month)](https://pepy.tech/project/magic-pdf) -opendatalab%2FMinerU | Trendshift - - -[English](README.md) | [简体中文](README_zh-CN.md) - - - -

-PDF-Extract-Kit: 高质量PDF解析工具箱🔥🔥🔥 -

- - -

- 👋 join us on Discord and WeChat -

- -
- - -# 更新记录 -- 2024/08/09 0.7.0b1发布,简化安装步骤提升易用性,加入表格识别功能 -- 2024/08/01 0.6.2b1发布,优化了依赖冲突问题和安装文档 -- 2024/07/05 首次开源 - - - -
-

文档目录

-
    -
  1. - MinerU - -
  2. -
  3. TODO
  4. -
  5. Known Issues
  6. -
  7. FAQ
  8. -
  9. Contributors
  10. -
  11. License Information
  12. -
  13. Acknowledgements
  14. -
  15. Citation
  16. -
  17. Star History
  18. -
  19. magic-doc快速提取PPT/DOC/PDF
  20. -
  21. magic-html提取混合网页内容
  22. -
  23. Links
  24. -
-
- - - -# MinerU -## 项目简介 -MinerU是一款将PDF转化为机器可读格式的工具(如markdown、json),可以很方便地抽取为任意格式。 -MinerU诞生于[书生-浦语](https://github.com/InternLM/InternLM)的预训练过程中,我们将会集中精力解决科技文献中的符号转化问题,希望在大模型时代为科技发展做出贡献。 -相比国内外知名商用产品MinerU还很年轻,如果遇到问题或者结果不及预期请到[issue](https://github.com/opendatalab/MinerU/issues)提交问题,同时**附上相关PDF**。 - -https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c - -## 主要功能 - -- 删除页眉、页脚、脚注、页码等元素,保持语义连贯 -- 对多栏输出符合人类阅读顺序的文本 -- 保留原文档的结构,包括标题、段落、列表等 -- 提取图像、图片标题、表格、表格标题 -- 自动识别文档中的公式并将公式转换成latex -- 自动识别文档中的表格并将表格转换成latex -- 乱码PDF自动检测并启用OCR -- 支持CPU和GPU环境 -- 支持windows/linux/mac平台 - - -## 快速开始 - -如果遇到任何安装问题,请先查询 FAQ
-如果遇到解析效果不及预期,参考 Known Issues
-有3种不同方式可以体验MinerU的效果: -- [在线体验(无需任何安装)](#在线体验) -- [使用CPU快速体验(Windows,Linux,Mac)](#使用cpu快速体验) -- [Linux/Windows + CUDA](#使用gpu) - - -**⚠️安装前必看——软硬件环境支持说明** - -为了确保项目的稳定性和可靠性,我们在开发过程中仅对特定的软硬件环境进行优化和测试。这样当用户在推荐的系统配置上部署和运行项目时,能够获得最佳的性能表现和最少的兼容性问题。 - -通过集中资源和精力于主线环境,我们团队能够更高效地解决潜在的BUG,及时开发新功能。 - -在非主线环境中,由于硬件、软件配置的多样性,以及第三方依赖项的兼容性问题,我们无法100%保证项目的完全可用性。因此,对于希望在非推荐环境中使用本项目的用户,我们建议先仔细阅读文档以及FAQ,大多数问题已经在FAQ中有对应的解决方案,除此之外我们鼓励社区反馈问题,以便我们能够逐步扩大支持范围。 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
操作系统
Ubuntu 22.04 LTSWindows 10 / 11macOS 11+
CPUx86_64x86_64x86_64 / arm64
内存大于等于16GB,推荐32G以上
python版本3.10
Nvidia Driver 版本latest(专有驱动)latestNone
CUDA环境自动安装[12.1(pytorch)+11.8(paddle)]11.8(手动安装)+cuDNN v8.7.0(手动安装)None
GPU硬件支持列表最低要求 8G+显存3060ti/3070/3080/3080ti/4060/4070/4070ti
- 8G显存仅可开启lavout和公式识别加速
None
推荐配置 16G+显存3090/3090ti/4070tisuper/4080/4090
- 16G及以上可以同时开启layout,公式识别和ocr加速
- -### 在线体验 - -[在线体验点击这里](https://opendatalab.com/OpenSourceTools/Extractor/PDF) - - -### 使用CPU快速体验 - -#### 1. 安装magic-pdf -最新版本国内镜像源同步可能会有延迟,请耐心等待 -```bash -conda create -n MinerU python=3.10 -conda activate MinerU -pip install magic-pdf[full]==0.7.0b1 --extra-index-url https://wheels.myhloli.com -i https://pypi.tuna.tsinghua.edu.cn/simple -``` -#### 2. 下载模型权重文件 - -详细参考 [如何下载模型文件](docs/how_to_download_models_zh_cn.md) -> ❗️模型下载后请务必检查模型文件是否下载完整 -> -> 请检查目录下的模型文件大小与网页上描述是否一致,如果可以的话,最好通过sha256校验模型是否下载完整 - -#### 3. 拷贝配置文件并进行配置 -在仓库根目录可以获得 [magic-pdf.template.json](magic-pdf.template.json) 配置模版文件 -> ❗️务必执行以下命令将配置文件拷贝到【用户目录】下,否则程序将无法运行 -> -> windows的用户目录为 "C:\Users\用户名", linux用户目录为 "/home/用户名", macOS用户目录为 "/Users/用户名" -```bash -cp magic-pdf.template.json ~/magic-pdf.json -``` - -在用户目录中找到magic-pdf.json文件并配置"models-dir"为[2. 下载模型权重文件](#2-下载模型权重文件)中下载的模型权重文件所在目录 -> ❗️务必正确配置模型权重文件所在目录的【绝对路径】,否则会因为找不到模型文件而导致程序无法运行 -> -> windows系统中此路径应包含盘符,且需把路径中所有的"\"替换为"/",否则会因为转义原因导致json文件语法错误。 -> -> 例如:模型放在D盘根目录的models目录,则model-dir的值应为"D:/models" -```json -{ - // other config - "models-dir": "D:/models", - "table-config": { - "is_table_recog_enable": false, // 表格识别功能默认是关闭的,如果需要修改此处的值 - "max_time": 400 - } -} -``` - - -### 使用GPU -如果您的设备支持CUDA,且满足主线环境中的显卡要求,则可以使用GPU加速,请根据自己的系统选择适合的教程: - -- [Ubuntu22.04LTS + GPU](docs/README_Ubuntu_CUDA_Acceleration_zh_CN.md) -- [Windows10/11 + GPU](docs/README_Windows_CUDA_Acceleration_zh_CN.md) - - -## 使用 - -### 命令行 - -```bash -magic-pdf --help -Usage: magic-pdf [OPTIONS] - -Options: - -v, --version display the version and exit - -p, --path PATH local pdf filepath or directory [required] - -o, --output-dir TEXT output local directory - -m, --method [ocr|txt|auto] the method for parsing pdf. - ocr: using ocr technique to extract information from pdf, - txt: suitable for the text-based pdf only and outperform ocr, - auto: automatically choose the best method for parsing pdf - from ocr and txt. - without method specified, auto will be used by default. - --help Show this message and exit. - - -## show version -magic-pdf -v - -## command line example -magic-pdf -p {some_pdf} -o {some_output_dir} -m auto -``` - -其中 `{some_pdf}` 可以是单个pdf文件,也可以是一个包含多个pdf文件的目录。 -运行完命令后输出的结果会保存在`{some_output_dir}`目录下, 输出的文件列表如下 - -```text -├── some_pdf.md # markdown 文件 -├── images # 存放图片目录 -├── layout.pdf # layout 绘图 -├── middle.json # minerU 中间处理结果 -├── model.json # 模型推理结果 -├── origin.pdf # 原 pdf 文件 -└── spans.pdf # 最小粒度的bbox位置信息绘图 -``` - -更多有关输出文件的信息,请参考[输出文件说明](docs/output_file_zh_cn.md) - - -### API - -处理本地磁盘上的文件 -```python -image_writer = DiskReaderWriter(local_image_dir) -image_dir = str(os.path.basename(local_image_dir)) -jso_useful_key = {"_pdf_type": "", "model_list": []} -pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer) -pipe.pipe_classify() -pipe.pipe_analyze() -pipe.pipe_parse() -md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") -``` - -处理对象存储上的文件 -```python -s3pdf_cli = S3ReaderWriter(pdf_ak, pdf_sk, pdf_endpoint) -image_dir = "s3://img_bucket/" -s3image_cli = S3ReaderWriter(img_ak, img_sk, img_endpoint, parent_path=image_dir) -pdf_bytes = s3pdf_cli.read(s3_pdf_path, mode=s3pdf_cli.MODE_BIN) -jso_useful_key = {"_pdf_type": "", "model_list": []} -pipe = UNIPipe(pdf_bytes, jso_useful_key, s3image_cli) -pipe.pipe_classify() -pipe.pipe_analyze() -pipe.pipe_parse() -md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none") -``` - -详细实现可参考 -- [demo.py 最简单的处理方式](demo/demo.py) -- [magic_pdf_parse_main.py 能够更清晰看到处理流程](demo/magic_pdf_parse_main.py) - - -### 二次开发 - -TODO - -# TODO - -- [ ] 基于语义的阅读顺序 -- [ ] 正文中列表识别 -- [ ] 正文中代码块识别 -- [ ] 目录识别 -- [x] 表格识别 -- [ ] 化学式识别 -- [ ] 几何图形识别 - - -# Known Issues -- 阅读顺序基于规则的分割,在一些情况下会乱序 -- 不支持竖排文字 -- 列表、代码块、目录在layout模型里还没有支持 -- 漫画书、艺术图册、小学教材、习题尚不能很好解析 -- 在一些公式密集的PDF上强制启用OCR效果会更好 -- 如果您要处理包含大量公式的pdf,强烈建议开启OCR功能。使用pymuPDF提取文字的时候会出现文本行互相重叠的情况导致公式插入位置不准确。 -- **表格识别**目前处于测试阶段,识别速度较慢,识别准确度有待提升。以下是我们在Ubuntu 22.04 LTS + Intel(R) Xeon(R) Platinum 8352V CPU @ 2.10GHz + NVIDIA GeForce RTX 4090环境下的一些性能测试结果,可供参考。 - -| 表格大小 | 解析耗时 | -|---------------|----------------------------| -| 6\*5 55kb | 37s | -| 16\*12 284kb | 3m18s | -| 44\*7 559kb | 4m12s | - - - -# FAQ -[常见问题](docs/FAQ_zh_cn.md) - -[FAQ](docs/FAQ.md) - - -# All Thanks To Our Contributors - - - - - -# License Information - -[LICENSE.md](LICENSE.md) - -本项目目前采用PyMuPDF以实现高级功能,但因其遵循AGPL协议,可能对某些使用场景构成限制。未来版本迭代中,我们计划探索并替换为许可条款更为宽松的PDF处理库,以提升用户友好度及灵活性。 - -# Acknowledgments -- [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit) -- [StructEqTable](https://github.com/UniModal4Reasoning/StructEqTable-Deploy) -- [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) -- [PyMuPDF](https://github.com/pymupdf/PyMuPDF) -- [fast-langdetect](https://github.com/LlmKira/fast-langdetect) -- [pdfminer.six](https://github.com/pdfminer/pdfminer.six) - -# Citation - -```bibtex -@article{he2024opendatalab, - title={Opendatalab: Empowering general artificial intelligence with open datasets}, - author={He, Conghui and Li, Wei and Jin, Zhenjiang and Xu, Chao and Wang, Bin and Lin, Dahua}, - journal={arXiv preprint arXiv:2407.13773}, - year={2024} -} - -@misc{2024mineru, - title={MinerU: A One-stop, Open-source, High-quality Data Extraction Tool}, - author={MinerU Contributors}, - howpublished = {\url{https://github.com/opendatalab/MinerU}}, - year={2024} -} -``` - -# Star History - - - - - - Star History Chart - - - -# Magic-doc -[Magic-Doc](https://github.com/InternLM/magic-doc) Fast speed ppt/pptx/doc/docx/pdf extraction tool - -# Magic-html -[Magic-HTML](https://github.com/opendatalab/magic-html) Mixed web page extraction tool - -# Links - -- [LabelU (A Lightweight Multi-modal Data Annotation Tool)](https://github.com/opendatalab/labelU) -- [LabelLLM (An Open-source LLM Dialogue Annotation Platform)](https://github.com/opendatalab/LabelLLM) -- [PDF-Extract-Kit (A Comprehensive Toolkit for High-Quality PDF Content Extraction)](https://github.com/opendatalab/PDF-Extract-Kit)