This is a quick and fun proof of concept demo developed to show off the capabilities of Snowflake Document AI. The idea of the "magic" is to have an audience member fill out the paper form and then you as the "magician" will snap a picture of the form and it will magically appear on the streamlit app on the screen without you having to touch your computer. Top hat and cape are optional by highly recommended for effect.
- Snowflake
- account
- access to Document AI
- access to Streamlit in Snowflake
- internal stage
- ability to create a table
- A computer to run python file watcher
- Microsoft teams / OneDrive and or Google Drive (A way to email a file to a folder on the computer running the file watcher script)
Create a stage where form images can be sent and a table to store the processed data.
CREATE STAGE doc_ai_stage
DIRECTORY = (ENABLE = TRUE)
ENCRYPTION = (TYPE = 'SNOWFLAKE_SSE');
CREATE OR REPLACE TABLE MY_DB.MY_SCHEMA.DOCFORM_TABLE (
SCORE FLOAT,
DATE_VALUE VARCHAR,
TEXT_VALUE VARCHAR,
DROPDOWN_VALUE VARCHAR,
NUMERIC_VALUE VARCHAR,
FREE_TEXT_WRITING_VALUE VARCHAR
)
*Replace MY_DB
and MY_SCHEMA
with your database and schema.
Deploy a Document AI model from Snowsight UI.
Print off 20 copies of the ./resources/demo_form_empty.pdf file
and have various people fill it out. All fields can be filled out by hand (the dropdown field can be preselected; it is used to show the option of having a preselected field in a form). Ideally the forms should use printing for all fields except the handwriting field which should use cursive.
Upload the training files to the model and train it.
Copy code from 01_magic_streamlit_app.py
into a a Streamlit in Snowflake app.
Setup a local folder to watch for form files.
- Copy
02_magic_file_watcher.py
to a local folder and setup virtual environmentpython -m venv .venv
,pip install -r requirements.txt'
. - Add the connection parameters to the script along with the WATCH_DIR, STAGE, TABLE_NAME, MODEL_NAME, MODEL_VERSION and FILE_TYPE.
- Start the file watcher script.
- Start the Streamlit app and make it full screen.
- Get someone to fill out the document, snap a picture and upload it to the watched folder using only your phone.
- Watch as they are amazed that their writing appears on the screen like "MAGIC" ✨.