-
Notifications
You must be signed in to change notification settings - Fork 1
/
Sentiment-Analysis.js
55 lines (46 loc) · 1.72 KB
/
Sentiment-Analysis.js
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
let model;
model = ml5.sentiment('movieReviews', Ready);
function on_key_up() {
getSentiment();
}
function getSentiment() {
var text = document.getElementById("text").value;
const prediction = model.predict(text);
if (prediction.score >= 0.9){
document.getElementById("show").innerHTML = "🤩";
}
else if (prediction.score < 0.9 && prediction.score >= 0.8){
document.getElementById("show").innerHTML = "😍";
}
else if (prediction.score < 0.8 && prediction.score >= 0.7){
document.getElementById("show").innerHTML = "😇";
}
else if (prediction.score < 0.7 && prediction.score >= 0.6){
document.getElementById("show").innerHTML = "😃";
}
else if (prediction.score < 0.6 && prediction.score >= 0.5){
document.getElementById("show").innerHTML = "🙂";
}
else if (prediction.score < 0.4 && prediction.score >= 0.3){
document.getElementById("show").innerHTML = "🙁";
}
else if (prediction.score < 0.3 && prediction.score >= 0.2){
document.getElementById("show").innerHTML = "😔";
}
else if (prediction.score < 0.2 && prediction.score >= 0.1){
document.getElementById("show").innerHTML = "🤬";
}
else if (prediction.score < 0.1){
document.getElementById("show").innerHTML = "💩";
}
document.getElementById("score").innerHTML = (`${(prediction.score*10).toFixed(1)}/10`);
}
function Ready() {
var elem = document.getElementById('wait');
elem.parentNode.removeChild(elem);
var newElement = document.createElement("p");
var newNode = document.createTextNode("Model is ready");
newElement.appendChild(newNode);
var getElement = document.getElementById("show_div");
getElement.appendChild(newElement);
}