Create script.js
Browse files
script.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Capture image from webcam and send to backend
|
| 2 |
+
async function recognizePose() {
|
| 3 |
+
const video = document.querySelector('video');
|
| 4 |
+
const canvas = document.createElement('canvas');
|
| 5 |
+
canvas.width = video.videoWidth;
|
| 6 |
+
canvas.height = video.videoHeight;
|
| 7 |
+
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 8 |
+
const image = canvas.toDataURL('image/jpeg');
|
| 9 |
+
|
| 10 |
+
const response = await fetch('https://your-space-name.hf.space/api/recognize_pose', {
|
| 11 |
+
method: 'POST',
|
| 12 |
+
headers: {
|
| 13 |
+
'Content-Type': 'application/json',
|
| 14 |
+
},
|
| 15 |
+
body: JSON.stringify({ image: image })
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
const result = await response.json();
|
| 19 |
+
document.getElementById('output').innerText = result.pose || 'Pose not recognized';
|
| 20 |
+
}
|