Spaces:
Sleeping
Sleeping
Update app.py
Browse files29 unmodified lines303132333435363738391 unmodified line41424344454647484930 unmodified lines8081828384858687884 unmodified lines939495969798991001011021 unmodified line10410510610710810929 unmodified linesbody { font-family: Arial, sans-serif; text-align: center; background: #f4f4f4; }h2 { color: #333; }.container { max-width: 600px; margin: auto; background: white; padding: 20px; border-radius: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2); }.video-container { position: relative; display: flex; justify-content: center; align-items: center; width: 400px; height: 400px; margin: auto; overflow: hidden; }video { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }#prediction-box { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, 0.7); color: white; padding: 5px 10px; border-radius: 5px; font-weight: bold; }</style><script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js"></script><script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js"></script>1 unmodified line<script>let videoStream;let hands;async function startCamera() {videoStream = await navigator.mediaDevices.getUserMedia({ video: { width: 400, height: 400 } });document.getElementById('video').srcObject = videoStream;setupHandTracking();}30 unmodified linesctx.drawImage(video, 0, 0, canvas.width, canvas.height);if (results.multiHandLandmarks) {results.multiHandLandmarks.forEach((landmarks) => {drawConnectors(ctx, landmarks, HAND_CONNECTIONS, {color: 'blue', lineWidth: 3});drawLandmarks(ctx, landmarks, {color: 'red', radius: 5});drawBoundingBox(ctx, landmarks);});}}4 unmodified lineslet xMax = Math.max(...landmarks.map(p => p.x)) * ctx.canvas.width;let yMax = Math.max(...landmarks.map(p => p.y)) * ctx.canvas.height;ctx.strokeStyle = "yellow";ctx.lineWidth = 3;ctx.strokeRect(xMin, yMin, xMax - xMin, yMax - yMin);document.getElementById('prediction-box').innerText = "Gesture: Recognizing...";}</script></head><body>1 unmodified line<h2>Live Gesture Recognition</h2><button onclick="startCamera()">Start Camera</button><br><div class="video-container"><video id="video" autoplay></video><canvas id="canvas"></canvas>29 unmodified lines30313233343536373839401 unmodified line42434445464748495051525330 unmodified lines848586878889909192934 unmodified lines98991001011021031041051061071081091101111121131141151161171181191201211221231 unmodified line12512612712812913013113229 unmodified linesbody { font-family: Arial, sans-serif; text-align: center; background: #f4f4f4; }h2 { color: #333; }.container { max-width: 600px; margin: auto; background: white; padding: 20px; border-radius: 10px; box-shadow: 0px 4px 8px rgba(0, 0, 0, 0.2); }.video-container { position: relative; display: flex; justify-content: center; align-items: center; width: 400px; height: 400px; margin: auto; }video { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; }canvas { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }#prediction-box { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: rgba(0, 0, 0, 0.7); color: white; padding: 5px 10px; border-radius: 5px; }input, button { margin: 5px; padding: 8px; }</style><script src="https://cdn.jsdelivr.net/npm/@mediapipe/hands/hands.js"></script><script src="https://cdn.jsdelivr.net/npm/@mediapipe/drawing_utils/drawing_utils.js"></script>1 unmodified line<script>let videoStream;let hands;let trainingMode = false;let collectedGestures = [];let gestureName = "";async function startCamera() {videoStream = await navigator.mediaDevices.getUserMedia({ video: true });document.getElementById('video').srcObject = videoStream;setupHandTracking();}30 unmodified linesctx.drawImage(video, 0, 0, canvas.width, canvas.height);if (results.multiHandLandmarks) {results.multiHandLandmarks.forEach((landmarks) => {drawConnectors(ctx, landmarks, HAND_CONNECTIONS, {color: 'blue', lineWidth: 1});drawLandmarks(ctx, landmarks, {color: 'red', radius: 2});drawBoundingBox(ctx, landmarks);if (trainingMode) saveGesture(landmarks);});}}4 unmodified lineslet xMax = Math.max(...landmarks.map(p => p.x)) * ctx.canvas.width;let yMax = Math.max(...landmarks.map(p => p.y)) * ctx.canvas.height;ctx.strokeStyle = "yellow";ctx.lineWidth = 2;ctx.strokeRect(xMin, yMin, xMax - xMin, yMax - yMin);document.getElementById('prediction-box').innerText = "Gesture: Recognizing...";}function toggleTraining() {trainingMode = !trainingMode;document.getElementById('train-btn').innerText = trainingMode ? "Stop Training" : "Start Training";}function saveGesture(landmarks) {if (gestureName) {collectedGestures.push({name: gestureName, landmarks});console.log(`Saved gesture: ${gestureName}`);}}function setGestureName() {gestureName = document.getElementById('gesture-name').value;}</script></head><body>1 unmodified line<h2>Live Gesture Recognition</h2><button onclick="startCamera()">Start Camera</button><br><input type="text" id="gesture-name" placeholder="Enter Gesture Name" oninput="setGestureName()"><button id="train-btn" onclick="toggleTraining()">Start Training</button><div class="video-container"><video id="video" autoplay></video><canvas id="canvas"></canvas>
app.py+29-6