Spaces:
Running
Running
Create static/index.html
Browse files- static/index.html +55 -0
static/index.html
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html>
|
| 3 |
+
<head>
|
| 4 |
+
<title>Posture Detector</title>
|
| 5 |
+
</head>
|
| 6 |
+
<body>
|
| 7 |
+
<h1>Live Posture Detector</h1>
|
| 8 |
+
<video id="video" width="224" height="224" autoplay></video>
|
| 9 |
+
<p id="result">Loading...</p>
|
| 10 |
+
|
| 11 |
+
<script>
|
| 12 |
+
const video = document.getElementById('video');
|
| 13 |
+
const resultP = document.getElementById('result');
|
| 14 |
+
|
| 15 |
+
// Get webcam stream
|
| 16 |
+
navigator.mediaDevices.getUserMedia({ video: { width: 224, height: 224 } })
|
| 17 |
+
.then(stream => {
|
| 18 |
+
video.srcObject = stream;
|
| 19 |
+
})
|
| 20 |
+
.catch(err => {
|
| 21 |
+
alert('Error accessing webcam: ' + err);
|
| 22 |
+
});
|
| 23 |
+
|
| 24 |
+
// Create canvas to capture video frame
|
| 25 |
+
const canvas = document.createElement('canvas');
|
| 26 |
+
canvas.width = 224;
|
| 27 |
+
canvas.height = 224;
|
| 28 |
+
const ctx = canvas.getContext('2d');
|
| 29 |
+
|
| 30 |
+
async function sendFrame() {
|
| 31 |
+
// Draw current frame to canvas
|
| 32 |
+
ctx.drawImage(video, 0, 0, 224, 224);
|
| 33 |
+
// Convert to blob
|
| 34 |
+
const blob = await new Promise(resolve => canvas.toBlob(resolve, 'image/jpeg'));
|
| 35 |
+
// Prepare form data
|
| 36 |
+
const formData = new FormData();
|
| 37 |
+
formData.append('file', blob, 'frame.jpg');
|
| 38 |
+
|
| 39 |
+
try {
|
| 40 |
+
const response = await fetch('/predict', {
|
| 41 |
+
method: 'POST',
|
| 42 |
+
body: formData
|
| 43 |
+
});
|
| 44 |
+
const data = await response.json();
|
| 45 |
+
resultP.textContent = `${data.label} (${(data.confidence * 100).toFixed(2)}%)`;
|
| 46 |
+
} catch (error) {
|
| 47 |
+
resultP.textContent = 'Error: ' + error;
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
// Send frame every 1.5 seconds (adjust as needed)
|
| 52 |
+
setInterval(sendFrame, 1500);
|
| 53 |
+
</script>
|
| 54 |
+
</body>
|
| 55 |
+
</html>
|