简单使用Marker

简单使用Marker

1 简单介绍

Marker是由Datalab维护的开源项目,它利用了surya的模型进行做的,能够快速准确地将文档转换为Markdown、JSON、分块数据及HTML格式。相对MinerU和Docling文件解析的效果较差,但是解析的速度是较快的,如果考虑速度和性能,可以考虑这个模型。不好的地方除了github没有官方本地部署较完整的文档。

Datalab也维护了Surya,Surya是一款文档OCR工具包,功能包括:支持90多种语言的OCR技术、任意语言的行级文本检测

版面分析(表格、图像、标题等检测)、阅读顺序检测、表格识别(检测行/列)、LaTeX OCR(数学公式)。

复制代码
# Github地址(没有标准的开发文档)
https://github.com/datalab-to/marker

# Surya的Github地址
https://github.com/datalab-to/surya

2 安装环境

安装依赖环境

复制代码
pip install marker-pdf[full] -i https://pypi.tuna.tsinghua.edu.cn/simple

简单例子

注意:Windows中模型的默认下载路径是"C:\Users\Admin\AppData\Local\datalab",Admin是我的用户名,此处对应你的用户名。模型大小:4.97G。

复制代码
# 注意!! 解析的过程不支持多线程和多协程
from marker.converters.pdf import PdfConverter
from marker.models import create_model_dict
from marker.output import text_from_rendered


def test():
    print(create_model_dict())
    converter = PdfConverter(
        artifact_dict=create_model_dict()
    )

    # 解析图片
    rendered = converter("E:/temp/test.png")
    text, _, images = text_from_rendered(rendered)
    print(text, _, images)

    # 解析pdf
    rendered = converter("E:/test/test1.pdf")
    text, _, images = text_from_rendered(rendered)
    print(text, _, images)

    # 解析docx
    rendered = converter("E:/test/test2.docx")
    text, _, images = text_from_rendered(rendered)
    print(text, _, images)


if __name__ == '__main__':
    test()

截图

相关推荐
哈里谢顿19 小时前
Python 高并发服务限流终极方案:从原理到生产落地(2026 实战指南)
python
用户8356290780511 天前
无需 Office:Python 批量转换 PPT 为图片
后端·python
markfeng81 天前
Python+Django+H5+MySQL项目搭建
python·django
GinoWi1 天前
Chapter 2 - Python中的变量和简单的数据类型
python
JordanHaidee1 天前
Python 中 `if x:` 到底在判断什么?
后端·python
ServBay2 天前
10分钟彻底终结冗长代码,Python f-string 让你重获编程自由
后端·python
闲云一鹤2 天前
Python 入门(二)- 使用 FastAPI 快速生成后端 API 接口
python·fastapi
Rockbean2 天前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
曲幽2 天前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi
用户60648767188962 天前
国内开发者如何接入 Claude API?中转站方案实战指南(Python/Node.js 完整示例)
人工智能·python·api