Skip to main content

Notifications

Build and Train a Form Processing AI Model to use with Power Apps

                                                         0.PNG

Introduction

AI Builder is a Power Platform capability that provides you the AI models to take leverage of artificial intelligence to optimize your business as well as automate process. We can either use the already existing prebuilt models that suits our needs to use the Power of AI in Power Apps or Power Automate or create our own custom AI models to suit some specific business needs. You can read more about AI Models in the Official documentation here. The out of the box prebuilt available models in AI Builder are:

  • Business card reader    
  • Category classification     
  • Entity extraction                   
  • ID reader
  • Invoice Processing          
  • Key phrase extraction    
  • Language detection              
  • Receipt processing            
  • Sentiment analysis                
  • Text recognition                    
  • Text translation      

In earlier days if we wanted to use any of these models, we had to call Power Automate and add the AI Builder actions to leverage the Cognitive abilities. However, more and more AI Builder capabilities are coming natively to Power App so that we can add them as controls to the App and directly interact with the AI Models based on our needs.

In this article we will see how we can make use of the Form Processor within Power App to read forms of a predefined template. Since the forms can vary in templates with different fields , we will also see how to create a Model that can be used to meet our specific needs, train them to identify the data that we need and use it with the Form Processor in Power App.

Scenario

We have a requirement where we are handing over Forms to patients to fill out their details which can be used for Back Office data records keeping. Manually copying over the data can be cumbersome. So, we will automate the reading of the filled out forms by patients and extract the information using a Power App that leverages Form Processor

Priyaranjan_0-1648747825297.png

 

We will save the patient data to SharePoint List with the below columns

Priyaranjan_1-1648747825303.png 

 

Implementation

To get started with the creation of the Form Processing App, lets create a new Canvas App and add the Form Processor from the AI Builder to the screen. By default, it is not linked to any existing models. In case we do not have a model that has been trained to pick the information form the forms that we are going to use, we will have to create and train a new model.

Priyaranjan_2-1648747825309.png

 

So as to create a new model specific to the forms that we are going to use, lets head over to the AI Builder section in the make.powerapps.com and from Explore tab, select “Extract custom information from documents”

Priyaranjan_3-1648747825318.png

 

Add Fields to Model

This will open a new model builder that will initially ask us to add all the fields from the form that we would like to add to the model so that it can detect corresponding information from the forms.

Priyaranjan_4-1648747825321.png

 

As of now we can use Fields, Checkboxes, and tables with the models. For each Field/Checkbox/Table that we would like to add to the model, click on Add and select the field type and click on Next.

 

Priyaranjan_5-1648747825328.png

 

We will also give the name of the Field that we will be trying to map in the model.

Priyaranjan_6-1648747825331.png

 

Repeat the steps for all the fields. Since Phone Number and Date Of Birth is a collection of multiple sub fields, we will be mapping the sub fields (Day,Month,Year) in case of the Main field(Date of Birth) and combining their values later in the Power App.

Priyaranjan_7-1648747825335.png

 

So, we have mapped Area Code and Mobile Number which will together form the full Phone Number field value.

Priyaranjan_8-1648747825336.png

 

We will do the same for Date of Birth by adding the sub fields Day,Month and Year.

Priyaranjan_9-1648747825340.png

 

The Address field is also mapped using Street Address 1 and Street Address 2

Priyaranjan_10-1648747825342.png

 

We also have one Check Box that will be mapped to the model.

Priyaranjan_11-1648747825344.png

 

 

Let’s specify its name and add it to the model.

Priyaranjan_12-1648747825348.png

 

Thus, we have added all the fields and checkbox in the form to the model that we are going to use.

Priyaranjan_13-1648747825350.png

 

Add Sample Documents

Thus, after adding the fields to the model, lets add a collection of 5 or more documents so that we can use it for mapping the model fields to the fields in the sample documents which will help the model in the future to identify the text from respective fields.

 

 

 

 

 

 

 

Priyaranjan_14-1648747825352.png

 

Click on New collection which will open a right pane that gives the option to add documents.

 

Priyaranjan_15-1648747825357.png

 

Click on Add documents to upload the sample forms. We can select the source from which we can upload the document.

Priyaranjan_16-1648747825360.png

 

Once the documents are browsed and selected, click on Upload to add them to the collection.

Priyaranjan_17-1648747825366.png

 

Thus, we can see that all the selected documents have been uploaded and added to the collection.

Priyaranjan_18-1648747825371.png

 

Click on Next to move to the next phase of Tagging the model fields to the Form Area/Field.

Priyaranjan_19-1648747825375.png

 

Map the Fields to Form Area

 

Select each section of the Form from where we need to extract the data. The model will show a drop down of fields that we had created previously and selecting it will map the model field to the selected form area. Any text in that area will be extracted and mapped to the form field when we use the model in the future.

 

 

Priyaranjan_20-1648747825393.png

 

Since we have split the Date of Birth into 3 fields, Day, Month and Year, we will map them to their respective fields.

Priyaranjan_21-1648747825412.png

 

Thus, we have completed the mapping of all the fields in the current form. Repeat this process for all the forms that we have added to the collection so that it improves the accuracy of the model in extracting the data.

Priyaranjan_22-1648747825457.png

 

Click on Next to move to the next phase of Training the model.

Train the Model

Now based on the mapped model fields, the model will train itself using the uploaded collection and get itself up to speed in identifying text from a similar form that we will use in the future. Click on Train to start the training process.

Priyaranjan_23-1648747825462.png

 

The training will take some time to complete.

Priyaranjan_24-1648747825467.png

 

Test the Model

Once the training is complete, even before publishing, we can do a quick test to see how well the model is able to extract form data.

Priyaranjan_25-1648747825472.png

 

Click on Quick test and upload a new form.

Priyaranjan_26-1648747825476.png

 

The model has identified the data using the mapping we had done previously, and it also give a confidence score indicating the accuracy of the mapping.

Priyaranjan_27-1648747825490.png

 

Now let’s go ahead and Publish the model so that it becomes available for use in our Power App.

Priyaranjan_28-1648747825497.png

 

It can be access from Flow as well as SharePoint Syntex applications. Instead of selecting the New App in Power Apps, I will just head over to the app that we were creating previously.

Priyaranjan_29-1648747825505.png

 

 

 

Add Model to the Form Processor

We can see that the recently created model is now made available for use with the Form Processor control we had added to the screen.

Priyaranjan_30-1648747825510.png

 

 

Let’s select the model which will allow the form processor to use it for analysing the uploaded forms and extract the mapped data for use in the app. We have also added Text Controls to the App for all the fields that will be extracted from the uploaded form. For Address, to show it as a multi-line value, we will use an HTML Text control to better host the extracted data.

Priyaranjan_31-1648747825512.png

 

The Text Input controls get their default values from the Form processor using the expressions. FormProcessor.Results.<FieldsName>.Value . For Full Name field, since we have mapped it inside the model, we will be referring to its value using the below expression in the Default property of the text box.

 

 

FormProcessor.Results.'Full Name'.Value

 

 

Priyaranjan_32-1648747825515.png

 

Same way rest of the fields can be referred using the expressions:

Text Input Control

Expression

Full Name

FormProcessor.Results.'Full Name'.Value

Gender

FormProcessor.Results.Gender.Value

PhoneNumber

Concatenate(FormProcessor.Results.'Area Code'.Value,"-",FormProcessor.Results.'Mobile Number'.Value)

Date of Birth

Concatenate(FormProcessor.Results.Day.Value,"-",FormProcessor.Results.Month.Value,"-",FormProcessor.Results.Year.Value)

Address

Concatenate(FormProcessor.Results.'Street Address Line 1'.Value,"<br/>",FormProcessor.Results.'Street Address Line 2'.Value)

EmailID

FormProcessor.Results.'Email Address'.Value

Visited Previously

FormProcessor.Results.'Visited the Clinic Before ?'.Value

 

Since Date of Birth is a combination of the Day , Month and Year , we will use the Concatenate function to combine them together and show as a single value in the text box.

Priyaranjan_33-1648747825518.png

 

Same way as Address is a combination of Street Address Line 1 and Street Address Line 2, so as to show them as 2 lines, we are using the HTML text control and using the concatenate function with a new line character in the expression so that both addresses would show up in 2 lines.

Priyaranjan_34-1648747825523.png

 

Finally, we will use the Patch function to save the details back to the SharePoint List

 

 

Patch('Patient Details',{'Full Name':TextInput_FullName.Text,Gender:TextInput_Gender.Text,'Phone Number':TextInput_PhoneNumber.Text,'Date of Birth':TextInput_DateofBirth.Text,Address:HtmlText_Address.HtmlText,'Email ID':TextInput_EmailID.Text,'Visited Clinic Previously ?':Checkbox_VisitePreviously.Value})

 

 

Priyaranjan_35-1648747825530.png

 

Test the App

Now let’s test the app by previewing it. We will upload a patient form and the model will quickly extract the content and populate the form fields and on clicking Save, it gets saved to the list back end.

 

 

Form Processing.gif

Summary

Thus, we saw how to Create a Form Processing model, train it and use it with our app to extract data from forms that were created for a specific business need with a predefined layout.

Comments

*This post is locked for comments