-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
141 lines (121 loc) Β· 6.23 KB
/
index.html
File metadata and controls
141 lines (121 loc) Β· 6.23 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
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]> <html class="no-js"> <!--<![endif]-->
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@800&display=swap" rel="stylesheet">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@300;400&display=swap" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/earlyaccess/notosanskr.css">
<title>AI MASK CHECKING PROGRAM</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="main-background"></div>
<div class="main-logo">
<img src="images/HUSK_SMU.png" style="width:90px;
height: 70px;">
</div>
<nav>
<ul>
<li><a href="intro.html" >HUSK</a></li>
<li><a href="about.html">ABOUT</a></li>
</ul>
</nav>
<div class="main-content"></div>
<div class="main_text">SHOW YOUR FACE</div>
<button type="button" onclick="init()">Start</button>
<div class="label-container" id="label-container"></div>
</div>
<div class="square"></div>
<div class="webcam-container" id="webcam-container"></div>
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@1.3.1/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/image@0.8/dist/teachablemachine-image.min.js"></script>
<script type="text/javascript">
// More API functions here:
// https://github.com/googlecreativelab/teachablemachine-community/tree/master/libraries/image
// the link to your model provided by Teachable Machine export panel
const URL = "https://teachablemachine.withgoogle.com/models/WCUO2kwJa/";
let model, webcam, labelContainer, maxPredictions;
const data={
"λ§μ€ν¬μμ":{
"name":"λ§μ€ν¬ μμ",
"message" : "λ§μ€ν¬λ₯Ό μ¨μ£ΌμΈμ."
},
"λ§μ€ν¬μ":{
"name":"λ§μ€ν¬ μ",
"message" : "μμ ν©λλ€."
},
"μ½ν±μ€ν¬":{
"name":"μ½μ€ν¬&ν±μ€ν¬",
"message":"λ§μ€ν¬λ₯Ό μ λλ‘ μ¨μ£ΌμΈμ."
}
}
// Load the image model and setup the webcam
async function init() {
const modelURL = URL + "model.json";
const metadataURL = URL + "metadata.json";
model = await tmImage.load(modelURL, metadataURL);
maxPredictions = model.getTotalClasses();
// Convenience function to setup a webcam
const flip = true; // whether to flip the webcam
webcam = new tmImage.Webcam(700, 700, flip); // width, height, flip
await webcam.setup(); // request access to the webcam
await webcam.play();
window.requestAnimationFrame(loop);
// append elements to the DOM
document.getElementById("webcam-container").appendChild(webcam.canvas);
labelContainer = document.getElementById("label-container");
for (let i = 0; i < maxPredictions; i++) { // and class labels
labelContainer.appendChild(document.createElement("div"));
}
}
async function loop() {
webcam.update(); // update the webcam frame
await predict();
window.requestAnimationFrame(loop);
}
var status="λ§μ€ν¬ μμ"
var audio
// run the webcam image through the image model
async function predict() {
const prediction = await model.predict(webcam.canvas);
// predict can take in an image, video or canvas html element
if(prediction[0].probability.toFixed(2) == '1.00'){
if(status=="λ§μ€ν¬ μ"||status=="μ½ν±μ€ν¬"){
audio=new Audio('Audio1.mp3');
audio.play();
}
status="λ§μ€ν¬ μμ"
}else if(prediction[1].probability.toFixed(2) == '1.00'){
if(status=="λ§μ€ν¬ μμ"||status=="μ½ν±μ€ν¬"){
audio=new Audio('Audio2.m4a');
audio.play();}
status="λ§μ€ν¬ μ"
}else if(prediction[2].probability.toFixed(2) == '1.00'){
if(status=="λ§μ€ν¬ μ"||status=="λ§μ€ν¬ μμ"){
var audio=new Audio('Audio3.m4a');
audio.play();}
status="μ½ν±μ€ν¬"
}
for (let i = 0; i < maxPredictions; i++) {
if(prediction[i].probability.toFixed(2) == '1.00'){
const item=data[prediction[i].className]
labelContainer.innerHTML=`${item.message}`
}
// const classPrediction =
// prediction[i].className + ": " + prediction[i].probability.toFixed(2);
// labelContainer.childNodes[i].innerHTML = classPrediction;
}
}
</script>
</body>
</html>