Amplify'd ML Model Deployment - Part IV: Model Scoring Application in Flutter

Amplify'd ML Model Deployment - Part IV: Model Scoring Application in Flutter

Subscribe to my newsletter and never miss my upcoming articles

The Mobile Application is developed in Flutter (using Amplify packages for Flutter).

Amplify DataStore

As discussed previously Amplify DataStore is used to persist, version and sync the model.

The GraphQL schema is as follows:

type MLStore @model {
  id: ID!
  modelversion: String!
  modeljsonstr: String

modeljsonstr represents the json model string.

The developer updates the model using GraphQL client API or AWS AppSync Console (mutation query). The updated model can be viewed in the AWS AppSync GraphQL Console:

Screenshot 2021-03-02 at 4.15.06 AM.png

This model syncs with device store thanks to the architecture of Amplify DataStore.

Amplify Authentication

The authentication layer leverages Amplify Authentication (Cognito).

In case the app user is in an area of poor internet connectivity (eg. a bank personnel visiting villages to check loan application), a local store is maintained which expires in 24 hours (can be set as per policy) since the last cognito authentication session. This allows the user to access and run the model until the local session expires.

As the app is developed keeping modularity in mind, so all codes and screens related to authentication reside in the lib/auth/ folder.

Sign-up Screen

Screenshot 2021-03-01 at 1.09.02 PM.png

Login Process

Post successful login the user is directly taken to the form screen. Here new data can be entered for the process of scoring.

Form Auto-generation

Based on the schema of the input fields the form is auto-generated in which the user enters new data. The submit button triggers the model scoring process.

Form auto-generation is an important feature as it completely decouples the model from the UI. Now the data scientist can introduce or remove fields without worrying about updating the Mobile Application UI. Also changing the model algorithm will have no impact on the app code as the scoring engine has a separate code base.

Note: Form auto-generation & scoring engine will be published on as a separate package(s) very soon, so that it can be plugged into any Flutter application.

Some generated form screens are provided below:

Decision Tree

Screenshot 2021-03-01 at 1.48.07 PM.png

Screenshot 2021-03-01 at 1.48.28 PM.png

Field value updated on selection of categorical value: Screenshot 2021-03-01 at 1.48.35 PM.png

Kmeans Model Screen

Screenshot 2021-03-01 at 1.49.04 PM.png

Linear Regression Model Screen

Screenshot 2021-03-01 at 1.49.18 PM.png

Link to the code which autogenerates form schema from the JSON model.

Link to the scoring engine written in dart which computes the end results for the given input.

Scoring Result

Screenshot 2021-03-01 at 3.39.58 PM.png

Complete App Flow - Login to Scoring

Source Codes

Github Links of all codes developed for this hackathon:

  • JSON Machine Learning Model specification - Link
  • sklearn-model: scikit-learn model exporter (Python) - Link
  • Dart Scoring Engine + Auto-form Schema Generator + Flutter Application using Amplify Data Store & Authentication - Link

Pevious: Amplify'd ML Model Deployment - Part III: Exporting scikit-learn Models

Share this