-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWEB_main.html
216 lines (194 loc) · 6.87 KB
/
WEB_main.html
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
<!DOCTYPE html>
<html>
<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<!-- Bootstrap CSS -->
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"
integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z"
crossorigin="anonymous"
/>
<title>Hello, world!</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light nav-distance">
<a class="navbar-brand" href="#">TEST</a>
<button
class="navbar-toggler"
type="button"
data-toggle="collapse"
data-target="#navbarNav"
aria-controls="navbarNav"
aria-expanded="false"
aria-label="Toggle navigation"
>
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item active">
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Features</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Pricing</a>
</li>
<li class="nav-item">
<a class="nav-link disabled" href="#" tabindex="-1" aria-disabled="true"
>Disabled</a
>
</li>
</ul>
</div>
</nav>
<section class="section">
<h1 class="title">title</h1>
<h2 class="subtitle">subtitle</h2>
</section>
<!-- <script
class="jsbin"
src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"
></script> -->
<div class="container file-upload"> <!-- 이미지 업로드하는 부분-->
<div class="image-upload-wrap">
<input
class="file-upload-input"
type="file"
onchange="readURL(this);"
accept="image/*"
/>
<div class="drag-text">
<img src="img/upload.svg" class="mt-5 upload" style="width: 20%;" />
<h3 class="mb-5 upload-text">얼굴 사진을 올려놓거나 눌러서 업로드하세요!</h3>
</div>
</div>
<div class="file-upload-content">
<img class="file-upload-image" id="face-image" src="#" alt="your image" />
<p class="result-message"></p>
<div id="label-container"></div>
<div class="image-title-wrap">
<button type="button" onclick="removeUpload()" class="remove-image">
Remove <span class="image-title">Uploaded Image</span>
</button>
</div>
</div>
</div>
<div id="webcam-container"></div>
<div id="disqus_thread"></div>
<script>
(function () {
// DON'T EDIT BELOW THIS LINE
var d = document,
s = d.createElement('script');
s.src = 'https://naducoding.disqus.com/embed.js';
s.setAttribute('data-timestamp', +new Date());
(d.head || d.body).appendChild(s);
})();
</script>
<noscript
>Please enable JavaScript to view the
<a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript
>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script
src="https://code.jquery.com/jquery-3.5.1.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"
></script>
<script
src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"
></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"
integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV"
crossorigin="anonymous"
></script>
<!-- 결과 출력 -->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/[email protected]/dist/tf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/[email protected]/dist/teachablemachine-image.min.js"></script>
<script>
function readURL(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('.image-upload-wrap').hide();
$('.file-upload-image').attr('src', e.target.result);
$('.file-upload-content').show();
$('.image-title').html(input.files[0].name);
};
reader.readAsDataURL(input.files[0]);
init().then(() => {
console.log('hello');
predict();
});
} else {
removeUpload();
}
}
function removeUpload() {
$('.file-upload-input').replaceWith($('.file-upload-input').clone());
$('.file-upload-content').hide();
$('.image-upload-wrap').show();
}
$('.image-upload-wrap').bind('dragover', function () {
$('.image-upload-wrap').addClass('image-dropping');
});
$('.image-upload-wrap').bind('dragleave', function () {
$('.image-upload-wrap').removeClass('image-dropping');
});
</script>
<script type="text/javascript">
const URL = 'https://teachablemachine.withgoogle.com/models/PQZFCSNfE/'; // teachablemachine 주소
let model, webcam, labelContainer, maxPredictions;
async function init() {
const modelURL = URL + 'model.json';
const metadataURL = URL + 'metadata.json';
model = await tmImage.load(modelURL, metadataURL);
maxPredictions = model.getTotalClasses();
labelContainer = document.getElementById('label-container');
for (let i = 0; i < maxPredictions; i++) {
labelContainer.appendChild(document.createElement('div'));
}
}
async function predict() {
var image = document.getElementById('face-image');
const prediction = await model.predict(image, false);
prediction.sort((a, b) => parseFloat(b.probability) - parseFloat(a.probability));
console.log(prediction[0].className);
console.log(prediction[1].className);
var resultMessege; // 결과 출력
switch (prediction[0].className) {
case "미스터션샤인 - 유진 초이 (이병헌)":
resultMessege = "미스터션샤인 - 유진 초이 (이병헌)"
break;
case "미스터션샤인 - 김희성 (변요한)":
resultMessege = "미스터션샤인 - 김희성 (변요한)"
break;
case "미스터션샤인 - 고애신 (김태리)":
resultMessege = "미스터션샤인 - 고애신 (김태리)"
break;
case "미스터션샤인 - 구동매 (유연석)":
resultMessege = "미스터션샤인 - 구동매 (유연석)"
break;
default:
resultMessege = "알 수 없음"
}
$('.result-message').html(resultMessege);
for (let i = 0; i < maxPredictions; i++) { // 퍼센트 순위 출력
const classPrediction =
prediction[i].className + ': ' + prediction[i].probability.toFixed(2) * 100+"%";
labelContainer.childNodes[i].innerHTML = classPrediction;
}
}
</script>
</body>
</html>