Skip to content

[Python] Create your first CLI app with Facial Expression Recognition

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

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 Python API is available on pypi.org

pip install mojoperception

mojoperception update

You can update mojoperception using pip command :

pip install --upgrade mojoperception

Clone the project

In your work directory, clone the project :

git clone https://github.com/hoomano/mojo-perception-python.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/mojo-perception-example.py

Use the "API_KEY" in the following code section example/mojo-perception-example.py:

[...]
// Replace with your <API_KEY>
mojo_perception = MojoPerceptionAPI("<API_KEY>")
[...]

Run enjoy the example

🎉 You're done.

Run the example, and watch the "Attention" value print in the console. Try looking away, and you will see the prediction change accordingly

python example/mojo-perception-example.py

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.

2️⃣   If you have some python version issues, check your python version. Minimum version is python 3.6

Check the usage of your API Key

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