README_zh-CN.md.bak 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <div id="top">
  2. <p align="center">
  3. <img src="docs/images/MinerU-logo.png" width="160px" style="vertical-align:middle;">
  4. </p>
  5. </div>
  6. <div align="center">
  7. [![stars](https://img.shields.io/github/stars/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU)
  8. [![forks](https://img.shields.io/github/forks/opendatalab/MinerU.svg)](https://github.com/opendatalab/MinerU)
  9. [![open issues](https://img.shields.io/github/issues-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues)
  10. [![issue resolution](https://img.shields.io/github/issues-closed-raw/opendatalab/MinerU)](https://github.com/opendatalab/MinerU/issues)
  11. [![PyPI version](https://badge.fury.io/py/magic-pdf.svg)](https://badge.fury.io/py/magic-pdf)
  12. [![Downloads](https://static.pepy.tech/badge/magic-pdf)](https://pepy.tech/project/magic-pdf)
  13. [![Downloads](https://static.pepy.tech/badge/magic-pdf/month)](https://pepy.tech/project/magic-pdf)
  14. <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>
  15. [English](README.md) | [简体中文](README_zh-CN.md) | [日本語](README_ja-JP.md)
  16. </div>
  17. <div align="center">
  18. <p align="center">
  19. <a href="https://github.com/opendatalab/MinerU">MinerU: 端到端的PDF解析工具(基于PDF-Extract-Kit)支持PDF转Markdown</a>🚀🚀🚀<br>
  20. <a href="https://github.com/opendatalab/PDF-Extract-Kit">PDF-Extract-Kit: 高质量PDF解析工具箱</a>🔥🔥🔥
  21. </p>
  22. <p align="center">
  23. 👋 join us on <a href="https://discord.gg/gPxmVeGC" target="_blank">Discord</a> and <a href="https://cdn.vansin.top/internlm/mineru.jpg" target="_blank">WeChat</a>
  24. </p>
  25. </div>
  26. # MinerU
  27. ## 简介
  28. MinerU 是一款一站式、开源、高质量的数据提取工具,主要包含以下功能:
  29. - [Magic-PDF](#Magic-PDF) PDF文档提取
  30. - [Magic-Doc](#Magic-Doc) 网页与电子书提取
  31. # Magic-PDF
  32. ## 简介
  33. Magic-PDF 是一款将 PDF 转化为 markdown 格式的工具。支持转换本地文档或者位于支持S3协议对象存储上的文件。
  34. 主要功能包含
  35. - 支持多种前端模型输入
  36. - 删除页眉、页脚、脚注、页码等元素
  37. - 符合人类阅读顺序的排版格式
  38. - 保留原文档的结构和格式,包括标题、段落、列表等
  39. - 提取图像和表格并在markdown中展示
  40. - 将公式转换成latex
  41. - 乱码PDF自动识别并转换
  42. - 支持cpu和gpu环境
  43. - 支持windows/linux/mac平台
  44. https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c
  45. ## 项目全景
  46. ![项目全景图](docs/images/project_panorama_zh_cn.png)
  47. ## 流程图
  48. ![流程图](docs/images/flowchart_zh_cn.png)
  49. ### 子模块仓库
  50. - [PDF-Extract-Kit](https://github.com/opendatalab/PDF-Extract-Kit)
  51. - 高质量的PDF内容提取工具包
  52. ## 上手指南
  53. ### 配置要求
  54. python >= 3.9
  55. 推荐使用虚拟环境,以避免可能发生的依赖冲突,venv和conda均可使用。
  56. 例如:
  57. ```bash
  58. conda create -n MinerU python=3.10
  59. conda activate MinerU
  60. ```
  61. 开发基于python 3.10,如果在其他版本python出现问题请切换至3.10。
  62. ### 安装配置
  63. #### 1. 安装Magic-PDF
  64. **1.安装依赖**
  65. 完整功能包依赖detectron2,该库需要编译安装,如需自行编译,请参考 https://github.com/facebookresearch/detectron2/issues/5114
  66. 或是直接使用我们预编译的whl包:
  67. > ❗️预编译版本仅支持64位系统(windows/linux/macOS)+pyton 3.10平台;不支持任何32位系统和非mac的arm平台,如系统不支持请自行编译安装。
  68. ```bash
  69. pip install detectron2 --extra-index-url https://wheels.myhloli.com -i https://pypi.tuna.tsinghua.edu.cn/simple
  70. ```
  71. **2.使用pip安装完整功能包**
  72. > 受pypi限制,pip安装的完整功能包仅支持cpu推理,建议只用于快速测试解析能力。
  73. >
  74. > 如需在生产环境使用CUDA/MPS加速请参考[使用CUDA或MPS加速推理](#4-使用CUDA或MPS加速推理)
  75. ```bash
  76. pip install magic-pdf[full]==0.6.2b1 -i https://pypi.tuna.tsinghua.edu.cn/simple
  77. ```
  78. > ❗️❗️❗️
  79. > 我们预发布了0.6.2beta版本,该版本解决了很多issue中提出的问题,同时提高了安装成功率。但是该版本未经过完整的QA测试,不代表最终正式发布的质量水平。如果你遇到任何问题,请通过提交issue的方式及时向我们反馈,或者回退到使用0.6.1版本。
  80. > ```bash
  81. > pip install magic-pdf[full-cpu]==0.6.1
  82. > ```
  83. #### 2. 下载模型权重文件
  84. 详细参考 [如何下载模型文件](docs/how_to_download_models_zh_cn.md)
  85. > ❗️模型下载后请务必检查模型文件是否下载完整
  86. >
  87. > 请检查目录下的模型文件大小与网页上描述是否一致,如果可以的话,最好通过sha256校验模型是否下载完整
  88. #### 3. 拷贝配置文件并进行配置
  89. 在仓库根目录可以获得 [magic-pdf.template.json](magic-pdf.template.json) 配置模版文件
  90. > ❗️务必执行以下命令将配置文件拷贝到【用户目录】下,否则程序将无法运行
  91. >
  92. > windows的用户目录为 "C:\Users\用户名", linux用户目录为 "/home/用户名", macOS用户目录为 "/Users/用户名"
  93. ```bash
  94. cp magic-pdf.template.json ~/magic-pdf.json
  95. ```
  96. 在用户目录中找到magic-pdf.json文件并配置"models-dir"为[2. 下载模型权重文件](#2-下载模型权重文件)中下载的模型权重文件所在目录
  97. > ❗️务必正确配置模型权重文件所在目录的【绝对路径】,否则会因为找不到模型文件而导致程序无法运行
  98. >
  99. > windows系统中此路径应包含盘符,且需把路径中所有的"\"替换为"/",否则会因为转义原因导致json文件语法错误。
  100. >
  101. > 例如:模型放在D盘根目录的models目录,则model-dir的值应为"D:/models"
  102. ```json
  103. {
  104. "models-dir": "/tmp/models"
  105. }
  106. ```
  107. #### 4. 使用CUDA或MPS加速推理
  108. 如您有可用的Nvidia显卡或在使用Apple Silicon的Mac,可以使用CUDA或MPS进行加速
  109. ##### CUDA
  110. 需要根据自己的CUDA版本安装对应的pytorch版本
  111. 以下是对应CUDA 11.8版本的安装命令,更多信息请参考 https://pytorch.org/get-started/locally/
  112. ```bash
  113. pip install --force-reinstall torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu118
  114. ```
  115. > ❗️务必在命令中指定以下版本
  116. > ```bash
  117. > torch==2.3.1 torchvision==0.18.1
  118. > ```
  119. > 这是我们支持的最高版本,如果不指定版本会自动安装更高版本导致程序无法运行
  120. 同时需要修改【用户目录】中配置文件magic-pdf.json中"device-mode"的值
  121. ```json
  122. {
  123. "device-mode":"cuda"
  124. }
  125. ```
  126. ##### MPS
  127. 使用macOS(M系列芯片设备)可以使用MPS进行推理加速
  128. 需要修改配置文件magic-pdf.json中"device-mode"的值
  129. ```json
  130. {
  131. "device-mode":"mps"
  132. }
  133. ```
  134. ### 使用说明
  135. #### 1. 通过命令行使用
  136. ###### 直接使用
  137. ```bash
  138. magic-pdf pdf-command --pdf "pdf_path" --inside_model true
  139. ```
  140. 程序运行完成后,你可以在"/tmp/magic-pdf"目录下看到生成的markdown文件,markdown目录中可以找到对应的xxx_model.json文件
  141. 如果您有意对后处理pipeline进行二次开发,可以使用命令
  142. ```bash
  143. magic-pdf pdf-command --pdf "pdf_path" --model "model_json_path"
  144. ```
  145. 这样就不需要重跑模型数据,调试起来更方便
  146. ###### 更多用法
  147. ```bash
  148. magic-pdf --help
  149. ```
  150. #### 2. 通过接口调用
  151. ###### 本地使用
  152. ```python
  153. image_writer = DiskReaderWriter(local_image_dir)
  154. image_dir = str(os.path.basename(local_image_dir))
  155. jso_useful_key = {"_pdf_type": "", "model_list": model_json}
  156. pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer)
  157. pipe.pipe_classify()
  158. pipe.pipe_parse()
  159. md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none")
  160. ```
  161. ###### 在对象存储上使用
  162. ```python
  163. s3pdf_cli = S3ReaderWriter(pdf_ak, pdf_sk, pdf_endpoint)
  164. image_dir = "s3://img_bucket/"
  165. s3image_cli = S3ReaderWriter(img_ak, img_sk, img_endpoint, parent_path=image_dir)
  166. pdf_bytes = s3pdf_cli.read(s3_pdf_path, mode=s3pdf_cli.MODE_BIN)
  167. jso_useful_key = {"_pdf_type": "", "model_list": model_json}
  168. pipe = UNIPipe(pdf_bytes, jso_useful_key, s3image_cli)
  169. pipe.pipe_classify()
  170. pipe.pipe_parse()
  171. md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none")
  172. ```
  173. 详细实现可参考 [demo.py](demo/demo.py)
  174. ### 常见问题处理解答
  175. 参考 [FAQ](docs/FAQ_zh_cn.md)
  176. # Magic-Doc
  177. ## 简介
  178. Magic-Doc 是一款支持将网页或多格式电子书转换为 markdown 格式的工具。
  179. 主要功能包含
  180. - Web网页提取
  181. - 跨模态精准解析图文、表格、公式信息
  182. - 电子书文献提取
  183. - 支持 epub,mobi等多格式文献,文本图片全适配
  184. - 语言类型鉴定
  185. - 支持176种语言的准确识别
  186. https://github.com/opendatalab/MinerU/assets/11393164/a5a650e9-f4c0-463e-acc3-960967f1a1ca
  187. https://github.com/opendatalab/MinerU/assets/11393164/0f4a6fe9-6cca-4113-9fdc-a537749d764d
  188. https://github.com/opendatalab/MinerU/assets/11393164/20438a02-ce6c-4af8-9dde-d722a4e825b2
  189. ## 项目仓库
  190. - [Magic-Doc](https://github.com/InternLM/magic-doc)
  191. 优秀的网页与电子书提取工具
  192. ## 感谢我们的贡献者
  193. <a href="https://github.com/opendatalab/MinerU/graphs/contributors">
  194. <img src="https://contrib.rocks/image?repo=opendatalab/MinerU" />
  195. </a>
  196. ## 版权说明
  197. [LICENSE.md](LICENSE.md)
  198. 本项目目前采用PyMuPDF以实现高级功能,但因其遵循AGPL协议,可能对某些使用场景构成限制。未来版本迭代中,我们计划探索并替换为许可条款更为宽松的PDF处理库,以提升用户友好度及灵活性。
  199. ## 致谢
  200. - [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)
  201. - [PyMuPDF](https://github.com/pymupdf/PyMuPDF)
  202. - [fast-langdetect](https://github.com/LlmKira/fast-langdetect)
  203. - [pdfminer.six](https://github.com/pdfminer/pdfminer.six)
  204. # 引用
  205. ```bibtex
  206. @misc{2024mineru,
  207. title={MinerU: A One-stop, Open-source, High-quality Data Extraction Tool},
  208. author={MinerU Contributors},
  209. howpublished = {\url{https://github.com/opendatalab/MinerU}},
  210. year={2024}
  211. }
  212. ```
  213. # Star History
  214. <a>
  215. <picture>
  216. <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date&theme=dark" />
  217. <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date" />
  218. <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date" />
  219. </picture>
  220. </a>
  221. ## 友情链接
  222. - [LabelU (轻量级多模态标注工具)](https://github.com/opendatalab/labelU)
  223. - [LabelLLM (开源LLM对话标注平台)](https://github.com/opendatalab/LabelLLM)
  224. - [PDF-Extract-Kit (用于高质量PDF内容提取的综合工具包)](https://github.com/opendatalab/PDF-Extract-Kit))