How to use Emotion Recognizer with Thunkable X

Hello Thunkers! :tada:

I am back with another Tutorial - & this time, it’s more Interesting… :stuck_out_tongue_winking_eye:



:smiley: :frowning_face: How to make Emotion Recognizer app in Thunkable X :smiley: :frowning_face:



Introduction

So, Basically, What is Emotion Recognition AI?

Emotional artificial intelligence, also called Emotion AI or affective computing, is being used to develop machines that are capable of reading, interpreting, responding to, and imitating human affect—the way we, as humans, experience and express emotions. What does this mean for consumers? It means that your devices, such as your smartphone or smart speakers, will be able to offer you interaction that feels more natural than ever before, all by simply reading the emotional cues in your voice.

How Does Emotion AI Work?

Emotionally intelligent AI relies on user-generated data to catalogue and compare reactions to certain stimuli, such as videos or phone conversations and uses machine learning to transform this data into recognition of human emotion and behavioural patterns. This, in turn, can be leveraged by call centres that can use this knowledge to understand both agents’ and customers’ needs to provide a better consumer experience. Emotion AI can provide a more in-depth look into the micro-emotional reactions users have during their experiences, providing valuable feedback for researchers.

Our API - Face++

In this tutorial, we are going to deal with the Face++ API.

With this API, we can have lots of power in our hands for our App. Such as - Facial Recognition, Body Recognition, & Image Recognition. But now, we’ll just focus on Emotion Recognition.
You can refer to the API Docs here.

Setup

Then, after you complete the whole setup, hover over to this API Reference.

Getting Started

Building the URL for Request

Our API Base URL is: https://api-us.faceplusplus.com/facepp/v3/detect

To build our final URL, we need to know our required Parameters.
We send Parameters generally by adding/embedding them in URL.

Let’s have a look at our Required Parameters -

(Sorry if the image is unclear, plz open in a new tab or maximize it :sweat_smile:)

For every Parameter, we want to attach, we attach & before parameter name and = before parameter value. But, for the very 1st Parameter, make sure you attach “?”, not &.

So, our final URL formatted should be formatted like :

The Response

Like all common APIs, this site also provides us with a (our favourable) .JSON Response.

A look at the JSON

Take a look at the sample JSON Response here.
Or, download it : json response.txt (785 Bytes)

Our .JSON consists of 4 main items :

  • image-id
  • request_id
  • times_used
  • faces // only this is useful to us

Note : When you deal with JSONs, if you see " [ ] " brackets, then the item which has this brackets is a List. You need to call list items from the list. In our case, faces is a list.


Diving Deeper in the Response

Faces : 2 items - landmarks & attributes. // landmarks is not useful to us; only attributes.
Attributes : 3 properties - emotion, gender & age. // all are useful.
Emotion : 7 properties - // all represent values in % from your face.

  • Happiness
  • Sadness
  • Disgust
  • Anger
  • Neutral
  • Surprise
  • Fear

Gender : 1 property - value
Age : 1 property - value

Cropping/Extracting useful things from the Response

Gender and Age

So, according to the above response, our path for getting Gender & Age would be :
value > gender > attributes > 1st item from faces.
value > age > attributes > 1st item from faces.

Emotions

So, according to the response, our path for getting Emotions would be :

  • happiness > emotion > attributes > 1st item from faces.
  • sadness > emotion > attributes > 1st item from faces.
  • fear > emotion > attributes > 1st item from faces.
  • surprise > emotion > attributes > 1st item from faces.
  • anger > emotion > attributes > 1st item from faces.
  • neutral > emotion > attributes > 1st item from faces.
  • disgust > emotion > attributes > 1st item from faces.

Note: Make sure you match the emotion names correctly with the above pic and path given above the pic. These are CaSe SeNSitivE…

Completing the API URL

We need a URL for the image to POST it to API… Now?
The Cloudinary Media DB is the best and only solution for us.
Now, we need a face & it’s image URL for completion of blocks.

Getting Face & it’s URL

We’ll capture the face from the camera, and upload it to cloudinary.
Have a look at the blocks :

Final Touch

  • You can add a loading icon & visible it before camera.take photo and invisible it after the whole process completes.
  • Add an image component for the user to see his/her captured image (just for display.)
  • Disable/Invisible the Analyze button just after the user clicks it. (This will prevent multiple clicks on the button.)

:tada: We’ve Successfully made an Emotion Recongnizer :tada:

Some Important Instructions :

Don’t forget to add your API key and Secret in the Code :sweat_smile: & valid Cloudinary Details in the Designer…

Image Requirements

  • The image size “should not be larger > 2MB”. - otherwise, the API will return errors.

  • Make sure the image is JPEG & PNG only.

  • Size should be between 48x48 and 4096x4096 (pixels).

  • Capture your Face with the Front Camera for making the image < 2MB.

Visit the Project Page here.

Remix the App here & post your Remixes in the Community! .

Credits :

Thanks to @actech & @jane for helping me with JSONs.

& Thanks @Behavioral Signals for the introduction to Emotion AI.

Show some :hearts:

Hope it Helps everyone :smile:

Thanks :slight_smile:

:tada: :tada: Happy Thunking! :tada: :tada:

17 Likes

This is such a great tutorial!
Some Thunkers have been asking about an Emotion Recognizer for Thunkable X, and this will be a great resource for them :smiley:

4 Likes

Thanks Everyone!

2 Likes

Please feel free to give suggestions! :slight_smile:

1 Like

Thanks Kartik, Great piece

1 Like

Thanks, @abrownme! :blush:

P.S I am the same person, this is another account :slightly_smiling_face:

1 Like

Hi @kartik14, again.
I just remixed your app, signed up and used my keys, but the app remains in a waiting screen.
Do you have idea what could be wrong?
Thank you. :pray:
Ionut

1

2 Likes

Hi, @io.nut.ilie! :wave:

Did you put your Cloudinary Credintials too?

Thanks! :blush:

1 Like

Hi, @kartik14!
Yes, I have also the Cloudinary info inserted (on Design side).
But for the Web API, there are integrated only on Block side. Should this be ok or do I have to put them also on Design side?
Still the same loading screen for now.
Thank you.
Ionut

3

Hi, @io.nut.ilie! :wave:

This -

image

Needs to be this - “Cloud Name”

image

Thanks! :blush:

1 Like

I thank you! :handshake: but is still not working.
I will do it again from start maybe I have put it some wrong info and I am not aware now.

Mhm, I have done it again and it is still only the loading screen.
Thank you anyway for the concept.
Ionut

Hi, @io.nut.ilie! :wave:

Also, make sure that you have correct API key and secret.

Thanks!

1 Like

Hi, @kartik14!
Thank you!

1 Like

Is the problem solved?

Almost. Thank you @kartik14! I still don’t get what I doing wrong. :upside_down_face:

I

recommend that you should add the block get object from JSON after the resopnse. I had got problem like you when i didnt using that block, and when i add it later, everything work well.
Hope it help (sorry about my poor English)

2 Likes

Hi, @H_i_CH_n_Nguy_n! :wave:

Can you please show the blocks that work for you?

Thanks! :blush:

2 Likes



here you are. I had just tested and every thing work well.
Sorry about may late response :sweat_smile: :sweat_smile:

2 Likes

Could you share your full block code? and did you set any properties for Web_API at the design panel?

Thank you for your help.

1 Like