跳转到主要内容

Amazon Textract Helper工具

项目描述

Textractor-Textract-Helper

amazon-textract-helper 提供了一系列现成的函数和示例实现,用于加速任何使用 Amazon Textract 的项目的评估和开发。它安装了一个名为 amazon-textract 的命令行工具。

安装

> python -m pip install amazon-textract-helper

请确保您的环境已通过配置文件、环境变量或附加的角色设置 AWS 凭据。(https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html

测试

> amazon-textract --help
usage: amazon-textract [-h] (--input-document INPUT_DOCUMENT | --example | --stdin) [--features {FORMS,TABLES} [{FORMS,TABLES} ...]]
                       [--pretty-print {WORDS,LINES,FORMS,TABLES} [{WORDS,LINES,FORMS,TABLES} ...]]
                       [--pretty-print-table-format {csv,plain,simple,github,grid,fancy_grid,pipe,orgtbl,jira,presto,pretty,psql,rst,medi
awiki,moinmoin,youtrack,html,unsafehtml,latex,latex_raw,latex_booktabs,latex_longtable,textile,tsv}]
                       [--overlay {WORD,LINE,FORM,KEY,VALUE,TABLE,CELL} [{WORD,LINE,FORM,KEY,VALUE,TABLE,CELL} ...]]
                       [--pop-up-overlay-output] [--overlay-output-folder OVERLAY_OUTPUT_FOLDER] [--version] [--no-stdout] [-v | -vv]

optional arguments:
  -h, --help            show this help message and exit
  --input-document INPUT_DOCUMENT
                        s3 object (s3://) or file from local filesystem
  --example             using the example document to call Textract
  --stdin               receive JSON from stdin
  --features {FORMS,TABLES} [{FORMS,TABLES} ...]
                        features to call Textract with. Will trigger call to AnalyzeDocument instead of DetectDocumentText
  --pretty-print {WORDS,LINES,FORMS,TABLES} [{WORDS,LINES,FORMS,TABLES} ...]
  --pretty-print-table-format {csv,plain,simple,github,grid,fancy_grid,pipe,orgtbl,jira,presto,pretty,psql,rst,mediawiki,moinmoin,youtrac
k,html,unsafehtml,latex,latex_raw,latex_booktabs,latex_longtable,textile,tsv}
                        which format to output the pretty print information to. Only effects FORMS and TABLES
  --overlay {WORD,LINE,FORM,KEY,VALUE,TABLE,CELL} [{WORD,LINE,FORM,KEY,VALUE,TABLE,CELL} ...]
                        defines what bounding boxes to draw on the output
  --pop-up-overlay-output
                        shows image with overlay
  --overlay-text        shows image with WORD or LINE text overlay. When both WORD and LINE overlay are specified, WORD text will be overlayed
  --overlay-confidence  shows image with confidence overlay
  --overlay-output-folder OVERLAY_OUTPUT_FOLDER
                        output with bounding boxes to folder
  --version             print version information
  --no-stdout           no output to stdout
  -v                    >=INFO level logging output to stderr
  -vv                   >=DEBUG level logging output to stderr

示例命令

快速开始

> amazon-textract --example

这将使用 DetectDocumentText API 运行示例文档。输出将打印到 stdout,类似于以下内容

{"DocumentMetadata": {"Pages": 1}, "Blocks": [{"BlockType": "PAGE", "Geometry": {"BoundingBox": {"Width": 1.0, "Height": 1.0, "Left": 0.0
, "Top": 0.0}, "Polygon": [{"X": 9.33321120033382e-17, "Y": 0.0}, {"X": 1.0, "Y": 1.6069064689339292e-16}, {"X": 1.0, "Y": 1.0}],
"HTTPHeaders": {"x-amzn-requestid": "12345678-1234-1234-1234-123456789012", "content-type": "a
pplication/x-amz-json-1.1", "content-length": "48177", "date": "Thu, 01 Apr 2021 21:50:29 GMT"}, "RetryAttempts": 0}}

它正在运行。

使用 S3 上的文档调用

> amazon-textract --input-document "s3://somebucket/someprefix/someobjectname.png"

输出类似于快速开始

使用本地文件系统上的文档调用

> amazon-textract --input-document "./somepath/somefilename.png"

输出类似于快速开始

我们将继续使用 --example 参数以保持其简单易复现。S3 和本地文件的工作方式相同,只需将 --example 替换为 --input-document。

使用 STDIN 调用

# first create JSON
amazon-textract --example > example.json
# now use a stored JSON with the ```amazon-textract``` command
cat example.json | amazon-textract --stdin -pretty-print LINES

使用 FORMS 和 TABLES 调用

> amazon-textract --example --features FORMS TABLES

这将调用 [AnalyzeDocument API] (https://docs.aws.amazon.com/textract/latest/dg/API_AnalyzeDocument.html),输出将与“快速开始”类似,但包括 FORMS 和 TABLES 信息

美化输出

美化输出将单词、行、表格或表格格式化得很好。

例如,要打印 Amazon Textract 识别的表格到 stdout,使用

> amazon-textract --example --features TABLES --pretty-print TABLES

输出将类似于以下内容

|------------|-----------|---------------------|-----------------|-----------------------|
|            |           | Previous Employment | History         |                       |
| Start Date | End Date  | Employer Name       | Position Held   | Reason for leaving    |
| 1/15/2009  | 6/30/2011 | Any Company         | Assistant Baker | Family relocated      |
| 7/1/2011   | 8/10/2013 | Best Corp.          | Baker           | Better opportunity    |
| 8/15/2013  | present   | Example Corp.       | Head Baker      | N/A, current employer |

要美化输出 FORMS 和 TABLES,将输出

> amazon-textract --example --features FORMS TABLES --pretty-print FORMS TABLES

Phone Number:: 555-0100
Home Address:: 123 Any Street, Any Town, USA
Full Name:: Jane Doe
Mailing Address:: same as home address
|------------|-----------|---------------------|-----------------|-----------------------|
|            |           | Previous Employment | History         |                       |
| Start Date | End Date  | Employer Name       | Position Held   | Reason for leaving    |
| 1/15/2009  | 6/30/2011 | Any Company         | Assistant Baker | Family relocated      |
| 7/1/2011   | 8/10/2013 | Best Corp.          | Baker           | Better opportunity    |
| 8/15/2013  | present   | Example Corp.       | Head Baker      | N/A, current employer |

覆盖

目前,覆盖仅适用于图像,我们很快将添加对 PDF 的支持。

以下命令运行 DetectDocumentText,将文档中的单词美化打印到 stdout,并在每个单词周围绘制边界框,并在弹出窗口中显示结果,并将其存储在名为 'overlay-output-folder-name' 的文件夹中。

amazon-textract --example --pretty-print WORDS --overlay WORD --pop-up-overlay-output --overlay-output-folder overlay-output-folder-name
Sample overlay WORD

以下命令运行 AnalyzeDocument 以处理 FORMS 和 TABLES,将 FORMS 和 TABLES 美化打印到 stdout,并在每个 TABLE-CELL 和 FORM KEY/VALUE 周围绘制边界框,并在弹出窗口中显示结果,并将其存储在名为 'overlay-output-folder-name' 的文件夹中。

> amazon-textract --example --features TABLES FORMS --pretty-print FORMS TABLES --overlay FORM CELL --pop-up-overlay-output --overlay-output-folder ../mywonderfuloutputfolderfordocs/
Sample overlay FORM CELL

以下命令在每个单词周围绘制边界框,覆盖检测到的单词文本,并在弹出窗口中显示结果,并将其存储在名为 'overlay-output-folder-name' 的文件夹中。

> amazon-textract --example --overlay WORD --overlay-text --pop-up-overlay-output --overlay-output-folder overlay-output-folder-name
Sample overlay LINE with overlay text and confidence percentage

以下命令在每个行周围绘制边界框,覆盖行文本以及检测到的行文本的置信度百分比,并在弹出窗口中显示结果,并将其存储在名为 'overlay-output-folder-name' 的文件夹中。

> amazon-textract --example --overlay LINE --overlay-text --overlay-confidence --pop-up-overlay-output --overlay-output-folder overlay-output-folder-name
Sample overlay LINE with overlay text and confidence percentage

项目详细信息


下载文件

下载适用于您的平台的文件。如果您不确定要选择哪个,请了解更多关于 安装包 的信息。

源分布

amazon-textract-helper-0.0.35.tar.gz (1.4 MB 查看哈希值)

上传时间 源代码

构建版本

amazon_textract_helper-0.0.35-py2.py3-none-any.whl (298.1 kB 查看哈希值)

上传时间 Python 2 Python 3

由以下支持

AWSAWS云计算和安全赞助商DatadogDatadog监控FastlyFastlyCDNGoogleGoogle下载分析MicrosoftMicrosoftPSF赞助商PingdomPingdom监控SentrySentry错误日志StatusPageStatusPage状态页面