Upload 3 files
Browse files- Frontend/index.html +21 -0
- Frontend/scripts.js +40 -0
- Frontend/style.css +49 -0
Frontend/index.html
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8" />
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
6 |
+
<title>Photo to Emoji</title>
|
7 |
+
<link rel="stylesheet" href="style.css" />
|
8 |
+
</head>
|
9 |
+
<body>
|
10 |
+
<h1>Photo to Emoji Converter</h1>
|
11 |
+
<video autoplay="true" id="videoElement"></video>
|
12 |
+
<br />
|
13 |
+
<button onclick="captureAndSend()">Capture & Predict</button>
|
14 |
+
<div id="emojiDisplay"></div>
|
15 |
+
<div id="emotionText"></div>
|
16 |
+
<!-- Download link -->
|
17 |
+
<a id="downloadEmoji" download="emoji.png" style="display: none;">⬇️ Download Emoji</a>
|
18 |
+
|
19 |
+
<script src="scripts.js"></script>
|
20 |
+
</body>
|
21 |
+
</html>
|
Frontend/scripts.js
ADDED
@@ -0,0 +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("http://127.0.0.1:8000/process-image", {
|
20 |
+
method: "POST",
|
21 |
+
headers: { "Content-Type": "application/json" },
|
22 |
+
body: JSON.stringify({ image: dataUrl })
|
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 |
+
}
|
Frontend/style.css
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
body {
|
2 |
+
text-align: center;
|
3 |
+
font-family: Arial, sans-serif;
|
4 |
+
background-color: #222;
|
5 |
+
color: #fff;
|
6 |
+
}
|
7 |
+
|
8 |
+
h1 {
|
9 |
+
margin-top: 30px;
|
10 |
+
font-size: 2em;
|
11 |
+
}
|
12 |
+
|
13 |
+
#videoElement {
|
14 |
+
width: 400px;
|
15 |
+
border-radius: 10px;
|
16 |
+
margin-top: 20px;
|
17 |
+
}
|
18 |
+
|
19 |
+
button {
|
20 |
+
margin-top: 20px;
|
21 |
+
padding: 10px 20px;
|
22 |
+
font-size: 18px;
|
23 |
+
border: none;
|
24 |
+
background-color: #f39c12;
|
25 |
+
color: #fff;
|
26 |
+
cursor: pointer;
|
27 |
+
border-radius: 5px;
|
28 |
+
}
|
29 |
+
|
30 |
+
#emojiDisplay {
|
31 |
+
margin-top: 20px;
|
32 |
+
}
|
33 |
+
|
34 |
+
#emotionText {
|
35 |
+
font-size: 24px;
|
36 |
+
margin-top: 10px;
|
37 |
+
}
|
38 |
+
|
39 |
+
#downloadEmoji {
|
40 |
+
display: inline-block;
|
41 |
+
margin-top: 15px;
|
42 |
+
padding: 10px 20px;
|
43 |
+
font-size: 16px;
|
44 |
+
background-color: #3498db;
|
45 |
+
color: white;
|
46 |
+
border-radius: 5px;
|
47 |
+
text-decoration: none;
|
48 |
+
}
|
49 |
+
|