Skip to content

[Flutter] Create your first Flutter app with Facial Expression Recognition

Step by step example to run Mojo Facial Expression API for Flutter application.

../../images/demo_image.jpeg

Overview

In this tutorial, we will go through the process of building a command line interface app and mostly focusing on plugging the facial expression recognition API and print the result.

Open Source Tutorial : available on GitHub

You can find all the source code and documentation on GitHub

Install the library

Mojo Facial Expression Flutter package available on pub.dev

dev-dependencies:
    - mojo_perception: ^1.0.0

mojo_perception update

You can update mojo_perception using pub get command :

flutter pub get

Clone the project

In your work directory, clone the project :

git clone https://github.com/hoomano/mojo-perception-flutter.git

Get a fresh API token

Mojo Facial Expression API is accessible through Authorization token.

If you don't have an account yet

👉   Create your developer account, and get access to a 14-days free trial : https://hoomano.com/free-facial-expression-recognition
After registering, you'll receive your API Key. We'll need it right away.

Adjust code example example/lib/main.dart

Use the "API_KEY" in the following code section example/lib/main.dart:

[...]
// Replace with your <your_auth_token_here> and <user_namespace_here>
MojoPerceptionAPI mojoPerceptionApi = MojoPerceptionAPI(
      '<your_auth_token_here',
      'stream.mojo.ai',
      '443',
      '<user_namespace_here>');

[...]

Run enjoy the example

🎉 You're done.

Run the example, and watch the "Amusement" value displayed in the slide bar. Try looking away, and you will see the prediction change accordingly

flutter run

Customize the example

You can add callbacks on each emotions, add new emotions and enhance design to build your very own application.

Troubleshooting

1️⃣   If you face a "JsonWebTokenError", maybe that's because of the expiration. You can try to increase the user token duration to match your need. Default value of 360 seconds might be too short.

Check the usage of your API Key

Open the Mojo Facial Expression API Backoffice to check your consumption, and manage your account.