README.md 3.99 KB
Newer Older
zhougaofeng's avatar
zhougaofeng committed
1
2
# magic_pdf

zhougaofeng's avatar
zhougaofeng committed
3
## 一、安装pdf文档解析
zhougaofeng's avatar
zhougaofeng committed
4

zhougaofeng's avatar
zhougaofeng committed
5
### 以下演示在223节点安装pdf解析模块(可以直接使用镜像:1177ea7959ce)
zhougaofeng's avatar
zhougaofeng committed
6

zhougaofeng's avatar
zhougaofeng committed
7
### 1、下载本项目
zhougaofeng's avatar
zhougaofeng committed
8

zhougaofeng's avatar
zhougaofeng committed
9
`git clone http://developer.sourcefind.cn/codes/zhiAn123/magic_pdf.git`
zhougaofeng's avatar
zhougaofeng committed
10

zhougaofeng's avatar
zhougaofeng committed
11
12
13
14
15
16
17
#### 安装依赖包

【提供的镜像暂未支持doclayout-YoLo模型,如需使用,请下载最新的库文件】
pip install -U magic-pdf[full] --extra-index-url https://wheels.myhloli.com -i https://mirrors.aliyun.com/pypi/simple

安装完毕后,请卸载需要使用光源库文件(torch、vllm等),以及nvdia-cuda类似不支持的库文件

zhougaofeng's avatar
zhougaofeng committed
18
### 2、下载需要的模型库
zhougaofeng's avatar
zhougaofeng committed
19

zhougaofeng's avatar
zhougaofeng committed
20

zhougaofeng's avatar
zhougaofeng committed
21
22
下载qwen模型:[快速下载通道](http://113.200.138.88:18080/aimodels/qwen/Qwen2-VL-7B-Instruct.git)

zhougaofeng's avatar
zhougaofeng committed
23
下载PDF解析需要的模型: [快速下载通道](http://113.200.138.88:18080/aimodels/opendatalab/PDF-Extract-Kit)
zhougaofeng's avatar
zhougaofeng committed
24

zhougaofeng's avatar
zhougaofeng committed
25
26
`pip install modelscope`

zhougaofeng's avatar
zhougaofeng committed
27
`wget https://gitee.com/myhloli/MinerU/raw/master/scripts/download_models.py -O download_models.py`
zhougaofeng's avatar
zhougaofeng committed
28

zhougaofeng's avatar
zhougaofeng committed
29
`python download_models.py`
zhougaofeng's avatar
zhougaofeng committed
30

zhougaofeng's avatar
zhougaofeng committed
31
【注意,download_models.py执行完毕,会把模型文件以及layout文件安装在/root/.cache下】
zhougaofeng's avatar
zhougaofeng committed
32

zhougaofeng's avatar
zhougaofeng committed
33
### 3、安装需要的依赖库
zhougaofeng's avatar
zhougaofeng committed
34

zhougaofeng's avatar
zhougaofeng committed
35
#### 进入主目录(以下内容都在主目录下进行)
zhougaofeng's avatar
zhougaofeng committed
36

zhougaofeng's avatar
zhougaofeng committed
37
`cd magic_pdf`
zhougaofeng's avatar
zhougaofeng committed
38

zhougaofeng's avatar
zhougaofeng committed
39
执行本地源码安装
zhougaofeng's avatar
zhougaofeng committed
40

zhougaofeng's avatar
zhougaofeng committed
41
#### pip install -e .
zhougaofeng's avatar
zhougaofeng committed
42

zhougaofeng's avatar
zhougaofeng committed
43
44
### 4、修改magic-pdf.json
在第二步执行download_models.py文件后,会在/root文件夹下,下载名为magic-pdf.json文件,修改文件内容
zhougaofeng's avatar
zhougaofeng committed
45

zhougaofeng's avatar
zhougaofeng committed
46
47
48
<div align=center>
    <img src="doc/image (9).png"/>
</div>
zhougaofeng's avatar
zhougaofeng committed
49

zhougaofeng's avatar
zhougaofeng committed
50
"models-dir":"[模型路径]" 路径指向**第二步下载的pdf解析模型路径下的models文件夹**
zhougaofeng's avatar
zhougaofeng committed
51

zhougaofeng's avatar
zhougaofeng committed
52
53
54
<div align=center>
    <img src="doc/image (10).png"/>
</div>
zhougaofeng's avatar
zhougaofeng committed
55

56
57
58
59
60
61
### 5、配置config.ini中的路由地址

vim magic_pdf/config.ini

默认如下:

62
63
64
<div align=center>
    <img src="doc/image13.png"/>
</div>
65
66
67
68

根据需要,自行配置路由地址

### 6、启动qwen-ocr模块:
zhougaofeng's avatar
zhougaofeng committed
69

zhougaofeng's avatar
zhougaofeng committed
70
71
#### 6.1、启动非vllm的qwen-ocr模块:

zhougaofeng's avatar
zhougaofeng committed
72
修改magic_pdf/magic_pdf/dict2md/ocr_server.py文件中模型路径地址
zhougaofeng's avatar
zhougaofeng committed
73
74
75
76

<div align=center>
    <img src="doc/image11.png"/>
</div>
zhougaofeng's avatar
zhougaofeng committed
77

zhougaofeng's avatar
zhougaofeng committed
78
##### qwen-ocr服务启动代码:
zhougaofeng's avatar
zhougaofeng committed
79

zhougaofeng's avatar
zhougaofeng committed
80
`python magic_pdf/dict2md/ocr_server.py`
zhougaofeng's avatar
zhougaofeng committed
81

82
默认使用0号DCU卡 ,可以通过--dcu_id 指定卡,-c 指定qwen模型地址,--config_path 指定config.ini路径
zhougaofeng's avatar
zhougaofeng committed
83

zhougaofeng's avatar
zhougaofeng committed
84
85
86
87
88
qwen-ocr模块启动成功:
<div align=center>
    <img src="doc/image (5).png"/>
</div>

zhougaofeng's avatar
zhougaofeng committed
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#### 6.2、 启动vllm的qwen-ocr模块:

1、修改magic_pdf/magic_pdf/dict2md/ocr_vllm_server.py文件中模型路径地址
2、修改magic_pdf/magic_pdf/pre_proc/cut_image.py、magic_pdf/magic_pdf/tools/pdf_server.py、magic_pdf/magic_pdf/parse/ofd_parse.py文件
将注释更改如下
<div align=center>
    <img src="doc/image_vllm.png"/>
</div>

##### qwen-ocr-vllm服务启动代码:

`CUDA_VISIBLE_DEVICES=0 python magic_pdf/dict2md/ocr_vllm_server.py`

默认使用0号DCU卡,-c 指定qwen模型地址,--config_path 指定config.ini路径 


qwen-ocr模块启动成功:
<div align=center>
    <img src="doc/image (5).png"/>
</div>


111
### 7、启动pdf-server解析服务:
zhougaofeng's avatar
zhougaofeng committed
112
113
114

#### pdf-server解析服务启动代码:

zhougaofeng's avatar
zhougaofeng committed
115
`python magic_pdf/tools/pdf_server.py`
zhougaofeng's avatar
zhougaofeng committed
116

117
默认使用0号DCU卡 ,可以通过--dcu_id 指定卡,--config_path 指定config.ini路径
zhougaofeng's avatar
zhougaofeng committed
118

zhougaofeng's avatar
zhougaofeng committed
119
120
121
<div align=center>
    <img src="doc/image (6).png"/>
</div>
zhougaofeng's avatar
zhougaofeng committed
122

zhougaofeng's avatar
zhougaofeng committed
123
124
125
126
启动成功:
<div align=center>
    <img src="doc/image (7).png"/>
</div>
zhougaofeng's avatar
zhougaofeng committed
127

128
129
### 8、解析pdf

zhougaofeng's avatar
zhougaofeng committed
130
`python magic_pdf/parse/common_parse.py -p [文件/目录 路径] -o [输出地址]`
131
132
133
134
135
136
137

-p指定pdf路径,-o指定输出路径 --config_path 指定config.ini路径 

<div align=center>
    <img src="doc/image12.png"/>
</div>

zhougaofeng's avatar
zhougaofeng committed
138
139
140
<div align=center>
    <img src="doc/image (8).png"/>
</div>
141

zhougaofeng's avatar
zhougaofeng committed
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
## 二、安装ofd文档解析

`1、pip install easyofd`

2、安装需要的字体文件

查看容器内的字体:

`fc-list`

请配置magic_pdf/tools/font_tools.py文件,配置字体路径

<div align=center>
    <img src="doc/font.png"/>
</div>

若代码执行过程中报错,字体未找到,请向容器内添加字体后,再修改font_tools.py文件




163