简单使用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()

截图

相关推荐
Hgfdsaqwr31 分钟前
Python在2024年的主要趋势与发展方向
jvm·数据库·python
一晌小贪欢1 小时前
Python 测试利器:使用 pytest 高效编写和管理单元测试
python·单元测试·pytest·python3·python测试
小文数模1 小时前
2026年美赛数学建模C题完整参考论文(含模型和代码)
python·数学建模·matlab
Halo_tjn1 小时前
基于封装的专项 知识点
java·前端·python·算法
vlln1 小时前
【论文速读】递归语言模型 (Recursive Language Models): 将上下文作为环境的推理范式
人工智能·语言模型·自然语言处理
Hgfdsaqwr1 小时前
掌握Python魔法方法(Magic Methods)
jvm·数据库·python
weixin_395448912 小时前
export_onnx.py_0130
pytorch·python·深度学习
s1hiyu2 小时前
使用Scrapy框架构建分布式爬虫
jvm·数据库·python
2301_763472462 小时前
使用Seaborn绘制统计图形:更美更简单
jvm·数据库·python
无垠的广袤2 小时前
【VisionFive 2 Lite 单板计算机】边缘AI视觉应用部署:缺陷检测
linux·人工智能·python·opencv·开发板