File size: 1,326 Bytes
8a35d1e 5c16164 8a35d1e 2bc715c 8a35d1e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
const video = document.querySelector("#videoElement");
navigator.mediaDevices.getUserMedia({ video: true })
.then((stream) => {
video.srcObject = stream;
})
.catch((err) => {
console.error("Error accessing camera: ", err);
});
function captureAndSend() {
const canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
const context = canvas.getContext('2d');
context.drawImage(video, 0, 0, canvas.width, canvas.height);
const dataUrl = canvas.toDataURL("image/jpeg");
fetch("https://prime810-facefeel.hf.space/process-image", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ image: dataUrl })
})
.then(response => response.json())
.then(data => {
document.getElementById("emojiDisplay").innerHTML =
`<img src="${data.emoji}" style="width:200px; border-radius:10px;">`;
document.getElementById("emotionText").textContent =
`Emotion: ${data.emotion}`;
// Show download button
const link = document.getElementById("downloadEmoji");
link.href = data.emoji;
link.style.display = "inline-block";
})
.catch(error => {
console.error("Error:", error);
alert("Failed to get emoji. Is your backend running?");
});
}
|