MinerU 用于處理pdf 屬于是工作流 最后解析成markdown+json
__version__ = "2.1.10"
##構(gòu)建虛擬環(huán)境,執(zhí)行環(huán)境路徑(空間較大),避免依賴(lài)過(guò)大
conda create -p /root/autodl-tmp/data/mineru python=3.10
conda activate /root/autodl-tmp/data/mineru
## 用git下載代碼
git clone https://github.com/opendatalab/MinerU.git
cd MinerU
## 項(xiàng)目用uv工具管理,先下個(gè)uv
pip install uv
#阿里云的源好像還沒(méi)有,換清華的
pip install uv -i https://pypi.tuna.tsinghua.edu.cn/simple
## 安裝依賴(lài)
uv pip install -e .[core] -i https://mirrors.aliyun.com/pypi/simple
#阿里云的源好像403,換清華的
uv pip install -e .[core] --index-url https://pypi.tuna.tsinghua.edu.cn/simple
#依賴(lài)超級(jí)多,貌似147個(gè)(2.1.10) 150個(gè)(3.0版本),耐心等待。
## 下載模型(也可以不執(zhí)行,執(zhí)行了會(huì)下載較多的模型,占用空間)
mineru-models-download
## 執(zhí)行命令
mineru -p /root/autodl-tmp/data/mineru/input/劉邦的簡(jiǎn)歷.pdf -o /root/autodl-tmp/data/mineru/output -d cuda
mineru -p /root/autodl-tmp/input/DeepSeek專(zhuān)題之企業(yè)級(jí)智能客服.pdf -o /root/autodl-tmp/output

報(bào)錯(cuò)的話
conda install -c nvidia nccl
檢查并修復(fù) PyTorch 環(huán)境
確保 PyTorch 版本與 CUDA 匹配
pip uninstall torch torchvision torchaudio
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118 # 替換為您的 CUDA 版本

pip install pymupdf
#新版-d移除了 會(huì)自動(dòng)檢測(cè)設(shè)備 --source 也移除了 使用環(huán)境變量來(lái)設(shè)置
export MINERU_MODEL_SOURCE=modelscope

image.png
設(shè)置模型下載位置
# 創(chuàng)建模型目錄
mkdir -p /root/autodl-tmp/data/mineru/models
# 寫(xiě)入環(huán)境變量
echo 'export MODELSCOPE_CACHE=/root/autodl-tmp/data/mineru/models' >> ~/.bashrc
echo 'export MINERU_MODEL_SOURCE=modelscope' >> ~/.bashrc
source ~/.bashrc
2.1.10版本的
cd /root/autodl-tmp/MinerU/projects/multi_gpu_v2

image.png
#完成以上自定義配置后,回到服務(wù)器終端,依次執(zhí)行如下三條命令安裝LitServe服務(wù)運(yùn)行所需要的依賴(lài)環(huán)境:
pip install -U litserve python-multipart filetype
pip install paddlepaddle-gpu==3.0.0b1 -i https://www.paddlepaddle.org.cn/packages/stable/cu118
# 啟動(dòng)腳本
python server.py
3.0版本移除了litserver 內(nèi)置了自己的多gpu方案
# 單卡直接用
mineru-api --host 0.0.0.0 --port 8000
# 多卡
mineru-router --host 0.0.0.0 --port 8002 --local-gpus auto

image.png
3.0的同步方法
/file_parse
~~