forked from juanca20101906/juanca20101906.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
232 lines (203 loc) · 6.82 KB
/
Copy pathindex.html
File metadata and controls
232 lines (203 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>TP Sentiment Analysis</title>
<style>
.container{ width: 600px; float: left;}
.title{ font-size: 12pt; font-weight: bold;}
#analysis{
width: 400px;
min-height: 240px;
border: 1px solid #008000;
}
#camara{
width: 320px;
min-height: 240px;
border: 1px solid #008000;
align-items: right;
}
#start_over {
position: absolute;
background-color: #7C0098;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 1000;
cursor: pointer;
}
#start_over span {
position: absolute;
font-size: 30px;
top: 0;
bottom: 0;
left: 0;
right: 0;
color: white;
display: block;
height: 20px;
margin: auto;
text-align: center;
}
#myProgress {
width: 86%;
background-color: rgb(189, 185, 185);
}
#myBar {
width: 1%;
height: 30px;
background-color: #D60088;
}
#videoContainer {
margin: 0px auto;
width: 550px;
height: 450px;
border: 10px #aeadaf solid;
}
#videoElement {
width: 550px;
height: 450px;
background-color: rgb(189, 185, 185);
}
</style>
<!-- configuration for the Alert plugin -->
<meta name="mphtools-feature" content="compatibilityUI, cameraPrivacyPopup, compatibilityAutoCheck">
</head>
<body>
<h1 style="text-align:left; font-family: segoe ui;"> Sentiment Analysis </h1>
<!-- include automatic alerts about browser and App compatibility -->
<script src="https://sdk.morphcast.com/mphtools/v1.0/mphtools.js"></script>
<!-- include MorphCast SDK -->
<script src="https://ai-sdk.morphcast.com/v1.14/ai-sdk.js"></script>
<!-- include radar chart -->
<script src="https://cdn.jsdelivr.net/npm/apexcharts"></script>
<!-- elements of the page -->
<!--<div><b>Results</b></div> -->
<div class="container">
<div id="age" style="font-family: segoe ui;">Likely Age: -</div>
<div id="gender" style="font-family: segoe ui;">Likely Gender: -</div>
<div id="emotion" style="font-family: segoe ui;">Dominant Emotion: -</div>
<span style="font-family: segoe ui;">Histogram of Emotions:</span>
<div id="chart"></div>
<span style="font-family: segoe ui;">Attention level:</span>
<div id="myProgress">
<div id="myBar"></div>
</div>
</div>
<div class="container">
<div id="videoContainer">
<video autoplay="true" id="videoElement">
</video>
</div>
</div>
<div id="start_over">
<span style="font-family: segoe ui;">CLICK TO START</span>
</div>
<script>
// Complete code documentation of MorphCast AI SDK, here:
// https://ai-sdk.morphcast.com/latest/index.html
const initSDK = new Promise((res) => {
res(CY.loader()
.licenseKey("ee9ca40c75046c939854fdfacba44c48070f76db8cab")
.addModule(CY.modules().FACE_AGE.name)
.addModule(CY.modules().FACE_GENDER.name)
.addModule(CY.modules().FACE_EMOTION.name)
.addModule(CY.modules().FACE_ATTENTION.name)
.load());
});
/*
Event listeners for MorphCast SDK output
*/
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
today = mm + '/' + dd + '/' + yyyy;
window.addEventListener(CY.modules().FACE_AGE.eventName, (evt) => {
age_div.innerHTML = 'Likely Age: ' + evt.detail.output.numericAge + ' years';
console.log('Age:', evt.detail.output.numericAge);
});
window.addEventListener(CY.modules().FACE_GENDER.eventName, (evt) => {
gen_div.innerHTML = 'Likely Gender: ' + evt.detail.output.mostConfident;
console.log('Gender:', evt.detail.output.mostConfident);
});
window.addEventListener(CY.modules().FACE_EMOTION.eventName, (evt) => {
emo_div.innerHTML = 'Dominant Emotion: ' + evt.detail.output.dominantEmotion;
var myDate = new Date().toTimeString().replace(/.*(\d{2}:\d{2}:\d{2}).*/, "$1");
console.log('Date:', today)
console.log('Hour:', myDate)
console.log('Dominant Emotion:', evt.detail.output.dominantEmotion);
// data for the histogram
const emotions = evt.detail.output.emotion;
const labels = [];
const data = [];
console.log('Angry:',evt.detail.output.emotion.Angry);
console.log('Disgust:',evt.detail.output.emotion.Disgust);
console.log('Fear:',evt.detail.output.emotion.Fear);
console.log('Happy:',evt.detail.output.emotion.Happy);
console.log('Neutral:',evt.detail.output.emotion.Neutral);
console.log('Sad:',evt.detail.output.emotion.Sad);
console.log('Surprise:',evt.detail.output.emotion.Surprise);
Object.keys(emotions).forEach(k => {
labels.push(k);
data.push(parseInt((emotions[k] * 100).toFixed(0)));
});
chart.updateOptions({
labels: labels,
series:[{
name: 'Emotion',
data: data
}]
});
});
window.addEventListener(CY.modules().FACE_ATTENTION.eventName, (evt) => {
const attention = evt.detail.output.attention;
console.log('Attention:', evt.detail.output.attention);
console.log(';');
const elem = document.getElementById("myBar");
elem.style.width = attention * 100 + "%";
});
var video = document.querySelector("#videoElement");
if (navigator.mediaDevices.getUserMedia) {
navigator.mediaDevices.getUserMedia({ video: true })
.then(function (stream) {
video.srcObject = stream;
})
.catch(function (err0r) {
console.log("Something went wrong!");
});
};
/*
Elements of the page
*/
const startButton = document.querySelector("#start_over");
startButton.onclick = () => {
startButton.style.display = "none";
initSDK.then(({start}) => start());
};
const age_div = document.querySelector("#age");
const gen_div = document.querySelector("#gender");
const emo_div = document.querySelector("#emotion");
const options = {
chart: {
height: 350,
width: 500,
type: 'bar'
},
colors: ['#7C0098'],
yaxis: {
min:0,
max:100
},
series:[],
title: {
text: ''
},
labels:[]
};
const chart = new ApexCharts(document.querySelector("#chart"), options);
chart.render();
</script>
</body>
</html>