Git Product home page Git Product logo

textract-demo's Introduction

End-to-End Smart OCR

Amazon Textract's advanced extraction features go beyond simple OCR to recover structure from documents: Including tables, key-value pairs (like on forms), and other tricky use-cases like multi-column text.

However, many practical applications need to combine this technology with use-case-specific logic - such as:

  • Pre-checking that submitted images are high-quality and of the expected document type
  • Post-processing structured text results into business-process-level fields (e.g. in one domain "Amount", "Total Amount" and "Amount Payable" may be different raw annotations for the same thing; whereas in another the differences might be important!)
  • Human review and re-training flows

This solution demonstrates how Textract can be integrated with:

...on a simple example use-case: extracting vendor, date, and total amount from receipt images.

The design is modular, to show how this pre- and post-processing can be easily customized for different applications.

Solution Architecture Overview

This overview diagram is not an exhaustive list of AWS services used in the solution.

Smart OCR Architecture Diagram

The solution orchestrates the core OCR pipeline with AWS Step Functions - rather than direct point-to-point integrations - which gives us a customizable, graphically-visualizable flow (defined in /source/StateMachine.asl.json):

AWS Step Functions Screenshot

The client application and associated services are built and deployed as an AWS Amplify app, which simplifies setup of standard client-cloud integration patterns (e.g. user sign-up/login, authenticated S3 data upload).

Rather than have our web client poll the state machine for progress updates, we push messages via Amplify PubSub - powered by AWS IoT Core.

The Amplify build settings (in amplify.yml with some help from the Makefile) define how both the Amplify-native and custom stack components are built and deployed... Leaving us with the folder structure you see in this repository:

├── amplify                   [Auto-generated, Amplify-native service config]
├── source
│   ├── ocr                       [Custom, non-Amplify backend service stack]
│   │   ├── human-review              [Human review integration with Amazon A2I]
│   │   ├── postprocessing            [Extract business-level fields from Textract output]
│   │   ├── preprocessing             [Image pre-check/cleanup logic]
│   │   ├── textract-integration      [SFn-Textract integrations]
│   │   ├── ui-notifications          [SFn-IoT push notifications components]
│   │   ├── StateMachine.asl.json     [Processing flow definition]
│   │   └── template.sam.yml          [AWS SAM template for non-Amplify components]
│   └── webui                     [Front-end app (VueJS, BootstrapVue, Amplify)]
├── amplify.yml               [Overall solution build steps]
└── Makefile                  [Detailed build commands, to simplify amplify.yml]
NOTE For details on each component, check the READMEs in their subfolders!

Deploying the Solution

If you have:

...then you can go ahead and click the button below, which will fork the repository and deploy the base solution stack(s):

One-click deployment

From here, there are just a few extra (but not trivial) manual configuration steps required to complete your setup:

Now you should be all set to upload images through the app UI, review low-confidence results through the Amazon A2I UI, and see the results!

The App in Action

"Successful extraction with review screenshot"

textract-demo's People

Contributors

athewsey avatar bbonik avatar nutchanon-l avatar seemag avatar vanithar75 avatar wonwilli avatar yuansingapore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

textract-demo's Issues

Newly-registered users may have to sign in twice (or just refresh?) for notifications service to work

Each user needs the appropriate IoT policy attached to their Cognito identity to have access to the notifications service...

However the only hooks available to us are on Cognito user (currently using PostAuthenticated) - and the identity is created after the user logs in.

So the app currently makes a best-effort attempt to attach the policy to the Cognito Identity, but it could fail or the timing could work out wrong when first registering & logging in - resulting in the user having to refresh the page, or maybe even log out and in again, for their IoT (PubSub notifications) permissions to get set up.

nodejs 10.x no longer supported

When try to deploy Ampify backend, it throw the error related to Lambda runtime deprecated

The runtime parameter of nodejs10.x is no longer supported for creating or updating AWS Lambda functions

Which section should be modify to support latest nodejs version?

Amplify Application failed to build

I followed the instructions on from the readme and when AWS Amplify tries to build the app I get the following error:

2024-02-19T15:51:00.365Z [WARNING]: 2024-02-19 15:51:00 Command 'build' is not configured correctly. Unable to import 'samcli.commands.build'
Traceback (most recent call last):
File "/root/.local/lib/python3.7/site-packages/samcli/cli/command.py", line 263, in get_command
mod = importlib.import_module(pkg_name)
File "/usr/lib64/python3.7/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 1006, in _gcd_import
File "", line 983, in _find_and_load
File "", line 967, in _find_and_load_unlocked
File "", line 677, in _load_unlocked
File "", line 728, in exec_module
File "", line 219, in _call_with_frames_removed
File "/root/.local/lib/python3.7/site-packages/samcli/commands/build/init.py", line 6, in
from .command import cli # noqa
File "/root/.local/lib/python3.7/site-packages/samcli/commands/build/command.py", line 11, in
from samcli.commands._utils.options import (
File "/root/.local/lib/python3.7/site-packages/samcli/commands/_utils/options.py", line 28, in
from samcli.commands._utils.custom_options.hook_name_option import HookNameOption
File "/root/.local/lib/python3.7/site-packages/samcli/commands/_utils/custom_options/hook_name_option.py", line 15, in
from samcli.lib.telemetry.event import EventName, EventTracker
File "/root/.local/lib/python3.7/site-packages/samcli/lib/telemetry/event.py", line 16, in
from samcli.lib.telemetry.telemetry import Telemetry
File "/root/.local/lib/python3.7/site-packages/samcli/lib/telemetry/telemetry.py", line 7, in
import requests
File "/root/.local/lib/python3.7/site-packages/requests/init.py", line 43, in
import urllib3
File "/root/.local/lib/python3.7/site-packages/urllib3/init.py", line 42, in
"urllib3 v2.0 only supports OpenSSL 1.1.1+, currently "
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips 26 Jan 2017'. See: urllib3/urllib3#2168
2024-02-19T15:51:00.365Z [WARNING]: Usage: sam [OPTIONS] COMMAND [ARGS]...
Try 'sam -h' for help.
2024-02-19T15:51:00.366Z [WARNING]: Error: No such command 'build'.
2024-02-19T15:51:00.393Z [WARNING]: make[1]: *** [deploy.processing] Error 2
2024-02-19T15:51:00.393Z [WARNING]: make: *** [deploy] Error 2

Registering users not receiving verification code on new forks/branches

When creating a new fork/branch in Amplify (therefore a new stack), newly registering users don't seem to be receiving their verification codes to email initially.

This seems to be because of some kind of misconfiguration in the Amplify auth resource... Manual workaround to correct a new environment is to:

  • Open the Cognito User Pools console and select the relevant user pool
  • In General Settings > MFA and Verifications set Which attributes do you want to verify? to Email. You might also have to set Do you want to enable Multi-Factor Authentication (MFA)? to Optional
  • Either force-confirm the previously registered users in the Cognito console, or delete and ask them to re-register

Ideally hoping there's some way the Amplify configuration can be fixed to set the user pool up right-first-time

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.