6k Star 超好用OCR 工具!一键 PDF 转 Markdown

项目简介

ZeroX是一个将 pdf、docx、图片等文件转换为Markdown格式的工具,它利用GPT视觉模型(gpt-4o-mini 或 gpt-4o)来实现这一转换。这个项目旨在提高文档处理的效率,使得 pdf、docx、图片内容能够更方便地在Markdown环境中使用和编辑。

项目特点

  • 多功能OCR转换:Zerox可以处理不同文件类型(PDF、Word、图片等),并将文件转为一系列图片,然后利用GPT模型将图片内容转为Markdown格式文本。
  • 简单的文件转换流程
    • 接收文件输入(支持URL或本地文件路径)。
    • 将文件内容转换为图片。
    • 使用GPT等视觉模型进行OCR,并输出Markdown文本。
  • 多模型支持:支持不同的视觉模型,包括OpenAI、Azure OpenAI、Anthropic、AWS等多种模型,用户可以自由选择和配置。
  • 多平台实现:提供Node.js和Python SDK,便于在不同的开发环境中使用。
  • 配置选项丰富
    • 支持并发和页数选择,用户可以定义转换的页码和并发数量。
    • 支持格式保持选项,特别适合含有复杂表格和跨页内容的文档。
    • 支持清理临时文件、设置临时文件夹路径等。
  • 兼容多种文件格式:支持包括PDF、Word、Excel、PPT、HTML、XML等多种文件格式。

项目地址

https://github.com/getomni-ai/zerox

主要功能

  • 输入文件(pdf、docx、图像等)
  • 将文件转换为一系列图像
  • 将每张图像传递给GPT,生成Markdown
  • 汇总响应并返回Markdown

在线试用: https://getomni.ai/ocr-demo

效果演示

小编输入一个 pdf 文件,以下是转换后的效果:

图标被转换成表格:

支持json格式展示:

部署指南

Zerox 同时提供 Node 和 Python 包,我们看 Node 版本示例:

安装 Zerox

npm install zerox

用法

使用 URL

import { zerox } from "zerox";

const result = await zerox({
  filePath: "https://omni-demo-data.s3.amazonaws.com/test/cs101.pdf",
  openaiAPIKey: process.env.OPENAI_API_KEY,
});

从本地路径

import path from "path";
import { zerox } from "zerox";

const result = await zerox({
  filePath: path.resolve(__dirname, "./cs101.pdf"),
  openaiAPIKey: process.env.OPENAI_API_KEY,
});

其他配置

const result = await zerox({
  // Required
  filePath: "path/to/file",
  openaiAPIKey: process.env.OPENAI_API_KEY,

  // Optional
  cleanup: true, // Clear images from tmp after run.
  concurrency: 10, // Number of pages to run at a time.
  correctOrientation: true, // True by default, attempts to identify and correct page orientation.
  maintainFormat: false, // Slower but helps maintain consistent formatting.
  model: 'gpt-4o-mini' // Model to use (gpt-4o-mini or gpt-4o).
  outputDir: undefined, // Save combined result.md to a file.
  pagesToConvertAsImages: -1, // Page numbers to convert to image as array (e.g. `[1, 2, 3]`) or a number (e.g. `1`). Set to -1 to convert all pages.
  tempDir: "/os/tmp", // Directory to use for temporary files (default: system temp directory).
  trimEdges: true, // True by default, trims pixels from all edges that contain values similar to the given background colour, which defaults to that of the top-left pixel.
});

输出示例

{
  completionTime: 10038,
  fileName: 'invoice_36258',
  inputTokens: 25543,
  outputTokens: 210,
  pages: [
    {
      content: '# INVOICE # 36258\n' +
        '**Date:** Mar 06 2012  \n' +
        '**Ship Mode:** First Class  \n' +
        '**Balance Due:** $50.10  \n' +
        '## Bill To:\n' +
        'Aaron Bergman  \n' +
        '98103, Seattle,  \n' +
        'Washington, United States  \n' +
        '## Ship To:\n' +
        'Aaron Bergman  \n' +
        '98103, Seattle,  \n' +
        'Washington, United States  \n' +
        '\n' +
        '| Item                                       | Quantity | Rate   | Amount  |\n' +
        '|--------------------------------------------|----------|--------|---------|\n' +
        "| Global Push Button Manager's Chair, Indigo | 1        | $48.71 | $48.71  |\n" +
        '| Chairs, Furniture, FUR-CH-4421             |          |        |         |\n' +
        '\n' +
        '**Subtotal:** $48.71  \n' +
        '**Discount (20%):** $9.74  \n' +
        '**Shipping:** $11.13  \n' +
        '**Total:** $50.10  \n' +
        '---\n' +
        '**Notes:**  \n' +
        'Thanks for your business!  \n' +
        '**Terms:**  \n' +
        'Order ID : CA-2012-AB10015140-40974  ',
      page: 1,
      contentLength: 747
    }
  ]
}

Zerox OCR 是一款开源的文件转换工具,专注于将 PDF、Word、图片等文件类型高效转换为 Markdown 格式文本。OCR 需求的小伙伴可以一试。

更多精彩内容关注公众号【十月指南】

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值