README_zh-CN.md 9.34 KB
Newer Older
徐超's avatar
徐超 committed
1
2
3
4
5
6
<div id="top">
<p align="center">
  <img src="docs/images/datalab_logo.png" width="160px" style="vertical-align:middle;">
  <span style="font-size: 28px; vertical-align: middle;">MinerU</span>
</p>
</div>
赵小蒙's avatar
赵小蒙 committed
7
8
<div align="center">

赵小蒙's avatar
赵小蒙 committed
9
10
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)
myhloli's avatar
myhloli committed
12
13
14
15
[![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)
myhloli's avatar
myhloli committed
16
<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>
赵小蒙's avatar
赵小蒙 committed
17
18
19
20
21
22

[English](README.md) | [简体中文](README_zh-CN.md)

</div>

<div align="center">
徐超's avatar
徐超 committed
23
24
25
26
27
28
29
30
<p align="center">
<a href="https://github.com/opendatalab/MinerU">MinerU: 端到端的PDF解析工具(基于PDF-Extract-Kit)支持PDF转Markdown</a>🚀🚀🚀<br>
<a href="https://github.com/opendatalab/PDF-Extract-Kit">PDF-Extract-Kit: 高质量PDF解析工具箱</a>🔥🔥🔥
</p>

<p align="center">
    👋 join us on <a href="https://discord.gg/AsQMhuMN" target="_blank">Discord</a> and <a href="https://cdn.vansin.top/internlm/mineru.jpg" target="_blank">WeChat</a>
</p>
赵小蒙's avatar
赵小蒙 committed
31
32
</div>

赵小蒙's avatar
赵小蒙 committed
33
34
# MinerU 

赵小蒙's avatar
赵小蒙 committed
35

myhloli's avatar
myhloli committed
36
37
## 简介

赵小蒙's avatar
赵小蒙 committed
38
MinerU 是一款一站式、开源、高质量的数据提取工具,主要包含以下功能:
赵小蒙's avatar
赵小蒙 committed
39

赵小蒙's avatar
赵小蒙 committed
40
41
- [Magic-PDF](#Magic-PDF)  PDF文档提取
- [Magic-Doc](#Magic-Doc)  网页与电子书提取  
赵小蒙's avatar
赵小蒙 committed
42

赵小蒙's avatar
赵小蒙 committed
43
44
# Magic-PDF

赵小蒙's avatar
赵小蒙 committed
45

赵小蒙's avatar
赵小蒙 committed
46
## 简介
赵小蒙's avatar
赵小蒙 committed
47
48
49
50
51
52
53
54

Magic-PDF 是一款将 PDF 转化为 markdown 格式的工具。支持转换本地文档或者位于支持S3协议对象存储上的文件。

主要功能包含

- 支持多种前端模型输入
- 删除页眉、页脚、脚注、页码等元素
- 符合人类阅读顺序的排版格式
赵小蒙's avatar
赵小蒙 committed
55
- 保留原文档的结构和格式,包括标题、段落、列表等
赵小蒙's avatar
赵小蒙 committed
56
57
58
59
60
61
- 提取图像和表格并在markdown中展示
- 将公式转换成latex
- 乱码PDF自动识别并转换
- 支持cpu和gpu环境
- 支持windows/linux/mac平台

myhloli's avatar
myhloli committed
62

Xiaomeng Zhao's avatar
Xiaomeng Zhao committed
63
https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c
myhloli's avatar
myhloli committed
64
65


赵小蒙's avatar
update:  
赵小蒙 committed
66

赵小蒙's avatar
赵小蒙 committed
67
68
69
70
## 项目全景

![项目全景图](docs/images/project_panorama_zh_cn.png)

赵小蒙's avatar
赵小蒙 committed
71
72
## 流程图

73
74
75
76
![流程图](docs/images/flowchart_zh_cn.png)

### 子模块仓库

wangbinDL's avatar
wangbinDL committed
77
- [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit) 
赵小蒙's avatar
赵小蒙 committed
78
  - 高质量的PDF内容提取工具包
赵小蒙's avatar
赵小蒙 committed
79

赵小蒙's avatar
赵小蒙 committed
80
## 上手指南
赵小蒙's avatar
赵小蒙 committed
81

赵小蒙's avatar
赵小蒙 committed
82
### 配置要求
赵小蒙's avatar
赵小蒙 committed
83

赵小蒙's avatar
赵小蒙 committed
84
python >= 3.9
赵小蒙's avatar
赵小蒙 committed
85

myhloli's avatar
myhloli committed
86
推荐使用虚拟环境,以避免可能发生的依赖冲突,venv和conda均可使用。  
87
88
89
90
91
例如:
```bash
conda create -n MinerU python=3.10
conda activate MinerU
```
92
93
开发基于python 3.10,如果在其他版本python出现问题请切换至3.10。

94
### 安装配置
赵小蒙's avatar
赵小蒙 committed
95

赵小蒙's avatar
赵小蒙 committed
96
#### 1. 安装Magic-PDF
赵小蒙's avatar
赵小蒙 committed
97

98
使用pip安装完整功能包:
99
> 受pypi限制,pip安装的完整功能包仅支持cpu推理,建议只用于快速测试解析能力。
100
>
101
> 如需在生产环境使用CUDA/MPS加速请参考[使用CUDA或MPS加速推理](#4-使用CUDA或MPS加速推理)
102
```bash
103
pip install magic-pdf[full-cpu]
104
```
105
106
107
108
109
110
> ❗️已收到多起由于镜像源和依赖冲突问题导致安装了错误版本软件包的反馈,请务必安装完成后通过以下命令验证版本是否正确
> ```bash
> magic-pdf --version
> ```
> 如版本低于0.6.x,请提交issue进行反馈。

111
完整功能包依赖detectron2,该库需要编译安装,如需自行编译,请参考 https://github.com/facebookresearch/detectron2/issues/5114  
112
113
或是直接使用我们预编译的whl包:
> ❗️预编译版本仅支持64位系统(windows/linux/macOS)+pyton 3.10平台;不支持任何32位系统和非mac的arm平台,如系统不支持请自行编译安装。
114
115
```bash
pip install detectron2 --extra-index-url https://myhloli.github.io/wheels/
赵小蒙's avatar
赵小蒙 committed
116
117
```

118
#### 2. 下载模型权重文件
赵小蒙's avatar
赵小蒙 committed
119

myhloli's avatar
myhloli committed
120
121
详细参考 [如何下载模型文件](docs/how_to_download_models_zh_cn.md)  
下载后请将models目录移动到空间较大的ssd磁盘目录  
122
123

#### 3. 拷贝配置文件并进行配置
myhloli's avatar
myhloli committed
124
在仓库根目录可以获得 [magic-pdf.template.json](magic-pdf.template.json) 文件
赵小蒙's avatar
赵小蒙 committed
125
```bash
赵小蒙's avatar
赵小蒙 committed
126
cp magic-pdf.template.json ~/magic-pdf.json
127
128
129
130
131
132
133
134
```
在magic-pdf.json中配置"models-dir"为模型权重文件所在目录
```json
{
  "models-dir": "/tmp/models"
}
```

135
136
137
#### 4. 使用CUDA或MPS加速推理
如您有可用的Nvidia显卡或在使用Apple Silicon的Mac,可以使用CUDA或MPS进行加速
##### CUDA
138

myhloli's avatar
myhloli committed
139
140
需要根据自己的CUDA版本安装对应的pytorch版本  
以下是对应CUDA 11.8版本的安装命令,更多信息请参考 https://pytorch.org/get-started/locally/  
141
142
143
144
145
146
147
148
149
150
151
```bash
pip install --force-reinstall torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu118
```

同时需要修改配置文件magic-pdf.json中"device-mode"的值
```json
{
  "device-mode":"cuda"
}
```

152
##### MPS
myhloli's avatar
myhloli committed
153
154
使用macOS(M系列芯片设备)可以使用MPS进行推理加速  
需要修改配置文件magic-pdf.json中"device-mode"的值  
155
156
157
158
159
160
161
```json
{
  "device-mode":"mps"
}
```


162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
### 使用说明

#### 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. 通过接口调用
赵小蒙's avatar
赵小蒙 committed
186
187
188
189
190

###### 本地使用
```python
image_writer = DiskReaderWriter(local_image_dir)
image_dir = str(os.path.basename(local_image_dir))
191
jso_useful_key = {"_pdf_type": "", "model_list": model_json}
赵小蒙's avatar
赵小蒙 committed
192
193
194
195
196
197
198
199
200
201
202
203
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)
204
jso_useful_key = {"_pdf_type": "", "model_list": model_json}
赵小蒙's avatar
赵小蒙 committed
205
206
207
208
209
210
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")
```

211
详细实现可参考 [demo.py](demo/demo.py)
赵小蒙's avatar
赵小蒙 committed
212

myhloli's avatar
myhloli committed
213

214
215
216
217
218
### 常见问题处理解答

参考 [FAQ](docs/FAQ_zh_cn.md) 


赵小蒙's avatar
赵小蒙 committed
219
220
# Magic-Doc

赵小蒙's avatar
赵小蒙 committed
221

myhloli's avatar
myhloli committed
222
223
## 简介

赵小蒙's avatar
赵小蒙 committed
224
225
226
227
228
229
230
231
232
233
234
235
236
Magic-Doc 是一款支持将网页或多格式电子书转换为 markdown 格式的工具。

主要功能包含
 
- Web网页提取
  - 跨模态精准解析图文、表格、公式信息

- 电子书文献提取
  - 支持 epub,mobi等多格式文献,文本图片全适配

- 语言类型鉴定
  - 支持176种语言的准确识别

myhloli's avatar
myhloli committed
237
238
239
240
241
242
https://github.com/opendatalab/MinerU/assets/11393164/a5a650e9-f4c0-463e-acc3-960967f1a1ca



https://github.com/opendatalab/MinerU/assets/11393164/0f4a6fe9-6cca-4113-9fdc-a537749d764d

赵小蒙's avatar
赵小蒙 committed
243
244


myhloli's avatar
myhloli committed
245
https://github.com/opendatalab/MinerU/assets/11393164/20438a02-ce6c-4af8-9dde-d722a4e825b2
赵小蒙's avatar
赵小蒙 committed
246
247


myhloli's avatar
myhloli committed
248

赵小蒙's avatar
赵小蒙 committed
249

myhloli's avatar
myhloli committed
250
## 项目仓库
myhloli's avatar
myhloli committed
251

赵小蒙's avatar
赵小蒙 committed
252
- [Magic-Doc](https://github.com/InternLM/magic-doc)
myhloli's avatar
myhloli committed
253
  优秀的网页与电子书提取工具
赵小蒙's avatar
赵小蒙 committed
254

赵小蒙's avatar
赵小蒙 committed
255

赵小蒙's avatar
赵小蒙 committed
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
## 感谢我们的贡献者

<a href="https://github.com/magicpdf/Magic-PDF/graphs/contributors">
  <img src="https://contrib.rocks/image?repo=opendatalab/MinerU" />
</a>


## 版权说明

[LICENSE.md](LICENSE.md)

本项目目前采用PyMuPDF以实现高级功能,但因其遵循AGPL协议,可能对某些使用场景构成限制。未来版本迭代中,我们计划探索并替换为许可条款更为宽松的PDF处理库,以提升用户友好度及灵活性。


## 致谢
- [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)
- [PyMuPDF](https://github.com/pymupdf/PyMuPDF)
赵小蒙's avatar
赵小蒙 committed
273
274
- [fast-langdetect](https://github.com/LlmKira/fast-langdetect)
- [pdfminer.six](https://github.com/pdfminer/pdfminer.six)
赵小蒙's avatar
赵小蒙 committed
275
276


赵小蒙's avatar
赵小蒙 committed
277
278
279
280
281
282
283
284
285
286
287
# 引用

```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}
}
```

赵小蒙's avatar
赵小蒙 committed
288
  
赵小蒙's avatar
赵小蒙 committed
289
# Star History
赵小蒙's avatar
赵小蒙 committed
290

赵小蒙's avatar
赵小蒙 committed
291
292
293
294
295
296
<a>
 <picture>
   <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date&theme=dark" />
   <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date" />
   <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date" />
 </picture>
Xiaomeng Zhao's avatar
Xiaomeng Zhao committed
297
</a>
qiangqiang199's avatar
qiangqiang199 committed
298
299
300
301
302

## 友情链接
- [LabelU (轻量级多模态标注工具)](https://github.com/opendatalab/labelU)
- [LabelLLM (开源LLM对话标注平台)](https://github.com/opendatalab/LabelLLM)
- [PDF-Extract-Kit (用于高质量PDF内容提取的综合工具包)](https://github.com/opendatalab/PDF-Extract-Kit))