Spaces:
Sleeping
Sleeping
Update templates/index.html
Browse files123456789101112131415161718192021123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960<html>
<head>
<title>ASL Hand Gesture Recognition</title>
</head>
<body>
<h1>ASL Hand Gesture Recognition</h1>
<img src="{{ url_for('video') }}" width="640" height="480">
<h2>Detected Gesture: <span id="gesture">None</span></h2>
<script>
setInterval(async () => {
let response = await fetch('/video');
let text = await response.text();
let match = text.match(/Gesture: (\w+)/);
if (match) {
document.getElementById('gesture').innerText = match[1];
}
}, 1000);
</script>
</body>
</html><head> <script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands"></script> <script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils"></script> <script> let videoStream; let isTraining = false;
async function startCamera() { videoStream = await navigator.mediaDevices.getUserMedia({ video: true }); document.getElementById('video').srcObject = videoStream;
const video = document.getElementById("video"); const canvas = document.getElementById("outputCanvas"); const ctx = canvas.getContext("2d");
const hands = new Hands({ locateFile: (file) => `https://cdn.jsdelivr.net/npm/@mediapipe/hands/${file}` });
hands.setOptions({ maxNumHands: 2, modelComplexity: 1, minDetectionConfidence: 0.5, minTrackingConfidence: 0.5 });
hands.onResults((results) => { ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.drawImage(video, 0, 0, canvas.width, canvas.height); if (results.multiHandLandmarks) { for (const landmarks of results.multiHandLandmarks) { drawConnectors(ctx, landmarks, HAND_CONNECTIONS, { color: "#00FF00", lineWidth: 2 }); drawLandmarks(ctx, landmarks, { color: "#FF0000", radius: 4 }); } } });
const camera = new Camera(video, { onFrame: async () => { await hands.send({ image: video }); }, width: 640, height: 480 });
camera.start(); } </script></head><body> <div class="container"> <h2>Live Gesture Recognition</h2> <button onclick="startCamera()">Start Camera</button> <button id="modeButton" onclick="toggleMode()">Switch to Train Mode</button> <br> <video id="video" autoplay></video> <canvas id="outputCanvas" width="640" height="480"></canvas> <br> <button onclick="captureImage()">Capture Image</button> <h3 id="prediction-box">Prediction: </h3> </div></body>templates/index.html+60-21