Spaces:
Running
Running
Update index.html
Browse files- index.html +69 -44
index.html
CHANGED
|
@@ -3,12 +3,18 @@
|
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
| 6 |
-
<title>Hot / Cold / Normal Indicator</title>
|
| 7 |
<style>
|
| 8 |
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; margin: 24px; }
|
| 9 |
.row { display:flex; gap:16px; flex-wrap:wrap; align-items:flex-start; }
|
| 10 |
.card { border:1px solid #ddd; border-radius:16px; padding:16px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
#lamp {
|
| 14 |
width: 240px; height: 240px; border-radius: 999px;
|
|
@@ -23,22 +29,16 @@
|
|
| 23 |
#lamp.normal { background: #757575; box-shadow: 0 10px 30px rgba(117,117,117,.25); }
|
| 24 |
#lamp.pulse { transform: scale(1.03); }
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
.controls { display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
|
| 30 |
-
.small { color:#666; font-size: 14px; line-height:1.4; }
|
| 31 |
-
input[type="range"] { width: 220px; }
|
| 32 |
-
#preds { font-size: 14px; white-space: pre; }
|
| 33 |
-
.badge { display:inline-block; padding:2px 8px; border-radius:999px; border:1px solid #ddd; font-size:12px; color:#444; }
|
| 34 |
</style>
|
| 35 |
</head>
|
| 36 |
|
| 37 |
<body>
|
| 38 |
-
<h2>Teachable Machine λͺ¨μ
νμ β π΄/π΅/βͺ + μμ±
|
| 39 |
<p class="small">
|
| 40 |
-
|
| 41 |
-
|
| 42 |
</p>
|
| 43 |
|
| 44 |
<div class="row">
|
|
@@ -62,9 +62,12 @@
|
|
| 62 |
</div>
|
| 63 |
|
| 64 |
<div style="margin-top:12px;">
|
| 65 |
-
<video
|
|
|
|
| 66 |
</div>
|
| 67 |
|
|
|
|
|
|
|
| 68 |
<p class="small" style="margin-top:10px;">
|
| 69 |
ν: μκ³κ°μ μ¬λ¦¬λ©΄ λ βνμ€ν λλ§β λμμ/μΆμμκ° λΉλλ€.
|
| 70 |
</p>
|
|
@@ -85,15 +88,15 @@
|
|
| 85 |
</div>
|
| 86 |
</div>
|
| 87 |
|
| 88 |
-
<!-- TFJS + Teachable Machine -->
|
| 89 |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.20.0/dist/tf.min.js"></script>
|
| 90 |
-
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/
|
| 91 |
|
| 92 |
<script>
|
| 93 |
-
// λ€ Teachable Machine λͺ¨λΈ μ£Όμ
|
| 94 |
const MODEL_URL = "https://teachablemachine.withgoogle.com/models/IMOO3vPNb/";
|
| 95 |
|
| 96 |
-
// ν΄λμ€ μ΄λ¦ (
|
| 97 |
const CLASS_HOT = "λμΈλ";
|
| 98 |
const CLASS_COLD = "μΆμΈλ";
|
| 99 |
const CLASS_NORMAL = "νμμ";
|
|
@@ -106,6 +109,7 @@
|
|
| 106 |
const predsEl = document.getElementById("preds");
|
| 107 |
const statusEl = document.getElementById("status");
|
| 108 |
const lastSayEl = document.getElementById("lastSay");
|
|
|
|
| 109 |
|
| 110 |
const btnStart = document.getElementById("btnStart");
|
| 111 |
const btnStop = document.getElementById("btnStop");
|
|
@@ -113,7 +117,9 @@
|
|
| 113 |
const threshVal = document.getElementById("threshVal");
|
| 114 |
const voiceOn = document.getElementById("voiceOn");
|
| 115 |
const speakNormal = document.getElementById("speakNormal");
|
| 116 |
-
|
|
|
|
|
|
|
| 117 |
|
| 118 |
thresh.addEventListener("input", () => threshVal.textContent = (+thresh.value).toFixed(2));
|
| 119 |
|
|
@@ -154,32 +160,38 @@
|
|
| 154 |
const pNormal = getProb(predictions, CLASS_NORMAL);
|
| 155 |
|
| 156 |
const arr = [
|
| 157 |
-
{state:
|
| 158 |
-
{state:
|
| 159 |
-
{state:
|
| 160 |
-
].sort((a,b)
|
| 161 |
|
| 162 |
const top = arr[0];
|
| 163 |
-
if (top.p < threshold) {
|
| 164 |
-
return {state:"normal", text:"νμμ"};
|
| 165 |
-
}
|
| 166 |
return top;
|
| 167 |
}
|
| 168 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
async function loop() {
|
| 170 |
webcam.update();
|
| 171 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 172 |
|
| 173 |
predsEl.textContent = predictions
|
| 174 |
.map(p => `${p.className}: ${p.probability.toFixed(2)}`)
|
| 175 |
.join("\n");
|
| 176 |
|
| 177 |
-
const
|
| 178 |
-
const d = decideState(predictions, th);
|
| 179 |
|
| 180 |
if (d.state !== lastState) {
|
| 181 |
lastState = d.state;
|
| 182 |
-
|
| 183 |
if (d.state === "hot") {
|
| 184 |
setLamp("hot", "λμμ");
|
| 185 |
speak("λμμ");
|
|
@@ -196,23 +208,36 @@
|
|
| 196 |
}
|
| 197 |
|
| 198 |
async function start() {
|
|
|
|
| 199 |
btnStart.disabled = true;
|
| 200 |
setLamp("normal", "λ‘λ©μ€...");
|
| 201 |
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
}
|
| 217 |
|
| 218 |
function stop() {
|
|
|
|
| 3 |
<head>
|
| 4 |
<meta charset="utf-8" />
|
| 5 |
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
| 6 |
+
<title>Hot / Cold / Normal Indicator (Pose)</title>
|
| 7 |
<style>
|
| 8 |
body { font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif; margin: 24px; }
|
| 9 |
.row { display:flex; gap:16px; flex-wrap:wrap; align-items:flex-start; }
|
| 10 |
.card { border:1px solid #ddd; border-radius:16px; padding:16px; box-shadow: 0 2px 10px rgba(0,0,0,.04); }
|
| 11 |
+
.controls { display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
|
| 12 |
+
button { padding: 10px 14px; border-radius: 12px; border: 1px solid #ccc; background:#fff; cursor:pointer; }
|
| 13 |
+
button:disabled { opacity:.5; cursor:not-allowed; }
|
| 14 |
+
.small { color:#666; font-size: 14px; line-height:1.4; }
|
| 15 |
+
input[type="range"] { width: 220px; }
|
| 16 |
+
#preds { font-size: 14px; white-space: pre; }
|
| 17 |
+
.badge { display:inline-block; padding:2px 8px; border-radius:999px; border:1px solid #ddd; font-size:12px; color:#444; }
|
| 18 |
|
| 19 |
#lamp {
|
| 20 |
width: 240px; height: 240px; border-radius: 999px;
|
|
|
|
| 29 |
#lamp.normal { background: #757575; box-shadow: 0 10px 30px rgba(117,117,117,.25); }
|
| 30 |
#lamp.pulse { transform: scale(1.03); }
|
| 31 |
|
| 32 |
+
canvas { border-radius: 14px; background:#000; max-width: 100%; }
|
| 33 |
+
.error { color:#b00020; font-weight:700; margin-top:10px; white-space:pre-wrap; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
</style>
|
| 35 |
</head>
|
| 36 |
|
| 37 |
<body>
|
| 38 |
+
<h2>Teachable Machine λͺ¨μ
(Pose) νμ β π΄/π΅/βͺ + μμ±</h2>
|
| 39 |
<p class="small">
|
| 40 |
+
Pose λͺ¨λΈμ λΆλ¬μ μΉμΊ μμ μ€μκ° λΆλ₯νκ³ ,
|
| 41 |
+
<b>λΉ¨κ°λΆ(λμμ) / νλλΆ(μΆμμ) / νμλΆ(νμμ)</b> + μμ±μΌλ‘ μλ €μ€λλ€.
|
| 42 |
</p>
|
| 43 |
|
| 44 |
<div class="row">
|
|
|
|
| 62 |
</div>
|
| 63 |
|
| 64 |
<div style="margin-top:12px;">
|
| 65 |
+
<!-- Poseλ video λμ canvasλ‘ λ λλ§νλκ² μμ μ -->
|
| 66 |
+
<canvas id="canvas" width="420" height="315"></canvas>
|
| 67 |
</div>
|
| 68 |
|
| 69 |
+
<div id="err" class="error"></div>
|
| 70 |
+
|
| 71 |
<p class="small" style="margin-top:10px;">
|
| 72 |
ν: μκ³κ°μ μ¬λ¦¬λ©΄ λ βνμ€ν λλ§β λμμ/μΆμμκ° λΉλλ€.
|
| 73 |
</p>
|
|
|
|
| 88 |
</div>
|
| 89 |
</div>
|
| 90 |
|
| 91 |
+
<!-- TFJS + Teachable Machine (Pose) -->
|
| 92 |
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@4.20.0/dist/tf.min.js"></script>
|
| 93 |
+
<script src="https://cdn.jsdelivr.net/npm/@teachablemachine/pose@0.8/dist/teachablemachine-pose.min.js"></script>
|
| 94 |
|
| 95 |
<script>
|
| 96 |
+
// λ€ Teachable Machine λͺ¨λΈ μ£Όμ (λμ / ν¬ν¨)
|
| 97 |
const MODEL_URL = "https://teachablemachine.withgoogle.com/models/IMOO3vPNb/";
|
| 98 |
|
| 99 |
+
// ν΄λμ€ μ΄λ¦ (Teachable Machineμμ λ§λ κ·Έλλ‘)
|
| 100 |
const CLASS_HOT = "λμΈλ";
|
| 101 |
const CLASS_COLD = "μΆμΈλ";
|
| 102 |
const CLASS_NORMAL = "νμμ";
|
|
|
|
| 109 |
const predsEl = document.getElementById("preds");
|
| 110 |
const statusEl = document.getElementById("status");
|
| 111 |
const lastSayEl = document.getElementById("lastSay");
|
| 112 |
+
const errEl = document.getElementById("err");
|
| 113 |
|
| 114 |
const btnStart = document.getElementById("btnStart");
|
| 115 |
const btnStop = document.getElementById("btnStop");
|
|
|
|
| 117 |
const threshVal = document.getElementById("threshVal");
|
| 118 |
const voiceOn = document.getElementById("voiceOn");
|
| 119 |
const speakNormal = document.getElementById("speakNormal");
|
| 120 |
+
|
| 121 |
+
const canvas = document.getElementById("canvas");
|
| 122 |
+
const ctx = canvas.getContext("2d");
|
| 123 |
|
| 124 |
thresh.addEventListener("input", () => threshVal.textContent = (+thresh.value).toFixed(2));
|
| 125 |
|
|
|
|
| 160 |
const pNormal = getProb(predictions, CLASS_NORMAL);
|
| 161 |
|
| 162 |
const arr = [
|
| 163 |
+
{state:"hot", text:"λμμ", p:pHot},
|
| 164 |
+
{state:"cold", text:"μΆμμ", p:pCold},
|
| 165 |
+
{state:"normal", text:"νμμ", p:pNormal},
|
| 166 |
+
].sort((a,b)=>b.p-a.p);
|
| 167 |
|
| 168 |
const top = arr[0];
|
| 169 |
+
if (top.p < threshold) return {state:"normal", text:"νμμ"};
|
|
|
|
|
|
|
| 170 |
return top;
|
| 171 |
}
|
| 172 |
|
| 173 |
+
function drawWebcamToCanvas() {
|
| 174 |
+
// webcam.canvasλ tmPoseκ° λ΄λΆμ μΌλ‘ μ
λ°μ΄νΈνλ μΊλ²μ€
|
| 175 |
+
ctx.drawImage(webcam.canvas, 0, 0, canvas.width, canvas.height);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
async function loop() {
|
| 179 |
webcam.update();
|
| 180 |
+
|
| 181 |
+
// Pose μΆμ + λΆλ₯
|
| 182 |
+
const { posenetOutput } = await model.estimatePose(webcam.canvas);
|
| 183 |
+
const predictions = await model.predict(posenetOutput);
|
| 184 |
+
|
| 185 |
+
drawWebcamToCanvas();
|
| 186 |
|
| 187 |
predsEl.textContent = predictions
|
| 188 |
.map(p => `${p.className}: ${p.probability.toFixed(2)}`)
|
| 189 |
.join("\n");
|
| 190 |
|
| 191 |
+
const d = decideState(predictions, +thresh.value);
|
|
|
|
| 192 |
|
| 193 |
if (d.state !== lastState) {
|
| 194 |
lastState = d.state;
|
|
|
|
| 195 |
if (d.state === "hot") {
|
| 196 |
setLamp("hot", "λμμ");
|
| 197 |
speak("λμμ");
|
|
|
|
| 208 |
}
|
| 209 |
|
| 210 |
async function start() {
|
| 211 |
+
errEl.textContent = "";
|
| 212 |
btnStart.disabled = true;
|
| 213 |
setLamp("normal", "λ‘λ©μ€...");
|
| 214 |
|
| 215 |
+
try {
|
| 216 |
+
const modelURL = MODEL_URL + "model.json";
|
| 217 |
+
const metadataURL = MODEL_URL + "metadata.json";
|
| 218 |
+
model = await tmPose.load(modelURL, metadataURL);
|
| 219 |
+
|
| 220 |
+
// Webcam (Pose)
|
| 221 |
+
webcam = new tmPose.Webcam(420, 315, true);
|
| 222 |
+
await webcam.setup(); // μ¬κΈ°μ κΆν λ§νλ©΄ λ©μΆ€
|
| 223 |
+
await webcam.play();
|
| 224 |
+
|
| 225 |
+
btnStop.disabled = false;
|
| 226 |
+
setLamp("normal", "λΆμμ€");
|
| 227 |
+
lastState = "normal";
|
| 228 |
+
rafId = requestAnimationFrame(loop);
|
| 229 |
+
|
| 230 |
+
} catch (e) {
|
| 231 |
+
// μ€ν¨νλ©΄ λ²νΌ λ€μ μ΄λ¦¬κ³ μλ¬ νμ
|
| 232 |
+
btnStart.disabled = false;
|
| 233 |
+
btnStop.disabled = true;
|
| 234 |
+
setLamp("normal", "μ€ν¨");
|
| 235 |
+
errEl.textContent =
|
| 236 |
+
"β μμ μ€ν¨\n\n" +
|
| 237 |
+
(e?.message ? e.message : String(e)) +
|
| 238 |
+
"\n\n- μ£Όμμ°½ μλ¬Όμ μμ μΉ΄λ©λΌ νμ©νλμ§ νμΈ\n- λ€λ₯Έ ν/μ±μ΄ μΉ΄λ©λΌλ₯Ό μ μ μ€μ΄λ©΄ μ’
λ£\n- ν¬λ‘¬(PC)μμ μ¬μλ κΆμ₯";
|
| 239 |
+
console.error(e);
|
| 240 |
+
}
|
| 241 |
}
|
| 242 |
|
| 243 |
function stop() {
|