Spaces:
Paused
Paused
Download static/script.js from heboya8/flask-demo: direct link, hf CLI and curl.
- Browser
- Download file 1.17 kB
-
https://huggingface.co/spaces/heboya8/flask-demo/resolve/main/static/script.js
- Command line
-
hf download hf://spaces/heboya8/flask-demo/static/script.js
-
curl -L -o script.js https://huggingface.co/spaces/heboya8/flask-demo/resolve/main/static/script.js
1.17 kB
| // Access webcam | |
| navigator.mediaDevices.getUserMedia({ video: true }) | |
| .then(stream => { | |
| const video = document.getElementById('webcam'); | |
| video.srcObject = stream; | |
| }) | |
| .catch(err => { | |
| console.error("Webcam access error: ", err); | |
| alert("Could not access webcam. Please upload an image instead."); | |
| }); | |
| // Capture frame and send to server | |
| function capture() { | |
| const video = document.getElementById('webcam'); | |
| const canvas = document.getElementById('canvas'); | |
| canvas.width = video.videoWidth; | |
| canvas.height = video.videoHeight; | |
| canvas.getContext('2d').drawImage(video, 0, 0); | |
| canvas.toBlob(blob => { | |
| const formData = new FormData(); | |
| formData.append('file', blob, 'webcam.jpg'); | |
| fetch('/upload', { | |
| method: 'POST', | |
| body: formData | |
| }) | |
| .then(response => response.text()) | |
| .then(html => { | |
| document.body.innerHTML = html; // Load results page | |
| }) | |
| .catch(err => { | |
| console.error("Upload error: ", err); | |
| alert("Error uploading webcam frame."); | |
| }); | |
| }, 'image/jpeg'); | |
| } |