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
Merge branch 'master' into release-0.9.0
Xiaomeng Zhao140247931662
diff --cc README.mdindex d396dedd,9df61a28..82bcc84b--- a/README.md+++ b/README.md@@@ -18,8 -18,8 +18,10 @@@[](https://huggingface.co/spaces/opendatalab/MinerU)[](https://www.modelscope.cn/studios/OpenDataLab/MinerU)[](https://colab.research.google.com/gist/papayalove/b5f4913389e7ff9883c6b687de156e78/mineru_demo.ipynb)- [](https://arxiv.org/pdf/2409.18839?)+++ [](https://arxiv.org/abs/2409.18839)++<a href="https://trendshift.io/repositories/11174" target="_blank"><img src="https://trendshift.io/api/badge/repositories/11174" alt="opendatalab%2FMinerU | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a><!-- language -->@@@ -226,6 -207,6 +228,7 @@@ You can find the `magic-pdf.json` fileYou can modify certain configurations in this file to enable or disable features, such as table recognition:++> If the following items are not present in the JSON, please manually add the required items and remove the comment content (standard JSON does not support comments).```jsondiff --cc README_zh-CN.mdindex 0bea8556,7b4c4e89..783f8963--- a/README_zh-CN.md+++ b/README_zh-CN.md@@@ -18,8 -18,8 +18,9 @@@[](https://www.modelscope.cn/studios/OpenDataLab/MinerU)[](https://huggingface.co/spaces/opendatalab/MinerU)[](https://colab.research.google.com/gist/papayalove/b5f4913389e7ff9883c6b687de156e78/mineru_demo.ipynb)- [](https://arxiv.org/pdf/2409.18839?)+ [](https://arxiv.org/abs/2409.18839)++<a href="https://trendshift.io/repositories/11174" target="_blank"><img src="https://trendshift.io/api/badge/repositories/11174" alt="opendatalab%2FMinerU | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a><!-- language -->diff --cc docs/README_Ubuntu_CUDA_Acceleration_en_US.mdindex 010cc729,066bbd72..45abe97b--- a/docs/README_Ubuntu_CUDA_Acceleration_en_US.md+++ b/docs/README_Ubuntu_CUDA_Acceleration_en_US.md@@@ -1,97 -1,76 +1,100 @@@# Ubuntu 22.04 LTS### 1. Check if NVIDIA Drivers Are Installed- ```sh- nvidia-smi- ```- If you see information similar to the following, it means that the NVIDIA drivers are already installed, and you can skip Step 2.- ```plaintext- +---------------------------------------------------------------------------------------+- | NVIDIA-SMI 537.34 Driver Version: 537.34 CUDA Version: 12.2 |- |-----------------------------------------+----------------------+----------------------+- | GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |- | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |- | | | MIG M. |- |=========================================+======================+======================|- | 0 NVIDIA GeForce RTX 3060 Ti WDDM | 00000000:01:00.0 On | N/A |- | 0% 51C P8 12W / 200W | 1489MiB / 8192MiB | 5% Default |- | | | N/A |- +-----------------------------------------+----------------------+----------------------+- ```++```sh+nvidia-smi+```++If you see information similar to the following, it means that the NVIDIA drivers are already installed, and you can skip Step 2.++Notice:`CUDA Version` should be >= 12.1, If the displayed version number is less than 12.1, please upgrade the driver.++```plaintext++---------------------------------------------------------------------------------------++| NVIDIA-SMI 537.34 Driver Version: 537.34 CUDA Version: 12.2 |+|-----------------------------------------+----------------------+----------------------++| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |+| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |+| | | MIG M. |+|=========================================+======================+======================|+| 0 NVIDIA GeForce RTX 3060 Ti WDDM | 00000000:01:00.0 On | N/A |+| 0% 51C P8 12W / 200W | 1489MiB / 8192MiB | 5% Default |+| | | N/A |++-----------------------------------------+----------------------+----------------------++```### 2. Install the Driver- If no driver is installed, use the following command:- ```sh- sudo apt-get update- sudo apt-get install nvidia-driver-545- ```- Install the proprietary driver and restart your computer after installation.- ```sh- reboot- ```++If no driver is installed, use the following command:++```sh+sudo apt-get update+sudo apt-get install nvidia-driver-545+```++Install the proprietary driver and restart your computer after installation.++```sh+reboot+```### 3. Install Anaconda- If Anaconda is already installed, skip this step.- ```sh- wget https://repo.anaconda.com/archive/Anaconda3-2024.06-1-Linux-x86_64.sh- bash Anaconda3-2024.06-1-Linux-x86_64.sh- ```- In the final step, enter `yes`, close the terminal, and reopen it.++If Anaconda is already installed, skip this step.++```sh+wget https://repo.anaconda.com/archive/Anaconda3-2024.06-1-Linux-x86_64.sh+bash Anaconda3-2024.06-1-Linux-x86_64.sh+```++In the final step, enter `yes`, close the terminal, and reopen it.### 4. Create an Environment Using Conda- Specify Python version 3.10.- ```sh- conda create -n MinerU python=3.10- conda activate MinerU- ```++Specify Python version 3.10.++```sh+conda create -n MinerU python=3.10+conda activate MinerU+```### 5. Install Applications- ```sh- pip install -U magic-pdf[full] --extra-index-url https://wheels.myhloli.com- ```++```sh+pip install -U magic-pdf[full] --extra-index-url https://wheels.myhloli.com+```+❗ After installation, make sure to check the version of `magic-pdf` using the following command:- ```sh- magic-pdf --version- ```- If the version number is less than 0.7.0, please report the issue.++```sh+magic-pdf --version+```++If the version number is less than 0.7.0, please report the issue.### 6. Download Models- Refer to detailed instructions on [how to download model files](how_to_download_models_en.md).++++Refer to detailed instructions on [how to download model files](how_to_download_models_en.md).++## 7. Understand the Location of the Configuration FileAfter completing the [6. Download Models](#6-download-models) step, the script will automatically generate a `magic-pdf.json` file in the user directory and configure the default model path.You can find the `magic-pdf.json` file in your user directory.+> The user directory for Linux is "/home/username".++### 8. First Run- Download a sample file from the repository and test it.- ```sh- wget https://github.com/opendatalab/MinerU/raw/master/demo/small_ocr.pdf- magic-pdf -p small_ocr.pdf- ```++Download a sample file from the repository and test it.++```sh+wget https://github.com/opendatalab/MinerU/raw/master/demo/small_ocr.pdf+magic-pdf -p small_ocr.pdf+```### 9. Test CUDA Accelerationdiff --cc docs/README_Ubuntu_CUDA_Acceleration_zh_CN.mdindex e64b0220,50eb2da7..e685051a--- a/docs/README_Ubuntu_CUDA_Acceleration_zh_CN.md+++ b/docs/README_Ubuntu_CUDA_Acceleration_zh_CN.md@@@ -75,14 -53,11 +75,16 @@@ pip install -U magic-pdf[full] --extra-> 如果版本号小于0.7.0,请到issue中向我们反馈## 6. 下载模型+++详细参考 [如何下载模型文件](how_to_download_models_zh_cn.md)## 7. 了解配置文件存放的位置+完成[6.下载模型](#6-下载模型)步骤后,脚本会自动生成用户目录下的magic-pdf.json文件,并自动配置默认模型路径。-您可在【用户目录】下找到magic-pdf.json文件。+您可在【用户目录】下找到magic-pdf.json文件。+++> linux用户目录为 "/home/用户名"## 8. 第一次运行diff --cc docs/README_Windows_CUDA_Acceleration_en_US.mdindex e258011d,e74bfee1..5a911895--- a/docs/README_Windows_CUDA_Acceleration_en_US.md+++ b/docs/README_Windows_CUDA_Acceleration_en_US.md@@@ -48,53 -37,43 +48,54 @@@ You can find the `magic-pdf.json` file> The user directory for Windows is "C:/Users/username".### 7. First Run- Download a sample file from the repository and test it.- ```powershell- (New-Object System.Net.WebClient).DownloadFile('https://github.com/opendatalab/MinerU/raw/master/demo/small_ocr.pdf', 'small_ocr.pdf')- magic-pdf -p small_ocr.pdf- ```++Download a sample file from the repository and test it.++```powershell+ wget https://github.com/opendatalab/MinerU/raw/master/demo/small_ocr.pdf -O small_ocr.pdf+ magic-pdf -p small_ocr.pdf+```### 8. Test CUDA Acceleration- If your graphics card has at least 8GB of VRAM, follow these steps to test CUDA-accelerated parsing performance.- 1. **Overwrite the installation of torch and torchvision** supporting CUDA.- ```- pip install --force-reinstall torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu118- ```- >❗️Ensure the following versions are specified in the command:- >```- > torch==2.3.1 torchvision==0.18.1- >```- >These are the highest versions we support. Installing higher versions without specifying them will cause the program to fail.- 2. **Modify the value of `"device-mode"`** in the `magic-pdf.json` configuration file located in your user directory.-- ```json- {- "device-mode": "cuda"- }- ```- 3. **Run the following command to test CUDA acceleration**:-- ```- magic-pdf -p small_ocr.pdf- ```++If your graphics card has at least 8GB of VRAM, follow these steps to test CUDA-accelerated parsing performance.++1. **Overwrite the installation of torch and torchvision** supporting CUDA.++ ```+ pip install --force-reinstall torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu118+ ```++ > ❗️Ensure the following versions are specified in the command:+ >+ > ```+ > torch==2.3.1 torchvision==0.18.1+ > ```+ >+ > These are the highest versions we support. Installing higher versions without specifying them will cause the program to fail.++2. **Modify the value of `"device-mode"`** in the `magic-pdf.json` configuration file located in your user directory.++ ```json+ {+ "device-mode": "cuda"+ }+ ```++++3. **Run the following command to test CUDA acceleration**:++ ```+ magic-pdf -p small_ocr.pdf+ ```### 9. Enable CUDA Acceleration for OCR- >❗️This operation requires at least 16GB of VRAM on your graphics card, otherwise it will cause the program to crash or slow down.- 1. **Download paddlepaddle-gpu**, which will automatically enable OCR acceleration upon installation.- ```- pip install paddlepaddle-gpu==2.6.1- ```- 2. **Run the following command to test OCR acceleration**:- ```- magic-pdf -p small_ocr.pdf- ```++1. **Download paddlepaddle-gpu**, which will automatically enable OCR acceleration upon installation.+ ```+ pip install paddlepaddle-gpu==2.6.1+ ```+2. **Run the following command to test OCR acceleration**:+ ```+ magic-pdf -p small_ocr.pdf+ ```diff --cc docs/README_Windows_CUDA_Acceleration_zh_CN.mdindex a8647aac,11218551..8ac72787--- a/docs/README_Windows_CUDA_Acceleration_zh_CN.md+++ b/docs/README_Windows_CUDA_Acceleration_zh_CN.md@@@ -42,10 -33,8 +42,11 @@@ pip install -U magic-pdf[full] --extra-详细参考 [如何下载模型文件](how_to_download_models_zh_cn.md)## 6. 了解配置文件存放的位置+完成[5.下载模型](#5-下载模型)步骤后,脚本会自动生成用户目录下的magic-pdf.json文件,并自动配置默认模型路径。您可在【用户目录】下找到magic-pdf.json文件。+++> windows用户目录为 "C:/Users/用户名"## 7. 第一次运行diff --cc docs/download_models.pyindex ed1ee5c3,6b864eb6..6c79db19--- a/docs/download_models.py+++ b/docs/download_models.py@@@ -1,7 -1,6 +1,8 @@@+++import jsonimport os+import requests-import jsonfrom modelscope import snapshot_download@@@ -15,12 -7,14 +16,13 @@@ def download_json(url)def download_and_modify_json(url, local_filename, modifications):if os.path.exists(local_filename):data = json.load(open(local_filename))+ config_version = data.get('config_version', '0.0.0')+ if config_version < '1.0.0':+ data = download_json(url)else:- # 下载JSON文件- response = requests.get(url)- response.raise_for_status() # 检查请求是否成功+ data = download_json(url)- # 解析JSON内容- data = response.json()+# 修改内容for key, value in modifications.items():data[key] = value@@@ -31,23 -25,15 +33,25 @@@if __name__ == '__main__':- model_dir = snapshot_download('opendatalab/PDF-Extract-Kit')+++ mineru_patterns = [+ "models/Layout/LayoutLMv3/*",+ "models/Layout/YOLO/*",+ "models/MFD/YOLO/*",+ "models/MFR/unimernet_small/*",+ "models/TabRec/TableMaster/*",+ "models/TabRec/StructEqTable/*",+ ]+ model_dir = snapshot_download('opendatalab/PDF-Extract-Kit-1.0', allow_patterns=mineru_patterns)layoutreader_model_dir = snapshot_download('ppaanngggg/layoutreader')- model_dir = model_dir + "/models"- print(f"model_dir is: {model_dir}")- print(f"layoutreader_model_dir is: {layoutreader_model_dir}")+ model_dir = model_dir + '/models'+ print(f'model_dir is: {model_dir}')+ print(f'layoutreader_model_dir is: {layoutreader_model_dir}')++ json_url = 'https://gitee.com/myhloli/MinerU/raw/dev/magic-pdf.template.json'+ config_file_name = 'magic-pdf.json'+ home_dir = os.path.expanduser('~')+- json_url = 'https://gitee.com/myhloli/MinerU/raw/master/magic-pdf.template.json'- config_file_name = "magic-pdf.json"- home_dir = os.path.expanduser("~")config_file = os.path.join(home_dir, config_file_name)json_mods = {@@@ -56,4 -42,4 +60,6 @@@}download_and_modify_json(json_url, config_file, json_mods)- print(f"The configuration file has been configured successfully, the path is: {config_file}")+++ print(f'The configuration file has been configured successfully, the path is: {config_file}')++diff --cc docs/download_models_hf.pyindex 5e6b8dce,0aa28bad..9dfda1e5--- a/docs/download_models_hf.py+++ b/docs/download_models_hf.py@@@ -15,12 -7,14 +15,13 @@@ def download_json(url)def download_and_modify_json(url, local_filename, modifications):if os.path.exists(local_filename):data = json.load(open(local_filename))+ config_version = data.get('config_version', '0.0.0')+ if config_version < '1.0.0':+ data = download_json(url)else:- # 下载JSON文件- response = requests.get(url)- response.raise_for_status() # 检查请求是否成功+ data = download_json(url)- # 解析JSON内容- data = response.json()+# 修改内容for key, value in modifications.items():data[key] = value@@@ -31,30 -25,15 +32,31 @@@if __name__ == '__main__':- model_dir = snapshot_download('opendatalab/PDF-Extract-Kit')- layoutreader_model_dir = snapshot_download('hantian/layoutreader')- model_dir = model_dir + "/models"- print(f"model_dir is: {model_dir}")- print(f"layoutreader_model_dir is: {layoutreader_model_dir}")-- json_url = 'https://github.com/opendatalab/MinerU/raw/master/magic-pdf.template.json'- config_file_name = "magic-pdf.json"- home_dir = os.path.expanduser("~")++ mineru_patterns = [+ "models/Layout/LayoutLMv3/*",+ "models/Layout/YOLO/*",+ "models/MFD/YOLO/*",+ "models/MFR/unimernet_small/*",+ "models/TabRec/TableMaster/*",+ "models/TabRec/StructEqTable/*",+ ]+ model_dir = snapshot_download('opendatalab/PDF-Extract-Kit-1.0', allow_patterns=mineru_patterns)++ layoutreader_pattern = [+ "*.json",+ "*.safetensors",+ ]+ layoutreader_model_dir = snapshot_download('hantian/layoutreader', allow_patterns=layoutreader_pattern)++ model_dir = model_dir + '/models'+ print(f'model_dir is: {model_dir}')+ print(f'layoutreader_model_dir is: {layoutreader_model_dir}')++ json_url = 'https://github.com/opendatalab/MinerU/raw/dev/magic-pdf.template.json'+ config_file_name = 'magic-pdf.json'+ home_dir = os.path.expanduser('~')++config_file = os.path.join(home_dir, config_file_name)json_mods = {@@@ -63,4 -42,4 +65,6 @@@}download_and_modify_json(json_url, config_file, json_mods)- print(f"The configuration file has been configured successfully, the path is: {config_file}")+++ print(f'The configuration file has been configured successfully, the path is: {config_file}')++diff --cc docs/how_to_download_models_en.mdindex 34dd54e4,2f7c9fa0..6e31f524--- a/docs/how_to_download_models_en.md+++ b/docs/how_to_download_models_en.md@@@ -1,11 -1,10 +1,11 @@@Model downloads are divided into initial downloads and updates to the model directory. Please refer to the corresponding documentation for instructions on how to proceed.+# Initial download of model files--### 1. Download the Model from Hugging Face++### Download the Model from Hugging Face+Use a Python Script to Download Model Files from Hugging Face-```bashpip install huggingface_hubwget https://github.com/opendatalab/MinerU/raw/master/docs/download_models_hf.py -O download_models_hf.py@@@ -16,6 -14,6 +15,7 @@@ The Python script will automatically doThe configuration file can be found in the user directory, with the filename `magic-pdf.json`.++# How to update models previously downloaded## 1. Models downloaded via Git LFSdiff --cc docs/how_to_download_models_zh_cn.mdindex 9b395e34,54fc5782..25963d60--- a/docs/how_to_download_models_zh_cn.md+++ b/docs/how_to_download_models_zh_cn.md@@@ -10,6 -10,7 +10,7 @@@<pre><code>pip install huggingface_hubwget https://gitee.com/myhloli/MinerU/raw/master/docs/download_models_hf.py -O download_models_hf.pypython download_models_hf.py</code></pre>- <p>python脚本执行完毕后,会输出模型下载目录</p>++ <p>python脚本会自动下载模型文件并配置好配置文件中的模型目录</p></details>## 方法二:从 ModelScope 下载模型@@@ -24,10 -25,9 +25,10 @@@ python download_models.ppython脚本会自动下载模型文件并配置好配置文件中的模型目录配置文件可以在用户目录中找到,文件名为`magic-pdf.json`+> windows的用户目录为 "C:\\Users\\用户名", linux用户目录为 "/home/用户名", macOS用户目录为 "/Users/用户名"+# 此前下载过模型,如何更新## 1. 通过git lfs下载过模型