[Guide] Using Google Cloud Document AI with AppSheet

Introduction

This is a simple guide for using Google Cloud Document AI form processing with an AppSheet app. There have been some previously published sample apps and guides on this topic, but this one is much simpler and straightforward to use. In this case we will deploy a small adapter to Google Cloud Run to interface our AppSheet app to DocAI. The adapter service is completely serverless (meaning on infra is needed), and will only be called when we need a form processed, so will incur minimal / zero cost.

Document AI can easily and quickly process PDF and image scans of forms, and return very accurate extracted data of all of the form values. You can try it for yourself at https://cloud.google.com/document-ai and upload your own PDF to test and see the extracted form content.

Screenshot from 2023-11-03 11-14-56.png

So let's get started with connecting Document AI into an AppSheet app, and letting users upload and take photos of document forms, and get the results added into our app data, which can be further used in integration flows and alerts.

Step 1: Create a Document AI Form Processor

To start we need a Document AI form processor, which you can create in Google Cloud here. You will need a Google Cloud account and project, which you can start for free with $300 credits here. Document AI form processing is in general pretty cheap, costing between 5 and 6.5 cents per page, depending on usage (see pricing here). 

You might need to enable the Document AI API before proceeding (the console will guide you through the process).

Be sure to create a Form Parser from the processor gallery. You can name it anything you like, and choose between the EU and US for hosting.

Create a form parser.Create a form parser.

After creating it, you should see it listed under My Processors. Click on it and note the ID and Region fields, we will need those later when configuring our AppSheet service.

Step 2: Deploy the Adapter

The DocAI adapter is a service that is needed to connect AppSheet to Document AI. The adapter translates AppSheet data updates into DocAI API calls, and returns the results to AppSheet. This adapter model is a simple, low-cost and effective way to connect advanced services to AppSheet apps. The adapters also scale well, since anyone can then utilize in their apps.

To deploy the adapter go this Github project (don't worry, you won't have to touch any source code), and click the Run on Google Cloud button.

tyayers_0-1699009471925.png

After clicking the Run on Google Cloud button, trust the repo and authorize the Google Cloud Shell session, and then select your project to deploy the adapter to. I will be deploying to appsheet-test8.

tyayers_1-1699009780694.png

Then choose a region to deploy to. I will be using europe-west1.

tyayers_2-1699009862441.png

Now enter your Doc AI Region and Doc AI Processor ID that we saved from Step 1.

tyayers_3-1699009942385.png

Now the service will build and deploy to your chosen region. This can take 3-5 minutes.

Step 3: Give user rights to read AppSheet files

After the deploy process is complete, scroll up until you see some dark text stating "Add user XXXXXXXXX-compute@developer.gserviceaccount.com to your AppSheet Google Drive folder with Read permissions.", where XXXXXXXXXX is a long number. Copy the entire email address (in this case XXXXXXXXX-compute@developer.gserviceaccount.com) and add it with Viewer rights to your Google Drive > appsheet > data directory. This gives our adapter the permission to read uploaded files in order to send them to Doc AI. This should be done in the Google Drive account of your AppSheet app author.

tyayers_5-1699010387846.png

Step 4: Add adapter to AppSheet as data source

Now also copy the URL of the service that was deployed, which should be the last text displayed in green in your deployment window.

tyayers_6-1699010510571.png

In my case the URL is https://docai-service-sfh5dtwfxq-ew.a.run.app.

b445cfef-46a4-4105-8130-6050e9fdfbc7.pngNow go to your AppSheet Account Sources, and click + New Data Source. Enter a name like Doc AI Service and click Apigee. Apigee means add an API that AppSheet can use like a normal data service (and check out the Apigee service in Google Cloud if you are interested in a full API solution, however for this solution we are just using the data source and not the full Apigee service).

 

 

 

 


tyayers_7-1699010930735.png

 

Now add the URL from above into the OpenAPI Spec URL field, and enter anything into the Apigee API Key field (it's not valided in this sample project, please add for production use-cases), and then click Validate, and Authorize Access.

 

 

 

Step 5: Create an app

Now we're ready to create an app, and test the integration. Go back to your AppSheet Apps overview page (do a refresh if it's still open in your browser to make sure it knows about our new data source), and click Create > App > Start with existing data.

Select our Apigee Api > Doc AI Service in the list, and then choose documents as Sheet/Table.

tyayers_8-1699011213155.png

tyayers_9-1699011241708.png

Now the app will be created. Initially there's just some test data in the app. Open the data configuration, and change the file column to File type, and also set the field to not required (can be adjusted later).

tyayers_10-1699011363614.png

Now click the file button in the app preview to upload a file - just choose any test PDF like this one. After uploading and saving the record, you should be able to open the newly created record and see all of the form fields processed in the app.

tyayers_11-1699011644239.png

This is just a small example of what's possible, feel free to test further, and reach out here in the comments with any questions.

 

 

6 6 1,133
6 REPLIES 6

Updated, fixed bug with us parsers, and updated to support invoice parsers as well as form parsers. Just redeploy the service using the instructions above, and your app will pick up the changes. Let me know if anyone has any issues, or create an issue in the GitHub repository.

hi @tyayers ,

followed the steps but get stuck in step two when tried deploying the adapter into the google cloud, it keeps provisioning cloud shell machine even though i tried in incognito mode, any suggestions?

Hi Ricky, yes I've had that problem sometimes too.. There is a better way to use Cloud Shell directly, will post an update this week.

hi @tyayers ,

looking forward for the other ways to connect the appsheet with doc ai api endpoints.

Usually though if you retry later then it will work eventually.. 

hi @tyayers ,

now the cloud run process mentioned in step 2 working, but i get failed process while pushing the images to gcr.io/docai-service of my projects meanwhile i already make sure the iam permission needed has granted. any spesific iam permission need to added so the process can working?

Top Labels in this Space