JSFiddle - React, Tailwind, and code Playground
by morphcast
HTML
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<script src="https://ai-sdk.morphcast.com/stage/ai-sdk.js"></script>
<div id="age"> - </div>
<div id="gender"> - </div>
<div id="emotion"></div>
<div id="chart">
</div>
<div id="emo_over">
<span>CLICK TO START</span>
</div>
<div id="loader">
<div class="lds-ring">
<div></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
CSS
#emotion {
position: relative;
}
#emo_over {
position: absolute;
background-color: #7F8C8D;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;
cursor: pointer;
}
#emo_over span {
position: absolute;
font-size: 20px;
top: 0;
bottom: 0;
left: 0;
right: 0;
color: white;
display: block;
height: 20px;
margin: auto;
text-align: center;
}
#loader {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #7F8C8D;
z-index: 10000;
}
.lds-ring {
display: inline-block;
position: absolute;
width: 80px;
height: 80px;
margin: auto;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.lds-ring div {
box-sizing: border-box;
display: block;
position: absolute;
width: 64px;
height: 64px;
margin: 8px;
border: 8px solid #fff;
border-radius: 50%;
animation: lds-ring 1.2s cubic-bezier(0.5, 0, 0.5, 1) infinite;
border-color: #fff transparent transparent transparent;
}
.lds-ring div:nth-child(1) {
animation-delay: -0.45s;
}
.lds-ring div:nth-child(2) {
animation-delay: -0.3s;
}
.lds-ring div:nth-child(3) {
animation-delay: -0.15s;
}
@keyframes lds-ring {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
JavaScript
CY.loader()
.maxInputFrameSize(320)
.addModule(CY.modules().FACE_DETECTOR.name, {
maxInputFrameSize: 160
})
.addModule(CY.modules().FACE_ATTENTION.name, {})
.addModule(CY.modules().FACE_EMOTION.name, {
/* smoothness: Number, default 0.40. Value should be in range [0,1). A value near 1 provides greater smoothing and slower response (longer delay). Lower values provide lesser smoothing but faster response.
*/
smoothness: 0.4
})
.addModule(CY.modules().FACE_AGE.name, {
windowSizeMs: 8000, // Dimensione della finestra a 10 FPS scorrevole su cui viene fatta la media.
maxVarianceCutoff: Math.pow(6, 2), // Varianza massima per considerare la media di buona qualitĂ
maxStartWaitMs: 6000, // Tempo di attesa massimo per ricevere un valore, indipendentemente da
numericalStability: 7
})
.addModule(CY.modules().FACE_GENDER.name, {
smoothness: 0.95,
threshold: 0.7
})
.load()
.then(({
start,
stop
}) => start().then(() => LOADER.style.display = "none"));
var options = {
chart: {
height: 350,
type: 'radar',
},
yaxis: {
min: 0,
max: 50
},
series: [],
title: {
text: 'Emotions'
},
labels: []
};
let emoStarted = false;
const chart = new ApexCharts(document.querySelector("#emotion"), options);
chart.render();
const AGE = document.querySelector("#age");
const GEN = document.querySelector("#gender");
const EMO_START = document.querySelector("#emo_over");
const LOADER = document.querySelector("#loader");
EMO_START.onclick = function() {
emoStarted = true;
EMO_START.style.display = "none";
setTimeout(() => {
emoStarted = false;
alert("Tracking Emozioni terminato");
}, 5000);
}
window.addEventListener(CY.modules().FACE_AGE.eventName, (evt) => {
AGE.innerHTML = evt.detail.output.numericAge;
});
window.addEventListener(CY.modules().FACE_GENDER.eventName, (evt) => {
GEN.innerHTML = evt.detail.output.mostConfident;
});
data = {
Angry: 0,
Surprise: 0,
Fear:...