Gaia Mood Map v1
by morphcast
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MorphCast AI HTML5 SDK - Gaia Map Code v1</title>
<meta name="mphtools-feature" content="compatibilityUI, cameraPrivacyPopup, compatibilityAutoCheck">
</head>
<body style="font-size:12px;">
<script src="https://sdk.morphcast.com/mphtools/v1.0/mphtools.js"></script>
<script src="https://ai-sdk.morphcast.com/v1.14/ai-sdk.js"></script>
Gaia Map Code v1
<b><div id="final_mood"></div></b><br />
<input type="file" id="getimage" hidden>
<fieldset hidden>
<legend>Your image here</legend>
<img id="imgstore" />
</fieldset>
</body>
</html>
JavaScript
////// CODE FOR GAIA MOOD
/**
* Maps MorphCast moods and emotions to a Gaia mood
*/
class GaiaMoodMapperV1 {
static getDominantGaiaMood(emos, moods) {
const gaia_moods = this.getGaiaMoods(emos, moods);
const best = getArgMaxKey(gaia_moods);
return {
name: best,
conf: gaia_moods[best]
}
}
static getGaiaMoods(emos, moods) {
let renamedEmos = this._addPrefixToKeys(emos, 'E_');
let renamedMoods = this._addPrefixToKeys(moods, 'M_');
const merged = {
...renamedEmos,
...renamedMoods
};
return Object.keys(merged).reduce((acc, key) => {
const currentValue = merged[key];
const gaiaKey = GaiaMoodMapperV1.MAP[key];
const previousValue = acc[gaiaKey] || 0;
acc[gaiaKey] = Math.max(previousValue, currentValue);
return acc;
}, {});
}
static _addPrefixToKeys(emos, prefix) {
return Object.keys(emos).reduce((acc, key) => {
acc[prefix + key] = emos[key];
return acc;
}, {});
}
}
GaiaMoodMapperV1.MAP = {
"E_Neutral": "Neutral",
"E_Angry": "Angry",
"E_Disgust": "Sad",
"E_Surprise": "Happy",
"E_Fear": "Insecure",
"E_Happy": "Happy",
"E_Sad": "Sad",
"M_Angry" : "Angry",
"M_Annoyed" : "Angry",
"M_Enraged" : "Aggressive",
"M_Frustrated" : "Sad",
"M_Afraid" : "Insecure",
"M_Uncomfortable" : "Insecure",
"M_Worried" : "Insecure",
"M_Anxious" : "Insecure",
"M_Happy" : "Happy",
"M_Amused" : "Happy",
"M_Good" : "Happy",
"M_Pleased" : "Happy",
"M_Satisfied" : "Confident",
"M_Excited" : "Romantic",
"M_Hopeful" : "Confident",
"M_Apathetic" : "Insecure",
"M_Bored" : "Sad",
"M_Discontent" : "Sad",
"M_Calm" : "Calm",
"M_Content" : "Happy",
"M_Peaceful" : "Calm",
"M_Relaxed" : "Calm",
"M_Sad" : "Sad",
"M_Depressed" : "Sad",
"M_Disappointed" : "Sad",
"M_Melancholy" : "Sad",
"M_Distressed" : "Insecure",
"M_Contemplative" : "Romantic",
"M_Pensive" : "Insecure",
"M_Determined" : "Confident",
...