Spaces:
Running
Running
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Pose Detection & Exercise Guide</title> | |
<script src="https://cdn.tailwindcss.com"></script> | |
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
<style> | |
.gradient-bg { | |
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); | |
} | |
.pulse-animation { | |
animation: pulse 2s infinite; | |
} | |
@keyframes pulse { | |
0% { | |
transform: scale(1); | |
opacity: 1; | |
} | |
50% { | |
transform: scale(1.05); | |
opacity: 0.8; | |
} | |
100% { | |
transform: scale(1); | |
opacity: 1; | |
} | |
} | |
.video-container { | |
position: relative; | |
border-radius: 16px; | |
overflow: hidden; | |
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); | |
} | |
.error-shake { | |
animation: shake 0.5s; | |
} | |
@keyframes shake { | |
0%, 100% { transform: translateX(0); } | |
10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); } | |
20%, 40%, 60%, 80% { transform: translateX(5px); } | |
} | |
.skeleton-loader { | |
background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%); | |
background-size: 200% 100%; | |
animation: shimmer 1.5s infinite; | |
} | |
@keyframes shimmer { | |
0% { background-position: 200% 0; } | |
100% { background-position: -200% 0; } | |
} | |
.exercise-card { | |
transition: all 0.3s ease; | |
} | |
.exercise-card:hover { | |
transform: translateY(-5px); | |
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2); | |
} | |
.exercise-card.selected { | |
border: 3px solid #4f46e5; | |
background-color: rgba(79, 70, 229, 0.1); | |
} | |
.feedback-pulse { | |
animation: feedbackPulse 1.5s infinite; | |
} | |
@keyframes feedbackPulse { | |
0% { opacity: 0.7; } | |
50% { opacity: 1; } | |
100% { opacity: 0.7; } | |
} | |
</style> | |
</head> | |
<body class="gradient-bg min-h-screen flex flex-col items-center justify-center p-4"> | |
<div class="max-w-6xl w-full"> | |
<div class="text-center mb-8"> | |
<h1 class="text-4xl font-bold text-white mb-2">Exercise Pose Trainer</h1> | |
<p class="text-white/80 text-lg">Select an exercise and get real-time feedback on your form</p> | |
</div> | |
<div class="bg-white/10 backdrop-blur-md rounded-2xl p-6 shadow-xl mb-6"> | |
<h2 class="text-xl font-semibold text-white mb-4">Choose Your Exercise</h2> | |
<div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6"> | |
<div class="exercise-card bg-white/5 rounded-xl p-4 text-center cursor-pointer" data-exercise="squats"> | |
<div class="w-16 h-16 mx-auto mb-2 bg-blue-500/20 rounded-full flex items-center justify-center"> | |
<i class="fas fa-running text-blue-300 text-2xl"></i> | |
</div> | |
<h3 class="text-white font-medium">Squats</h3> | |
<p class="text-white/60 text-sm">Lower body strength</p> | |
</div> | |
<div class="exercise-card bg-white/5 rounded-xl p-4 text-center cursor-pointer" data-exercise="pushups"> | |
<div class="w-16 h-16 mx-auto mb-2 bg-purple-500/20 rounded-full flex items-center justify-center"> | |
<i class="fas fa-hand-paper text-purple-300 text-2xl"></i> | |
</div> | |
<h3 class="text-white font-medium">Push-ups</h3> | |
<p class="text-white/60 text-sm">Upper body strength</p> | |
</div> | |
<div class="exercise-card bg-white/5 rounded-xl p-4 text-center cursor-pointer" data-exercise="lunges"> | |
<div class="w-16 h-16 mx-auto mb-2 bg-green-500/20 rounded-full flex items-center justify-center"> | |
<i class="fas fa-arrows-alt-v text-green-300 text-2xl"></i> | |
</div> | |
<h3 class="text-white font-medium">Lunges</h3> | |
<p class="text-white/60 text-sm">Legs and balance</p> | |
</div> | |
<div class="exercise-card bg-white/5 rounded-xl p-4 text-center cursor-pointer" data-exercise="plank"> | |
<div class="w-16 h-16 mx-auto mb-2 bg-yellow-500/20 rounded-full flex items-center justify-center"> | |
<i class="fas fa-stopwatch text-yellow-300 text-2xl"></i> | |
</div> | |
<h3 class="text-white font-medium">Plank</h3> | |
<p class="text-white/60 text-sm">Core strength</p> | |
</div> | |
</div> | |
<div class="video-container mb-6"> | |
<div id="videoPlaceholder" class="w-full h-96 bg-black/20 flex items-center justify-center"> | |
<div class="text-center"> | |
<i class="fas fa-camera text-5xl text-white/50 mb-4"></i> | |
<p class="text-white/80">Select an exercise and start detection</p> | |
</div> | |
</div> | |
<video id="video" class="w-full hidden" autoplay playsinline></video> | |
<canvas id="canvas" class="absolute top-0 left-0 w-full h-full hidden"></canvas> | |
</div> | |
<div id="errorMessage" class="hidden mb-6"> | |
<div class="bg-red-500/20 border-l-4 border-red-500 text-white p-4 rounded-r-lg flex items-start"> | |
<i class="fas fa-exclamation-circle text-red-300 mt-1 mr-3"></i> | |
<div> | |
<h3 class="font-bold">Error detecting pose</h3> | |
<p class="text-sm opacity-80">Please ensure good lighting and clear visibility of your body.</p> | |
</div> | |
</div> | |
</div> | |
<div id="exerciseInstructions" class="hidden mb-6 bg-white/10 rounded-xl p-4"> | |
<h3 class="text-white font-semibold mb-3 flex items-center"> | |
<i class="fas fa-info-circle mr-2 text-blue-300"></i> | |
<span id="exerciseTitle">Exercise Instructions</span> | |
</h3> | |
<div id="exerciseDescription" class="text-white/80 text-sm"> | |
Select an exercise to see detailed instructions. | |
</div> | |
</div> | |
<div id="liveFeedback" class="hidden mb-6 bg-white/10 rounded-xl p-4"> | |
<h3 class="text-white font-semibold mb-3 flex items-center"> | |
<i class="fas fa-comment-dots mr-2 text-purple-300 feedback-pulse"></i> | |
Live Feedback | |
</h3> | |
<div id="feedbackContent" class="text-white/80 text-sm"> | |
<div class="flex items-center mb-2"> | |
<div class="w-3 h-3 rounded-full bg-green-400 mr-2"></div> | |
<span>Starting position detected</span> | |
</div> | |
<div class="flex items-center mb-2"> | |
<div class="w-3 h-3 rounded-full bg-yellow-400 mr-2"></div> | |
<span>Keep your back straight</span> | |
</div> | |
<div class="flex items-center"> | |
<div class="w-3 h-3 rounded-full bg-red-400 mr-2"></div> | |
<span>Bend your knees more</span> | |
</div> | |
</div> | |
</div> | |
<div class="flex flex-col sm:flex-row justify-center gap-4"> | |
<button id="startBtn" class="bg-blue-500 hover:bg-blue-600 text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center transition-all"> | |
<i class="fas fa-play mr-2"></i> Start Detection | |
</button> | |
<button id="retryBtn" class="bg-purple-500 hover:bg-purple-600 text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center transition-all hidden"> | |
<i class="fas fa-redo mr-2"></i> Try Again | |
</button> | |
<button id="stopBtn" class="bg-gray-500 hover:bg-gray-600 text-white font-medium py-3 px-6 rounded-lg flex items-center justify-center transition-all hidden"> | |
<i class="fas fa-stop mr-2"></i> Stop | |
</button> | |
</div> | |
</div> | |
<div class="mt-4 text-center text-white/70 text-sm"> | |
<p>Make sure your whole body is visible in the frame with good lighting conditions.</p> | |
</div> | |
</div> | |
<script> | |
// DOM Elements | |
const video = document.getElementById('video'); | |
const canvas = document.getElementById('canvas'); | |
const videoPlaceholder = document.getElementById('videoPlaceholder'); | |
const startBtn = document.getElementById('startBtn'); | |
const stopBtn = document.getElementById('stopBtn'); | |
const retryBtn = document.getElementById('retryBtn'); | |
const errorMessage = document.getElementById('errorMessage'); | |
const exerciseCards = document.querySelectorAll('.exercise-card'); | |
const exerciseInstructions = document.getElementById('exerciseInstructions'); | |
const exerciseTitle = document.getElementById('exerciseTitle'); | |
const exerciseDescription = document.getElementById('exerciseDescription'); | |
const liveFeedback = document.getElementById('liveFeedback'); | |
const feedbackContent = document.getElementById('feedbackContent'); | |
// Exercise data | |
const exercises = { | |
squats: { | |
title: "Squats", | |
description: "Stand with feet shoulder-width apart. Lower your body by bending your knees and pushing your hips back as if sitting in a chair. Keep your chest up and knees behind toes. Go as low as comfortable, then push through heels to return to start.", | |
tips: [ | |
"Keep knees aligned with toes", | |
"Maintain neutral spine", | |
"Engage core throughout", | |
"Go slow for better form" | |
] | |
}, | |
pushups: { | |
title: "Push-ups", | |
description: "Start in plank position with hands slightly wider than shoulders. Lower body until chest nearly touches floor, keeping elbows at 45-degree angle. Push back up to starting position while maintaining straight body line.", | |
tips: [ | |
"Keep body straight from head to heels", | |
"Don't let hips sag", | |
"Control the movement", | |
"Breathe out as you push up" | |
] | |
}, | |
lunges: { | |
title: "Lunges", | |
description: "Stand tall, step forward with one leg and lower hips until both knees are bent at 90 degrees. Front knee should be directly above ankle, back knee hovering just above floor. Push back up to starting position.", | |
tips: [ | |
"Keep torso upright", | |
"Don't let front knee go past toes", | |
"Engage core for balance", | |
"Control the movement down and up" | |
] | |
}, | |
plank: { | |
title: "Plank", | |
description: "Begin in push-up position but rest on forearms instead of hands. Body should form straight line from shoulders to ankles. Engage core and hold position without letting hips sag or rise.", | |
tips: [ | |
"Keep neck neutral", | |
"Engage glutes and core", | |
"Don't hold your breath", | |
"Start with short holds and increase time" | |
] | |
} | |
}; | |
// State variables | |
let selectedExercise = null; | |
let isDetecting = false; | |
let feedbackInterval = null; | |
// Event Listeners | |
startBtn.addEventListener('click', startDetection); | |
stopBtn.addEventListener('click', stopDetection); | |
retryBtn.addEventListener('click', retryDetection); | |
// Add click event to exercise cards | |
exerciseCards.forEach(card => { | |
card.addEventListener('click', () => { | |
// Remove selected class from all cards | |
exerciseCards.forEach(c => c.classList.remove('selected')); | |
// Add selected class to clicked card | |
card.classList.add('selected'); | |
// Set selected exercise | |
selectedExercise = card.dataset.exercise; | |
// Update instructions | |
updateExerciseInstructions(); | |
// Enable start button | |
startBtn.disabled = false; | |
startBtn.classList.remove('opacity-50', 'cursor-not-allowed'); | |
}); | |
}); | |
// Initially disable start button | |
startBtn.disabled = true; | |
startBtn.classList.add('opacity-50', 'cursor-not-allowed'); | |
// Functions | |
function updateExerciseInstructions() { | |
if (!selectedExercise) return; | |
const exercise = exercises[selectedExercise]; | |
exerciseTitle.textContent = exercise.title; | |
let descriptionHTML = `<p class="mb-3">${exercise.description}</p>`; | |
descriptionHTML += `<h4 class="font-medium text-white mb-2">Key Tips:</h4><ul class="list-disc pl-5 space-y-1">`; | |
exercise.tips.forEach(tip => { | |
descriptionHTML += `<li>${tip}</li>`; | |
}); | |
descriptionHTML += `</ul>`; | |
exerciseDescription.innerHTML = descriptionHTML; | |
exerciseInstructions.classList.remove('hidden'); | |
} | |
function generateRandomFeedback() { | |
if (!selectedExercise) return; | |
const exercise = exercises[selectedExercise]; | |
const allTips = exercise.tips; | |
const randomTips = [...allTips].sort(() => 0.5 - Math.random()).slice(0, 3); | |
let feedbackHTML = ''; | |
// Good feedback (green) | |
const goodTip = randomTips[0]; | |
feedbackHTML += `<div class="flex items-center mb-2"> | |
<div class="w-3 h-3 rounded-full bg-green-400 mr-2"></div> | |
<span>Good: ${goodTip}</span> | |
</div>`; | |
// Warning feedback (yellow) | |
const warningTip = randomTips[1]; | |
feedbackHTML += `<div class="flex items-center mb-2"> | |
<div class="w-3 h-3 rounded-full bg-yellow-400 mr-2"></div> | |
<span>Improve: ${warningTip}</span> | |
</div>`; | |
// Bad feedback (red) | |
const badTip = randomTips[2]; | |
feedbackHTML += `<div class="flex items-center"> | |
<div class="w-3 h-3 rounded-full bg-red-400 mr-2"></div> | |
<span>Correct: ${badTip}</span> | |
</div>`; | |
feedbackContent.innerHTML = feedbackHTML; | |
} | |
async function startDetection() { | |
if (!selectedExercise) return; | |
try { | |
// Show loading state | |
startBtn.classList.add('hidden'); | |
stopBtn.classList.remove('hidden'); | |
videoPlaceholder.classList.add('hidden'); | |
video.classList.remove('hidden'); | |
canvas.classList.remove('hidden'); | |
errorMessage.classList.add('hidden'); | |
liveFeedback.classList.remove('hidden'); | |
// Show exercise instructions | |
exerciseInstructions.classList.remove('hidden'); | |
// Start generating random feedback (simulated) | |
generateRandomFeedback(); | |
feedbackInterval = setInterval(generateRandomFeedback, 3000); | |
// Access camera | |
const stream = await navigator.mediaDevices.getUserMedia({ | |
video: { width: 640, height: 480, facingMode: 'user' }, | |
audio: false | |
}); | |
video.srcObject = stream; | |
// Start pose detection simulation | |
isDetecting = true; | |
simulatePoseDetection(); | |
} catch (err) { | |
console.error('Error accessing camera:', err); | |
showError(); | |
} | |
} | |
function stopDetection() { | |
// Stop video stream | |
if (video.srcObject) { | |
video.srcObject.getTracks().forEach(track => track.stop()); | |
} | |
// Clear feedback interval | |
if (feedbackInterval) { | |
clearInterval(feedbackInterval); | |
feedbackInterval = null; | |
} | |
// Reset UI | |
video.classList.add('hidden'); | |
canvas.classList.add('hidden'); | |
videoPlaceholder.classList.remove('hidden'); | |
stopBtn.classList.add('hidden'); | |
startBtn.classList.remove('hidden'); | |
liveFeedback.classList.add('hidden'); | |
isDetecting = false; | |
} | |
function retryDetection() { | |
errorMessage.classList.add('hidden'); | |
retryBtn.classList.add('hidden'); | |
startBtn.classList.remove('hidden'); | |
// Add shake animation to video placeholder to draw attention | |
videoPlaceholder.classList.remove('hidden'); | |
videoPlaceholder.classList.add('error-shake'); | |
setTimeout(() => { | |
videoPlaceholder.classList.remove('error-shake'); | |
}, 500); | |
} | |
function showError() { | |
errorMessage.classList.remove('hidden'); | |
retryBtn.classList.remove('hidden'); | |
stopBtn.classList.add('hidden'); | |
liveFeedback.classList.add('hidden'); | |
// Clear feedback interval | |
if (feedbackInterval) { | |
clearInterval(feedbackInterval); | |
feedbackInterval = null; | |
} | |
// Add shake animation to error message | |
errorMessage.classList.add('error-shake'); | |
setTimeout(() => { | |
errorMessage.classList.remove('error-shake'); | |
}, 500); | |
} | |
function simulatePoseDetection() { | |
if (!isDetecting) return; | |
// This would be replaced with actual pose detection logic | |
// For now we just simulate it with random feedback | |
// Continue the loop while detection is active | |
setTimeout(simulatePoseDetection, 100); | |
} | |
</script> | |
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=S6six/pose-tracker-base" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
</html> |