Building on skills learned in our previous blog, interact with machine learning and create a mobile app using Microsoft Flow and PowerApps.
Part of the Hackathon hosted by Centric Consulting intended to get our consultants a bit more exposure to Machine Learning. In the first part of this exercise, we walked through successfully connecting Microsoft Flow (and PowerApps) to an Azure Machine Learning Web Service.
Creating a Flow
Now that we’ve got our Custom Connector in Place, let’s make a flow!
So, open Microsoft Flow, and create a new blank flow. I named my flow ‘Machine Learning Request-Response.’ The first action we want to add is the generic “PowerApps’ trigger. This step essentially says “Start this Flow when PowerApps says so.”
The next action we want to take is the “Execute the web service and get a response synchronously” action in our custom connector.
Once you’ve clicked on that action, look for a prompt asking for a new connection name. Put in the API key from your Machine Learning Web Service (Part 1 of this series shows you where to find this key).
After you click ‘Create,’ you should see the details of the action, where you can format your request. The header area should be automatically filled out, and you can copy and paste the sample body of the request from the API Help Screen (also shown in Part 1 of the series).
Next, we want to replace “Values” in the body of our request with input gleaned from PowerApps.
Since we use PowerApps to input certain values, Flow has to know which values are mapped to which Input Boxes. So, we want to remove the word “value” in between each quotation mark, and click on “Ask In PowerApps.” This step creates a variable that passes from PowerApps to flow:
Next, let’s create a new action to parse our JSON response. Find the “Parse JSON” action and add it.
We’ll be passing the output of our API call to parse JSON, so in the content box, you should see a Body variable. Click to add that.
Next, we need to define the schema of our JSON output. Click on “Use Sample payload to generate schema.”
We want to copy and paste a sample response from the API. Once again, you can get this sample from the API Help document of your Machine Learning Web Service (as described in Part 1 of this series).
We need to add one final action to our flow. We want to respond to PowerApps with the value we were expecting from our response (instead of the entire JSON output response).
First, we need to add the “Respond to PowerApps” action:
Next, we add a “Text” response. We have to define a name (I used ‘flowresponse,’ but use whatever is most descriptive for you).
So in the value field, we want to construct an expression to find the value we want. In this case, based on my JSON schema it would be: body(‘Parse_JSON’)[‘Results’][‘output1’][‘value’][‘Values’]
That expression grabs the body of the output from parse JSON, and drills down to the “Values” key and gets the value.
You can now save your flow, and it’s complete!
Now, Let’s make a PowerApp!
I’m not going to review every single detail of building a PowerApp. If you need a refresher, read this blog.
For this demo, I built a PowerApp with four screens. A title screen, two screens to input the data, and one screen to view the results.
The input screen contains input text boxes (and one date control).
Now what I would like review what occurs when a user submits a request. On the submit button, I added my flow from “Actions -> Flows.” I then constructed this argument:
ClearCollect(responseColl, ‘MLRequest-Response’.Run(DatePicker1, TextInput1_2.Text, TextInput1_3.Text, TextInput1_4.Text, TextInput1.Text, TextInput1_5.Text, TextInput2.Text, TextInput1_6.Text, TextInput1_7.Text, TextInput1_8.Text, “”, “”)); Navigate(Screen3, Cover)
So, what’s happening here is I am instantiating a collection, which is collecting the response from running the flow.
In the flow, I am passing the parameters the flow wants by sending it the text values the user entered in for each of my input text boxes and then navigating to the next screen.
When I click the “Submit” button in my designer preview, I can go look at my collections, and see the value added to the collection:
Now that I have my value, I also wanted to display it in a more friendly way (without brackets and everything past the decimal). So I added a label and used the following formula:
This formula takes the flow response and looks for a contiguous match of just digits. Then I used concatenate to put “Days” at the end.
Lastly, as a bit of housekeeping on apps usage, when a user clicks the “Start Over” button, it resets all the controls, and sends the user back to the home screen!
The Final Application
Following these steps in tandem with those listed in Part 1, we successfully connected Microsoft Flow and PowerApps to an Azure Machine Learning Web Service and created a fully functional mobile app to predict how long an employee might stay with an organization. Now you can take these skills and apply what we practiced to your own business needs and strategies.
Part six of a Women in Tech series. This blog was originally published on Jo’s blog, here.