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