Spaces:
Running
Running
Download index.html from codrizsain/zero-team: direct link, hf CLI and curl.
- Browser
- Download file 5.67 kB
-
https://huggingface.co/spaces/codrizsain/zero-team/resolve/main/index.html
- Command line
-
hf download hf://spaces/codrizsain/zero-team/index.html
-
curl -L -o index.html https://huggingface.co/spaces/codrizsain/zero-team/resolve/main/index.html
5.67 kB
| <html lang="id"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Hand Detector - By Rizki Ardianasyah</title> | |
| <script src="https://cdn.jsdelivr.net/npm/@mediapipe/camera_utils/camera_utils.js" crossorigin="anonymous"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js" crossorigin="anonymous"></script> | |
| <script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js" crossorigin="anonymous"></script> | |
| <style> | |
| /* Desain simpel dark mode ala progamer */ | |
| body { | |
| background-color: #0f172a; | |
| color: white; | |
| font-family: sans-serif; | |
| display: flex; | |
| flex-direction: column; | |
| align-items: center; | |
| margin-top: 20px; | |
| } | |
| .monitor-container { | |
| position: relative; | |
| margin-top: 20px; | |
| } | |
| /* Efek neon biru dan pink pada kanvas */ | |
| canvas { | |
| border: 2px solid #3b82f6; | |
| box-shadow: 0 0 15px #ec4899; | |
| border-radius: 8px; | |
| background-color: #000; | |
| max-width: 100%; | |
| } | |
| /* GIF diletakkan mengambang di tengah kanvas */ | |
| #responGif { | |
| position: absolute; | |
| top: 50%; | |
| left: 50%; | |
| transform: translate(-50%, -50%); | |
| display: none; | |
| border-radius: 10px; | |
| z-index: 10; | |
| width: 250px; | |
| } | |
| button { | |
| background-color: #ec4899; | |
| color: white; | |
| border: none; | |
| padding: 12px 24px; | |
| font-size: 16px; | |
| border-radius: 5px; | |
| cursor: pointer; | |
| margin-bottom: 10px; | |
| font-weight: bold; | |
| } | |
| button:hover { background-color: #db2777; } | |
| </style> | |
| </head> | |
| <body> | |
| <h2>✋ Real-Time Hand Detector</h2> | |
| <p>Data Pengguna Diproses Langsung di Browser Anda.</p> | |
| <button id="startBtn">Mulai Kamera & Izinkan Suara</button> | |
| <div class="monitor-container"> | |
| <video id="videoElement" style="display: none;" autoplay playsinline></video> | |
| <canvas id="outputCanvas" width="640" height="480"></canvas> | |
| <img id="responGif" src="animasi.gif" alt="Animasi AI"> | |
| </div> | |
| <audio id="responAudio" src="suara.mp3"></audio> | |
| <script> | |
| const videoElement = document.getElementById('videoElement'); | |
| const canvasElement = document.getElementById('outputCanvas'); | |
| const canvasCtx = canvasElement.getContext('2d'); | |
| const responGif = document.getElementById('responGif'); | |
| const responAudio = document.getElementById('responAudio'); | |
| const startBtn = document.getElementById('startBtn'); | |
| let lastTriggerTime = 0; | |
| // Inisialisasi MediaPipe Hands | |
| const hands = new Hands({locateFile: (file) => { | |
| return `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}`; | |
| }}); | |
| hands.setOptions({ | |
| maxNumHands: 1, | |
| modelComplexity: 0, | |
| minDetectionConfidence: 0.5, | |
| minTrackingConfidence: 0.5 | |
| }); | |
| // Logika saat AI mendapatkan frame video | |
| hands.onResults((results) => { | |
| canvasCtx.save(); | |
| canvasCtx.clearRect(0, 0, canvasElement.width, canvasElement.height); | |
| canvasCtx.drawImage(results.image, 0, 0, canvasElement.width, canvasElement.height); | |
| let handDetected = false; | |
| if (results.multiHandLandmarks && results.multiHandLandmarks.length > 0) { | |
| handDetected = true; | |
| for (const landmarks of results.multiHandLandmarks) { | |
| drawConnectors(canvasCtx, landmarks, HAND_CONNECTIONS, {color: '#ec4899', lineWidth: 4}); | |
| drawLandmarks(canvasCtx, landmarks, {color: '#3b82f6', lineWidth: 2}); | |
| } | |
| } | |
| canvasCtx.restore(); | |
| // Logika Trigger Baru | |
| const currentTime = Date.now() / 1000; | |
| // Jeda diubah menjadi 14 detik agar tidak bentrok | |
| if (handDetected && (currentTime - lastTriggerTime > 14)) { | |
| // Tampilkan GIF dan putar suara | |
| responGif.style.display = 'block'; | |
| responAudio.currentTime = 0; | |
| responAudio.play(); | |
| lastTriggerTime = currentTime; | |
| // Set timer persis 14 detik (14000 ms) | |
| setTimeout(() => { | |
| responGif.style.display = 'none'; // Sembunyikan GIF | |
| responAudio.pause(); // Matikan paksa suara (jaga-jaga jika file asli > 14 detik) | |
| responAudio.currentTime = 0; // Kembalikan suara ke detik 0 | |
| }, 14000); | |
| } | |
| }); | |
| // Event saat tombol ditekan | |
| startBtn.addEventListener('click', () => { | |
| startBtn.style.display = 'none'; | |
| responAudio.play().then(() => { | |
| responAudio.pause(); | |
| responAudio.currentTime = 0; | |
| }).catch(()=>console.log("Audio siap")); | |
| // Nyalakan Kamera (Versi Ringan) | |
| const camera = new Camera(videoElement, { | |
| onFrame: async () => { | |
| await hands.send({image: videoElement}); | |
| }, | |
| width: 320, // Ubah dari 640 menjadi 320 | |
| height: 240 // Ubah dari 480 menjadi 240 | |
| }); | |
| camera.start(); | |
| }); | |
| </script> | |
| </body> | |
| </html> |