【maker-pdf 文档文字识别(包含ocr),安装使用完整教程】

测试效果还比较好,比markitdown要好

安装环境

bash 复制代码
conda create -n maker-pdf python=3.12
conda activate marker-pdf
pip install modelscope
pip install marker-pdf -U

下载模型

python 复制代码
from modelscope import snapshot_download

model_root = "models"
snapshot_download("Lixiang/marker-pdf", local_dir="models")

开始运行

python 复制代码
from marker.converters.pdf import PdfConverter
from marker.models import create_model_dict
from marker.output import text_from_rendered
from surya.settings import settings

## 权重地址,模型很大,没GPU的话会很慢
model_root = "models"
settings.MODEL_CACHE_DIR = model_root
for chectpoint in [
    "LAYOUT_MODEL_CHECKPOINT",
    "DETECTOR_MODEL_CHECKPOINT",
    "OCR_ERROR_MODEL_CHECKPOINT",
    "TABLE_REC_MODEL_CHECKPOINT",
    "RECOGNITION_MODEL_CHECKPOINT",
]:
    value = getattr(settings, chectpoint)
    if "s3://" in value:
	    value = value.replace("s3://", "/")
	    setattr(settings, chectpoint, model_root + value)

converter = PdfConverter(
    artifact_dict=create_model_dict(),
)
rendered = converter("test.pdf")
# text = rendered.markdown
text, _, images = text_from_rendered(rendered)
print(text)
相关推荐
2401_8315017312 分钟前
Python学习之day01学习(变量定义和数据类型使用)
开发语言·python·学习
倔强青铜三40 分钟前
苦练Python第61天:logging模块——让Python日志“有迹可循”的瑞士军刀
人工智能·python·面试
倔强青铜三43 分钟前
苦练Python第60天:json模块——让Python和JSON“无缝互译”的神兵利器
人工智能·python·面试
孤客网络科技工作室1 小时前
Python - 100天从新手到大师:第二十七天Python操作PDF文件
开发语言·python·pdf
悬剑13141 小时前
python简易程序跑NLPIR模型
python·nlpir
wheeldown1 小时前
【Leetcode高效算法】用双指针策略打破有效三角形的个数
python·算法·leetcode
真的想不出名儿1 小时前
登录前验证码校验实现
java·前端·python
做运维的阿瑞2 小时前
Python原生数据结构深度解析:从入门到精通
开发语言·数据结构·后端·python·系统架构
孤客网络科技工作室2 小时前
Python - 100天从新手到大师:第二十六天Python操作Word和PowerPoint文件
python·word·powerpoint
zzywxc7872 小时前
AI赋能千行百业:金融、医疗、教育、制造业的落地实践与未来展望
java·人工智能·python·microsoft·金融·golang·prompt