Integrate Azure ML Studio with PowerApps and Power Automate: Part 2

Sahil Srivastava
5 min readJul 15, 2020

--

Welcome to 2nd part of the series. In my previous blog, we created a predictive model on Adult Income Dataset in Azure ML Studio. In this part, we will create predictive web service and call it through Power Automate and create our UI in PowerApps.

PowerApps at its core is a Platform as a Service. It allows you to create Mobile Apps that run on Android, iOS, Windows (Modern Apps) — and with almost any Internet browser. You can act and modify data with PowerApps.
Power Automate previously known as Microsoft Flow is a cloud-based system with which you can create automated workflows and, thus, simplify business processes and manage them more effectively.

Setting up and Deploying Web Service

  1. Open your Training Experiment.
  2. On the bottom of page select Set up Web Service and choose Predictive Web Service (Recommended) from it.
  3. It will create a Predictive Experiment just like below.

4. This will create input and output schema for our Web Service.

You can see in the image that Web service has an input and it is transformed by all of modules such as column selection, converting string variables, which are basically used to preprocess our data. All of these transformations are applied to our Web Service input. And after it passes through our trained model in the end gives Web Service output which will be the final outcome whether income >50k or ≤50k.

5. Now Deploy it by selecting Deploy Web Service in the bottom.(You need to run your predictive experiment before deploying it.)

6. After deployment, it is going to redirect you to an API dashboard.

7. Now you can Test your model from the TEST button by entering some set of values and it will predict the income. Basically it’s an OOTB feature to check the predictive web service just like Postman.

Till now we have created our web service, now we will create a flow to call our web service.

Create a flow in Power Automate

  1. Create a new flow using PowerApps button template.

2. Add HTTP action. For completing this action you need to go to API dashboard.

  • Method: POST
  • URI: On API dashboard, click Request/Response. This will open API documentation page. Copy Request URI and paste it here.
  • Headers: Copy all Request Headers and paste it in here.(You can find API Key on API Dashboard)
  • Body: Copy Request Body and paste it here. Now in this step you need to replace requested “Values” with your own input values.

As we know our UI will be PowerApps canvas app, thus our input values will be coming from PowerApps to flow and our flow needs to know which values are mapped with which input box. Thus we will replace word “value” by clicking on Ask in PowerApps. It will create a variable that will be passed from PowerApps to flow.

Here we have replaced only those values which we need to input from PowerApps and rest are left as it is. And remember to create one extra variable for the income prediction.

3. Now add Parse JSON action to parse the response from our API call in JSON format.

  • Content: Add Body variable.
  • Schema: Select Generate from Sample and paste your Response body from API Documentation page.

This step will create Output in JSON format and now only step left is to fetch our income variable from the output and send it back to PowerApps.

4. Add Respond to PowerApp or flow action. Choose Text as the type of output. For the value field, we need to retrieve our income variable through an expression. It would be something like :

body(‘Parse_JSON’)[‘Results’][‘output1’][‘value’][‘Values’][0][8]

After this step our backend is completed and now we just need to create our UI and pass our inputs.

Create a Canvas app in PowerApps

  1. Create a blank canvas app and create its structure somehow like in the below image using Labels, Text Inputs and Button.

2. First go to Action and choose Power Automate. You will see the lists of flows associated with PowerApps. You need to add your flow.

3. Now OnSelect of Predict Button write the following query:

ClearCollect(ResponseCol, IntegrateAzureMLwithPowerApps.Run
(TextInput1.Text, TextInput2.Text, TextInput3.Text, TextInput4.Text, TextInput5.Text, TextInput6.Text, TextInput7.Text, “”)) ;

Here all the input values are passed to the flow and in return it will send our output i.e., income which will store in a Collection named ResponseCol.

Collection

4. Now select Label to show our output income. Add the following query on Text property of Label.

First(ResponseCol).response

5. Now you can customize your PowerApps on your own. I have shown the prediction in next screen like below.

Conclusion

Thus, we have successfully created a machine learning model on Azure ML Studio and deployed it on PowerApps(canvas app) in integration with Power Automate. It is a full fledged app which will predict the income of an Adult.
Now you can create your own Machine Learning model till deployment for different business problems.

Thanks for Reading!!!

References and further reading:

--

--