专栏名称: GitHubStore
分享有意思的开源项目
目录
相关文章推荐
吃什么情报局  ·  一年就 1 ... ·  19 小时前  
江苏警方  ·  近期大量上市,多人吃进急诊室!紧急提醒→ ·  22 小时前  
江苏警方  ·  近期大量上市,多人吃进急诊室!紧急提醒→ ·  22 小时前  
慧田哲学  ·  张鸣:退休之际的废话(这也太敢言了) ·  昨天  
51好读  ›  专栏  ›  GitHubStore

从文档中提取结构化数据Documind

GitHubStore  · 公众号  ·  · 2024-11-22 11:19

正文

项目简介

Documind 是一种先进的文档处理工具,利用人工智能从 PDF 中提取结构化数据。它旨在处理 PDF 转换、提取相关信息以及按照可自定义模式指定的格式设置结果。


这个存储库是建立在 Zerox 之上的 - https://github.com/getomni-ai/zerox 。Zerox 的 MIT 许可证包含在核心文件夹中,并且也在根许可证文件中提到。


特征

  • 将 PDF 转换为图像以进行详细的 AI 处理。

  • 使用 OpenAI 的 API 来提取和构建信息。

  • 允许用户指定各种文档格式的提取模式。

  • 专为在本地或云环境中灵活部署而设计。


尝试托管版本🚀

documind 托管版本的演示即将推出供您试用!托管版本通过完全托管的 API 提供无缝体验,因此您可以跳过设置并立即开始提取数据。


要完全访问托管服务,请请求访问权限,我们将为您进行设置。


要求

在使用 documind 之前,请确保安装了以下软件依赖项:


系统依赖

  • Ghostscript documind 依赖 Ghostscript 来处理某些 PDF 操作。

  • GraphicsMagick :文档转换中的图像处理所需。


在继续之前,请在您的系统上安装两者:

# On macOSbrew install ghostscript graphicsmagick
# On Debian/Ubuntusudo apt-get updatesudo apt-get install -y ghostscript graphicsmagick

Node.js 和 NPM

确保您的系统上安装了 Node.js (v18+) 和 NPM。


安装

您可以通过 npm 安装 documind

npm install documind

环境设置

documind 需要 .env 文件来存储敏感信息,例如您的 OpenAI API 密钥。

Create an .env file in your project directory and add the following:
在项目目录中创建一个 .env 文件并添加以下内容:

OPENAI_API_KEY=your_openai_api_key

用法

基本示例

首先,导入 documind 并定义您的架构。该架构概述了 documind 应在每个文档中查找哪些信息。这是一个快速入门的设置。


1. 定义模式

该架构是一个对象数组,其中每个对象定义:

  • name :要提取的字段名称。

  • type :数据类型(例如, "string" "number" "array" "object" )。

  • 描述 :字段的描述。

  • 子项 (可选):对于数组和对象,定义嵌套字段。


银行对账单的示例架构:

const schema = [  {    name: "accountNumber",    type: "string",    description: "The account number of the bank statement."  },  {    name: "openingBalance",    type: "number",    description: "The opening balance of the account."  },  {    name: "transactions",    type: "array",    description: "List of transactions in the account.",    children: [      {        name: "date",        type: "string",        description: "Transaction date."      },      {        name: "creditAmount",        type: "number",        description: "Credit Amount of the transaction."      },      {        name: "debitAmount",        type: "number",        description: "Debit Amount of the transaction."      },      {        name: "description",        type: "string",        description: "Transaction description."      }    ]  },  {    name: "closingBalance",    type: "number",    description: "The closing balance of the account."  }];


2.运行documind

使用 documind 通过传递文件 URL 和架构来处理 PDF。

import { extract } from 'documind';
const runExtraction = async () => { const result = await extract({ file: 'https://bank_statement.pdf', schema });
console.log("Extracted Data:", result);};
runExtraction();







请到「今天看啥」查看全文