Download index.html from iwan7705/killer: direct link, hf CLI and curl.
- Browser
- Download file 9.42 kB
-
https://huggingface.co/spaces/iwan7705/killer/resolve/main/index.html
- Command line
-
hf download hf://spaces/iwan7705/killer/index.html
-
curl -L -o index.html https://huggingface.co/spaces/iwan7705/killer/resolve/main/index.html
9.42 kB
| <html lang="id"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Sistem Deteksi Pose</title> | |
| <style> | |
| /* Desain dasar yang bersih dan lembut */ | |
| body { | |
| font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif; | |
| background: linear-gradient(135deg, #e0e7ff 0%, #f3f4f6 100%); | |
| margin: 0; | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| justify-content: center; | |
| min-height: 100vh; | |
| color: #334155; | |
| } | |
| /* Card utama yang simpel dan membulat */ | |
| .app-container { | |
| background-color: #ffffff; | |
| padding: 2.5rem 2rem; | |
| border-radius: 24px; | |
| box-shadow: 0 20px 40px rgba(15, 23, 42, 0.08); | |
| text-align: center; | |
| max-width: 420px; | |
| width: 90%; | |
| } | |
| h1 { | |
| font-size: 1.4rem; | |
| font-weight: 700; | |
| color: #1e293b; | |
| margin: 0 0 0.5rem 0; | |
| } | |
| p.subtitle { | |
| font-size: 0.95rem; | |
| color: #64748b; | |
| margin-bottom: 1.8rem; | |
| } | |
| /* Tombol melengkung bergaya modern */ | |
| button { | |
| background-color: #4f46e5; | |
| color: white; | |
| border: none; | |
| padding: 12px 32px; | |
| font-size: 1rem; | |
| font-weight: 600; | |
| border-radius: 9999px; /* Bentuk pil */ | |
| cursor: pointer; | |
| transition: all 0.3s ease; | |
| margin-bottom: 1.5rem; | |
| box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3); | |
| } | |
| button:hover { | |
| background-color: #4338ca; | |
| transform: translateY(-2px); | |
| } | |
| button:active { | |
| transform: translateY(0); | |
| } | |
| /* Area kamera tanpa border kasar */ | |
| #canvas-wrapper { | |
| display: inline-block; | |
| border-radius: 16px; | |
| overflow: hidden; | |
| background-color: #f8fafc; | |
| margin-bottom: 1.5rem; | |
| box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05); | |
| padding: 8px; | |
| border: 1px solid #f1f5f9; | |
| } | |
| canvas { | |
| display: block; | |
| border-radius: 12px; | |
| } | |
| /* Daftar prediksi yang rapi */ | |
| #label-container { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 12px; | |
| } | |
| .prediction-label { | |
| background-color: #f8fafc; | |
| padding: 14px 18px; | |
| border-radius: 12px; | |
| font-weight: 500; | |
| font-size: 0.95rem; | |
| display: flex; | |
| justify-content: space-between; | |
| color: #475569; | |
| transition: all 0.3s ease; | |
| border: 1px solid transparent; | |
| } | |
| /* Indikator visual saat pose terdeteksi (Warna hijau lembut) */ | |
| .active-prediction { | |
| background-color: #ecfdf5; | |
| border-color: #a7f3d0; | |
| color: #059669; | |
| font-weight: 600; | |
| transform: scale(1.02); | |
| box-shadow: 0 4px 10px rgba(16, 185, 129, 0.1); | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="app-container"> | |
| <h1>Deteksi Pose Interaktif</h1> | |
| <p class="subtitle">Peragakan: <b>Hidup</b>, <b>Diam</b>, <b>Celeng</b>, <b>Enam</b></p> | |
| <button type="button" id="start-btn" onclick="init()">Nyalakan Kamera</button> | |
| <div id="canvas-wrapper"> | |
| <!-- Canvas tempat video muncul --> | |
| <canvas id="canvas"></canvas> | |
| </div> | |
| <div id="label-container"></div> | |
| </div> | |
| <!-- File Audio Tersembunyi --> | |
| <audio id="audio-hidup" src="hidup jokowi.mp3"></audio> | |
| <audio id="audio-diam" src="diam.mp3"></audio> | |
| <audio id="audio-celeng" src="celeng.mp3"></audio> | |
| <audio id="audio-enam" src="enam.mp3"></audio> | |
| <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/pose@0.8/dist/teachablemachine-pose.min.js"></script> | |
| <script type="text/javascript"> | |
| const URL = "https://teachablemachine.withgoogle.com/models/eBJu18sKS/"; | |
| let model, webcam, ctx, labelContainer, maxPredictions; | |
| let isPlaying = false; | |
| const audioHidup = document.getElementById("audio-hidup"); | |
| const audioDiam = document.getElementById("audio-diam"); | |
| const audioCeleng = document.getElementById("audio-celeng"); | |
| const audioEnam = document.getElementById("audio-enam"); | |
| // Fungsi Jeda 2 Detik | |
| function resetAudioStatus() { | |
| setTimeout(function() { | |
| isPlaying = false; | |
| }, 2000); | |
| } | |
| audioHidup.onended = resetAudioStatus; | |
| audioDiam.onended = resetAudioStatus; | |
| audioCeleng.onended = resetAudioStatus; | |
| audioEnam.onended = resetAudioStatus; | |
| async function init() { | |
| const startBtn = document.getElementById("start-btn"); | |
| startBtn.innerText = "Mempersiapkan..."; | |
| startBtn.disabled = true; | |
| const modelURL = URL + "model.json"; | |
| const metadataURL = URL + "metadata.json"; | |
| model = await tmPose.load(modelURL, metadataURL); | |
| maxPredictions = model.getTotalClasses(); | |
| const size = 250; | |
| const flip = true; | |
| webcam = new tmPose.Webcam(size, size, flip); | |
| await webcam.setup(); | |
| await webcam.play(); | |
| window.requestAnimationFrame(loop); | |
| const canvas = document.getElementById("canvas"); | |
| canvas.width = size; canvas.height = size; | |
| ctx = canvas.getContext("2d"); | |
| labelContainer = document.getElementById("label-container"); | |
| labelContainer.innerHTML = ""; | |
| for (let i = 0; i < maxPredictions; i++) { | |
| const labelDiv = document.createElement("div"); | |
| labelDiv.className = "prediction-label"; | |
| labelContainer.appendChild(labelDiv); | |
| } | |
| startBtn.innerText = "Kamera Aktif"; | |
| startBtn.style.backgroundColor = "#10b981"; // Hijau | |
| startBtn.style.boxShadow = "0 4px 12px rgba(16, 185, 129, 0.3)"; | |
| } | |
| async function loop(timestamp) { | |
| webcam.update(); | |
| await predict(); | |
| window.requestAnimationFrame(loop); | |
| } | |
| async function predict() { | |
| const { pose, posenetOutput } = await model.estimatePose(webcam.canvas); | |
| const prediction = await model.predict(posenetOutput); | |
| for (let i = 0; i < maxPredictions; i++) { | |
| const className = prediction[i].className.toLowerCase(); | |
| const probability = prediction[i].probability; | |
| // Kapitalisasi huruf pertama untuk tampilan UI | |
| const displayClassName = prediction[i].className.charAt(0).toUpperCase() + prediction[i].className.slice(1); | |
| const classPrediction = `<span>${displayClassName}</span> <span>${(probability * 100).toFixed(0)}%</span>`; | |
| const labelElement = labelContainer.childNodes[i]; | |
| labelElement.innerHTML = classPrediction; | |
| // --- PERBAIKAN: Threshold Dinamis --- | |
| let threshold = 0.85; // Ambang batas normal 85% | |
| // Jika kelasnya adalah 'diam', turunkan ambang batasnya jadi 70% agar lebih responsif | |
| if (className.includes("diam")) { | |
| threshold = 0.70; | |
| } | |
| // Cek apakah probabilitas melebihi threshold yang sudah ditentukan | |
| if (probability > threshold) { | |
| labelElement.classList.add("active-prediction"); | |
| // Putar audio jika tidak sedang masa jeda | |
| if (!isPlaying) { | |
| if (className.includes("hidup")) { | |
| audioHidup.play(); | |
| isPlaying = true; | |
| } else if (className.includes("diam")) { | |
| audioDiam.play(); | |
| isPlaying = true; | |
| } else if (className.includes("celeng")) { | |
| audioCeleng.play(); | |
| isPlaying = true; | |
| } else if (className.includes("enam")) { | |
| audioEnam.play(); | |
| isPlaying = true; | |
| } | |
| } | |
| } else { | |
| labelElement.classList.remove("active-prediction"); | |
| } | |
| } | |
| drawPose(pose); | |
| } | |
| function drawPose(pose) { | |
| if (webcam.canvas) { | |
| ctx.drawImage(webcam.canvas, 0, 0); | |
| if (pose) { | |
| const minPartConfidence = 0.5; | |
| tmPose.drawKeypoints(pose.keypoints, minPartConfidence, ctx); | |
| tmPose.drawSkeleton(pose.keypoints, minPartConfidence, ctx); | |
| } | |
| } | |
| } | |
| </script> | |
| </body> | |
| </html> |