Mood Map v4 with img input
DEPLOYED - DO NOT TOUCH
by morphcast
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>MorphCast AI HTML5 SDK - Map Code v4</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>
Map Code v4
<b><div id="max"></div></b><br />
<b><div id="winner"></div></b>
<b><div id="netflix_mood_v4"></div></b><br />
<input type="file" id="getimage">
<fieldset>
<legend>Your image here</legend>
<img id="imgstore" />
</fieldset>
</body>
</html>
JavaScript
////// CODE FOR NETFLIX MOOD
class NetflixMoodMapperV4 {
static getNetflixMood(emos, moods) {
const netflix_moods = this.getNetflixMoods(emos, moods);
const best = getArgMaxKey(netflix_moods);
return {
name: best,
conf: netflix_moods[best]
}
}
static getNetflixMoods(emos, moods) {
let renamedEmos = this._addPrefixToKeys(emos, 'E_');
let renamedMoods = this._addPrefixToKeys(moods, 'M_');
const merged = {
...renamedEmos,
...renamedMoods
};
let mappedMerged = Object.keys(merged).reduce((acc, key) => {
const currentValue = merged[key];
const netflixKey = NetflixMoodMapperV4.MAP[key];
const previousValue = acc[netflixKey] || 0;
acc[netflixKey] = Math.max(previousValue, currentValue);
return acc;
}, {});
return mappedMerged;
}
static _addPrefixToKeys(emos, prefix) {
return Object.keys(emos).reduce((acc, key) => {
acc[prefix + key] = emos[key];
return acc;
}, {});
}
}
NetflixMoodMapperV4.MAP = {
"E_Neutral": "Neutral",
"E_Angry": "Angry",
"E_Disgust": "Disgust",
"E_Surprise": "Surprise",
"E_Fear": "Fear",
"E_Happy": "Happy",
"E_Sad": "Sad",
"M_Angry": "Angry",
"M_Annoyed": "Angry",
"M_Enraged": "Angry",
"M_Frustrated": "Angry",
"M_Afraid": "Fear",
"M_Uncomfortable": "Fear",
"M_Worried": "Fear",
"M_Anxious": "Fear",
"M_Happy": "Happy",
"M_Amused": "Happy",
"M_Good": "Happy",
"M_Pleased": "Happy",
"M_Satisfied": "Happy",
"M_Excited": "Excited",
"M_Hopeful": "Hopeful",
"M_Apathetic": "Meh",
"M_Bored": "Meh",
"M_Discontent": "Meh",
"M_Calm": "Relaxed",
"M_Content": "Relaxed",
"M_Peaceful": "Relaxed",
"M_Relaxed": "Relaxed",
"M_Sad": "Sad",
"M_Depressed": "Sad",
"M_Disappointed": "Sad",
"M_Melancholy": "Sad",
"M_Distressed": "Stressed",
"M_Contemplative": "Thoughtful",
"M_Pensive": "Thoughtful"
};
function getArgMaxKey(dict) {
return Object.keys(dict).reduce((a, b)...