Power Fx is the general-purpose, strong-typed, declarative, and functional programming language used across the Microsoft Power Platform. This excel-like formula language helps app makers to create apps using low code, read more about Power FX here.
With the latest announcement, Microsoft is giving another level of possibilities with Power FX. Now, you can bind the AI model to any control using Power FX. You heard it right! any control. Earlier it was possible to use AI with the AI builder controls only. Now, Microsoft has made it easier than ever to add intelligence to your Power Apps directly through Power FX. Let’s see how to use this feature for a text control to detect the language entered.
Turn on the AI models as data sources option
Figure1: Turn on Ai model as data source
In your power app, under the app settings go to Upcoming features > Preview, and turn on the AI model as data sources.
Add your AI model as Data Source
Under the Data tab, go to Add data and In the AI models list, select a language detection model. To know more about AI models please check the official Microsoft docs here.
Fig 2: Add your AI model to the APP
Add your Controls
Place a text input and two text labels on the canvas as explained below
- Rename the text input to TextInput1.
- Select Text label and place it on the canvas.
- Rename the text label to Language.
- Add another text label by selecting Text label and place it to the right of the Language text label.
Call the AI model using Power FX
Now we can use the power FX formula to call the AI model method. Select the text label you added in step 2 and enter the following Power Fx formula.
Now, save and run the app. You can type in random languages in the text box to see the AI model in action.
Now you have bound the AI model to a normal label control using Power FX.
‘Language detection’.Predict(TextInput1.Text).results returns a table of possible languages detected with the score. The language with the highest score (highest possible match) will be the first item in the table. So, using the function ‘First‘ the most matching language code is set to the label.
Another example of a prediction model can be found here.
Hope this helps.