-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
58 lines (49 loc) · 1.37 KB
/
Copy pathscript.js
File metadata and controls
58 lines (49 loc) · 1.37 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
function openFileDialog (){
$("#upload").trigger('click');
}
function readURL(files) {
if (files[0]) {
// A file reader to send the Microsoft Cognitive Services
var emotionReader = new FileReader();
emotionReader.onload = getEmotion;
emotionReader.readAsArrayBuffer(files[0]);
// A file reader to preview the image on the screen
var previewReader = new FileReader();
previewReader.onload = preview;
previewReader.readAsDataURL(files[0]);
}
}
function preview(e){
$('#pic').attr('src', e.target.result);
}
function getEmotion (e) {
$(".title").text("Let me see...");
$.ajax({
url : 'https://api.projectoxford.ai/emotion/v1.0/recognize',
type: 'POST',
processData: false,
contentType: "application/octet-stream",
data: e.target.result,
headers: {
"Content-Type": "application/octet-stream",
"Ocp-Apim-Subscription-Key": "e0b5b29480894ae6b192b98380dd550e"
},
success: displayEmotion,
error: function(jqXHR, textStatus, errorThrown)
{
debugger;
}
});
}
function displayEmotion(data){
var scores = data[0].scores || {};
var mostLikelyEmotion = "";
var maxScore = 0;
Object.keys(scores).forEach(function(emotion){
if (scores[emotion] > maxScore){
maxScore = scores[emotion];
mostLikelyEmotion = emotion;
}
});
$(".title").text("I sense " + mostLikelyEmotion);
}