README.md.bak 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. <div id="top">
  2. <p align="center">
  3. <img src="docs/images/MinerU-logo.png" width="300px" 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: 200px; height: 55px;"/></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: An end-to-end PDF parsing tool based on PDF-Extract-Kit, supporting conversion from PDF to Markdown.</a>🚀🚀🚀<br>
  20. <a href="https://github.com/opendatalab/PDF-Extract-Kit">PDF-Extract-Kit: A Comprehensive Toolkit for High-Quality PDF Content Extraction</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. ## Introduction
  28. MinerU is a one-stop, open-source, high-quality data extraction tool, includes the following primary features:
  29. - [Magic-PDF](#Magic-PDF) PDF Document Extraction
  30. - [Magic-Doc](#Magic-Doc) Webpage & E-book Extraction
  31. # Magic-PDF
  32. ## Introduction
  33. 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.
  34. Key features include:
  35. - Support for multiple front-end model inputs
  36. - Removal of headers, footers, footnotes, and page numbers
  37. - Human-readable layout formatting
  38. - Retains the original document's structure and formatting, including headings, paragraphs, lists, and more
  39. - Extraction and display of images and tables within markdown
  40. - Conversion of equations into LaTeX format
  41. - Automatic detection and conversion of garbled PDFs
  42. - Compatibility with CPU and GPU environments
  43. - Available for Windows, Linux and macOS platforms
  44. https://github.com/user-attachments/assets/4bea02c9-6d54-4cd6-97ed-dff14340982c
  45. ## Project Panorama
  46. ![Project Panorama](docs/images/project_panorama_en.png)
  47. ## Flowchart
  48. ![Flowchart](docs/images/flowchart_en.png)
  49. ### Dependency repositorys
  50. - [PDF-Extract-Kit : A Comprehensive Toolkit for High-Quality PDF Content Extraction](https://github.com/opendatalab/PDF-Extract-Kit) 🚀🚀🚀
  51. ## Getting Started
  52. ### Requirements
  53. - Python >= 3.9
  54. Using a virtual environment is recommended to avoid potential dependency conflicts; both venv and conda are suitable.
  55. For example:
  56. ```bash
  57. conda create -n MinerU python=3.10
  58. conda activate MinerU
  59. ```
  60. ### Installation and Configuration
  61. #### 1. Install Magic-PDF
  62. **1.Install dependencies**
  63. The full-feature package depends on detectron2, which requires a compilation installation.
  64. If you need to compile it yourself, please refer to https://github.com/facebookresearch/detectron2/issues/5114
  65. Alternatively, you can directly use our precompiled whl package (limited to Python 3.10):
  66. ```bash
  67. pip install detectron2 --extra-index-url https://wheels.myhloli.com
  68. ```
  69. **2.Install the full-feature package with pip**
  70. >Note: The pip-installed package supports CPU-only and is ideal for quick tests.
  71. >
  72. >For CUDA/MPS acceleration in production, see [Acceleration Using CUDA or MPS](#4-Acceleration-Using-CUDA-or-MPS).
  73. ```bash
  74. pip install magic-pdf[full]==0.6.2b1
  75. ```
  76. > ❗️❗️❗️
  77. > 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.
  78. > ```bash
  79. > pip install magic-pdf[full-cpu]==0.6.1
  80. > ```
  81. #### 2. Downloading model weights files
  82. For detailed references, please see below [how_to_download_models](docs/how_to_download_models_en.md)
  83. After downloading the model weights, move the 'models' directory to a directory on a larger disk space, preferably an SSD.
  84. #### 3. Copy the Configuration File and Make Configurations
  85. You can get the [magic-pdf.template.json](magic-pdf.template.json) file in the repository root directory.
  86. ```bash
  87. cp magic-pdf.template.json ~/magic-pdf.json
  88. ```
  89. In magic-pdf.json, configure "models-dir" to point to the directory where the model weights files are located.
  90. ```json
  91. {
  92. "models-dir": "/tmp/models"
  93. }
  94. ```
  95. #### 4. Acceleration Using CUDA or MPS
  96. If you have an available Nvidia GPU or are using a Mac with Apple Silicon, you can leverage acceleration with CUDA or MPS respectively.
  97. ##### CUDA
  98. You need to install the corresponding PyTorch version according to your CUDA version.
  99. This example installs the CUDA 11.8 version.More information https://pytorch.org/get-started/locally/
  100. ```bash
  101. pip install --force-reinstall torch==2.3.1 torchvision==0.18.1 --index-url https://download.pytorch.org/whl/cu118
  102. ```
  103. > ❗ ️Make sure to specify version
  104. > ```bash
  105. > torch==2.3.1 torchvision==0.18.1
  106. > ```
  107. > 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.
  108. Also, you need to modify the value of "device-mode" in the configuration file magic-pdf.json.
  109. ```json
  110. {
  111. "device-mode":"cuda"
  112. }
  113. ```
  114. ##### MPS
  115. For macOS users with M-series chip devices, you can use MPS for inference acceleration.
  116. You also need to modify the value of "device-mode" in the configuration file magic-pdf.json.
  117. ```json
  118. {
  119. "device-mode":"mps"
  120. }
  121. ```
  122. ### Usage
  123. #### 1.Usage via Command Line
  124. ###### simple
  125. ```bash
  126. magic-pdf pdf-command --pdf "pdf_path" --inside_model true
  127. ```
  128. After the program has finished, you can find the generated markdown files under the directory "/tmp/magic-pdf".
  129. You can find the corresponding xxx_model.json file in the markdown directory.
  130. If you intend to do secondary development on the post-processing pipeline, you can use the command:
  131. ```bash
  132. magic-pdf pdf-command --pdf "pdf_path" --model "model_json_path"
  133. ```
  134. In this way, you won't need to re-run the model data, making debugging more convenient.
  135. ###### more
  136. ```bash
  137. magic-pdf --help
  138. ```
  139. #### 2. Usage via Api
  140. ###### Local
  141. ```python
  142. image_writer = DiskReaderWriter(local_image_dir)
  143. image_dir = str(os.path.basename(local_image_dir))
  144. jso_useful_key = {"_pdf_type": "", "model_list": []}
  145. pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer)
  146. pipe.pipe_classify()
  147. pipe.pipe_parse()
  148. md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none")
  149. ```
  150. ###### Object Storage
  151. ```python
  152. s3pdf_cli = S3ReaderWriter(pdf_ak, pdf_sk, pdf_endpoint)
  153. image_dir = "s3://img_bucket/"
  154. s3image_cli = S3ReaderWriter(img_ak, img_sk, img_endpoint, parent_path=image_dir)
  155. pdf_bytes = s3pdf_cli.read(s3_pdf_path, mode=s3pdf_cli.MODE_BIN)
  156. jso_useful_key = {"_pdf_type": "", "model_list": []}
  157. pipe = UNIPipe(pdf_bytes, jso_useful_key, s3image_cli)
  158. pipe.pipe_classify()
  159. pipe.pipe_parse()
  160. md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none")
  161. ```
  162. Demo can be referred to [demo.py](demo/demo.py)
  163. # Magic-Doc
  164. ## Introduction
  165. Magic-Doc is a tool designed to convert web pages or multi-format e-books into markdown format.
  166. Key Features Include:
  167. - Web Page Extraction
  168. - Cross-modal precise parsing of text, images, tables, and formula information.
  169. - E-Book Document Extraction
  170. - Supports various document formats including epub, mobi, with full adaptation for text and images.
  171. - Language Type Identification
  172. - Accurate recognition of 176 languages.
  173. https://github.com/opendatalab/MinerU/assets/11393164/a5a650e9-f4c0-463e-acc3-960967f1a1ca
  174. https://github.com/opendatalab/MinerU/assets/11393164/0f4a6fe9-6cca-4113-9fdc-a537749d764d
  175. https://github.com/opendatalab/MinerU/assets/11393164/20438a02-ce6c-4af8-9dde-d722a4e825b2
  176. ## Project Repository
  177. - [Magic-Doc](https://github.com/InternLM/magic-doc)
  178. Outstanding Webpage and E-book Extraction Tool
  179. # All Thanks To Our Contributors
  180. <a href="https://github.com/opendatalab/MinerU/graphs/contributors">
  181. <img src="https://contrib.rocks/image?repo=opendatalab/MinerU" />
  182. </a>
  183. # License Information
  184. [LICENSE.md](LICENSE.md)
  185. 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.
  186. # Acknowledgments
  187. - [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR)
  188. - [PyMuPDF](https://github.com/pymupdf/PyMuPDF)
  189. - [fast-langdetect](https://github.com/LlmKira/fast-langdetect)
  190. - [pdfminer.six](https://github.com/pdfminer/pdfminer.six)
  191. # Citation
  192. ```bibtex
  193. @article{he2024opendatalab,
  194. title={Opendatalab: Empowering general artificial intelligence with open datasets},
  195. author={He, Conghui and Li, Wei and Jin, Zhenjiang and Xu, Chao and Wang, Bin and Lin, Dahua},
  196. journal={arXiv preprint arXiv:2407.13773},
  197. year={2024}
  198. }
  199. @misc{2024mineru,
  200. title={MinerU: A One-stop, Open-source, High-quality Data Extraction Tool},
  201. author={MinerU Contributors},
  202. howpublished = {\url{https://github.com/opendatalab/MinerU}},
  203. year={2024}
  204. }
  205. ```
  206. # Star History
  207. <a>
  208. <picture>
  209. <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date&theme=dark" />
  210. <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date" />
  211. <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=opendatalab/MinerU&type=Date" />
  212. </picture>
  213. </a>
  214. # Links
  215. - [LabelU (A Lightweight Multi-modal Data Annotation Tool)](https://github.com/opendatalab/labelU)
  216. - [LabelLLM (An Open-source LLM Dialogue Annotation Platform)](https://github.com/opendatalab/LabelLLM)
  217. - [PDF-Extract-Kit (A Comprehensive Toolkit for High-Quality PDF Content Extraction)](https://github.com/opendatalab/PDF-Extract-Kit)