Update app.py
Browse files
app.py
CHANGED
|
@@ -32,10 +32,10 @@ def index():
|
|
| 32 |
<title>Gesture Detection</title>
|
| 33 |
<style>
|
| 34 |
body {
|
| 35 |
-
font-family:
|
| 36 |
-
background
|
| 37 |
padding: 40px;
|
| 38 |
-
max-width:
|
| 39 |
margin: auto;
|
| 40 |
}
|
| 41 |
h1 {
|
|
@@ -43,57 +43,59 @@ def index():
|
|
| 43 |
color: #333;
|
| 44 |
}
|
| 45 |
form, .nav-buttons {
|
| 46 |
-
background-color:
|
| 47 |
-
padding:
|
| 48 |
-
border-radius:
|
| 49 |
-
box-shadow: 0
|
| 50 |
-
margin-bottom:
|
| 51 |
}
|
| 52 |
input[type="file"] {
|
| 53 |
display: block;
|
| 54 |
-
margin-bottom:
|
| 55 |
}
|
| 56 |
button {
|
| 57 |
-
padding: 10px
|
| 58 |
font-size: 16px;
|
| 59 |
-
background-color: #
|
| 60 |
color: white;
|
| 61 |
border: none;
|
| 62 |
-
border-radius:
|
| 63 |
cursor: pointer;
|
|
|
|
| 64 |
}
|
| 65 |
button:hover {
|
| 66 |
-
background-color: #
|
| 67 |
}
|
| 68 |
.result img {
|
| 69 |
max-width: 100%;
|
| 70 |
-
|
|
|
|
|
|
|
| 71 |
}
|
| 72 |
.nav-buttons {
|
| 73 |
text-align: center;
|
| 74 |
}
|
| 75 |
-
.nav-buttons a {
|
| 76 |
-
|
| 77 |
margin: 0 10px;
|
| 78 |
}
|
|
|
|
|
|
|
|
|
|
| 79 |
</style>
|
| 80 |
</head>
|
| 81 |
<body>
|
| 82 |
-
<h1>Gesture Detection</h1>
|
| 83 |
-
|
| 84 |
<form id="upload-form">
|
| 85 |
-
<label for="image">Upload image
|
| 86 |
<input type="file" id="image" name="image" accept="image/*" required />
|
| 87 |
<button type="submit">Detect Gesture</button>
|
| 88 |
</form>
|
| 89 |
-
|
| 90 |
<div class="result" id="result"></div>
|
| 91 |
-
|
| 92 |
<div class="nav-buttons">
|
| 93 |
-
<p>
|
| 94 |
-
<a href="/webcam"><button>Open Webcam
|
| 95 |
</div>
|
| 96 |
-
|
| 97 |
<script>
|
| 98 |
const form = document.getElementById("upload-form");
|
| 99 |
const resultDiv = document.getElementById("result");
|
|
@@ -103,13 +105,13 @@ def index():
|
|
| 103 |
const file = imageInput.files[0];
|
| 104 |
const formData = new FormData();
|
| 105 |
formData.append("image", file);
|
| 106 |
-
resultDiv.innerHTML = "Processing
|
| 107 |
const response = await fetch("/detect", {
|
| 108 |
method: "POST",
|
| 109 |
body: formData
|
| 110 |
});
|
| 111 |
if (!response.ok) {
|
| 112 |
-
resultDiv.innerHTML = "Error detecting gesture
|
| 113 |
return;
|
| 114 |
}
|
| 115 |
const data = await response.json();
|
|
@@ -134,20 +136,55 @@ def webcam_ui():
|
|
| 134 |
<head>
|
| 135 |
<title>Live Gesture Detection</title>
|
| 136 |
<style>
|
| 137 |
-
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
</style>
|
| 140 |
</head>
|
| 141 |
<body>
|
| 142 |
-
<h2>Live Gesture Detection
|
| 143 |
<video id="video" autoplay muted playsinline></video>
|
| 144 |
<canvas id="canvas" style="display:none;"></canvas>
|
| 145 |
<br>
|
| 146 |
<button id="start">Start Detection</button>
|
| 147 |
<button id="stop">Stop</button>
|
| 148 |
-
|
| 149 |
<div id="result"></div>
|
| 150 |
-
|
| 151 |
<script>
|
| 152 |
const video = document.getElementById('video');
|
| 153 |
const canvas = document.getElementById('canvas');
|
|
@@ -167,16 +204,13 @@ def webcam_ui():
|
|
| 167 |
canvas.width = video.videoWidth;
|
| 168 |
canvas.height = video.videoHeight;
|
| 169 |
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
|
| 170 |
-
|
| 171 |
canvas.toBlob(async (blob) => {
|
| 172 |
const formData = new FormData();
|
| 173 |
formData.append("image", blob, "frame.jpg");
|
| 174 |
-
|
| 175 |
const res = await fetch("/detect", {
|
| 176 |
method: "POST",
|
| 177 |
body: formData
|
| 178 |
});
|
| 179 |
-
|
| 180 |
if (res.ok) {
|
| 181 |
const data = await res.json();
|
| 182 |
resultDiv.innerHTML = `
|
|
@@ -187,7 +221,7 @@ def webcam_ui():
|
|
| 187 |
<img src="${data.saved_to}" />
|
| 188 |
`;
|
| 189 |
} else {
|
| 190 |
-
resultDiv.innerHTML = "Detection failed
|
| 191 |
}
|
| 192 |
}, "image/jpeg");
|
| 193 |
}, 1500);
|
|
@@ -195,13 +229,12 @@ def webcam_ui():
|
|
| 195 |
|
| 196 |
document.getElementById("stop").onclick = () => {
|
| 197 |
clearInterval(intervalId);
|
| 198 |
-
resultDiv.innerHTML = "Stopped
|
| 199 |
};
|
| 200 |
</script>
|
| 201 |
</body>
|
| 202 |
</html>
|
| 203 |
"""
|
| 204 |
|
| 205 |
-
|
| 206 |
if __name__ == "__main__":
|
| 207 |
app.run(host="0.0.0.0", port=5000)
|
|
|
|
| 32 |
<title>Gesture Detection</title>
|
| 33 |
<style>
|
| 34 |
body {
|
| 35 |
+
font-family: 'Segoe UI', sans-serif;
|
| 36 |
+
background: linear-gradient(to right, #eef2f3, #8e9eab);
|
| 37 |
padding: 40px;
|
| 38 |
+
max-width: 800px;
|
| 39 |
margin: auto;
|
| 40 |
}
|
| 41 |
h1 {
|
|
|
|
| 43 |
color: #333;
|
| 44 |
}
|
| 45 |
form, .nav-buttons {
|
| 46 |
+
background-color: #fff;
|
| 47 |
+
padding: 25px;
|
| 48 |
+
border-radius: 15px;
|
| 49 |
+
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
| 50 |
+
margin-bottom: 25px;
|
| 51 |
}
|
| 52 |
input[type="file"] {
|
| 53 |
display: block;
|
| 54 |
+
margin-bottom: 15px;
|
| 55 |
}
|
| 56 |
button {
|
| 57 |
+
padding: 10px 25px;
|
| 58 |
font-size: 16px;
|
| 59 |
+
background-color: #28a745;
|
| 60 |
color: white;
|
| 61 |
border: none;
|
| 62 |
+
border-radius: 6px;
|
| 63 |
cursor: pointer;
|
| 64 |
+
transition: background-color 0.3s;
|
| 65 |
}
|
| 66 |
button:hover {
|
| 67 |
+
background-color: #218838;
|
| 68 |
}
|
| 69 |
.result img {
|
| 70 |
max-width: 100%;
|
| 71 |
+
border-radius: 10px;
|
| 72 |
+
margin-top: 15px;
|
| 73 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
|
| 74 |
}
|
| 75 |
.nav-buttons {
|
| 76 |
text-align: center;
|
| 77 |
}
|
| 78 |
+
.nav-buttons a button {
|
| 79 |
+
background-color: #007BFF;
|
| 80 |
margin: 0 10px;
|
| 81 |
}
|
| 82 |
+
.nav-buttons a button:hover {
|
| 83 |
+
background-color: #0056b3;
|
| 84 |
+
}
|
| 85 |
</style>
|
| 86 |
</head>
|
| 87 |
<body>
|
| 88 |
+
<h1>Image-Based Gesture Detection</h1>
|
|
|
|
| 89 |
<form id="upload-form">
|
| 90 |
+
<label for="image"><strong>Upload an image:</strong></label>
|
| 91 |
<input type="file" id="image" name="image" accept="image/*" required />
|
| 92 |
<button type="submit">Detect Gesture</button>
|
| 93 |
</form>
|
|
|
|
| 94 |
<div class="result" id="result"></div>
|
|
|
|
| 95 |
<div class="nav-buttons">
|
| 96 |
+
<p><strong>Want real-time detection?</strong></p>
|
| 97 |
+
<a href="/webcam"><button>Open Webcam</button></a>
|
| 98 |
</div>
|
|
|
|
| 99 |
<script>
|
| 100 |
const form = document.getElementById("upload-form");
|
| 101 |
const resultDiv = document.getElementById("result");
|
|
|
|
| 105 |
const file = imageInput.files[0];
|
| 106 |
const formData = new FormData();
|
| 107 |
formData.append("image", file);
|
| 108 |
+
resultDiv.innerHTML = "<p>Processing...</p>";
|
| 109 |
const response = await fetch("/detect", {
|
| 110 |
method: "POST",
|
| 111 |
body: formData
|
| 112 |
});
|
| 113 |
if (!response.ok) {
|
| 114 |
+
resultDiv.innerHTML = "<p style='color:red;'>Error detecting gesture.</p>";
|
| 115 |
return;
|
| 116 |
}
|
| 117 |
const data = await response.json();
|
|
|
|
| 136 |
<head>
|
| 137 |
<title>Live Gesture Detection</title>
|
| 138 |
<style>
|
| 139 |
+
body {
|
| 140 |
+
font-family: 'Segoe UI', sans-serif;
|
| 141 |
+
background: linear-gradient(to right, #e0eafc, #cfdef3);
|
| 142 |
+
padding: 40px;
|
| 143 |
+
max-width: 800px;
|
| 144 |
+
margin: auto;
|
| 145 |
+
text-align: center;
|
| 146 |
+
}
|
| 147 |
+
h2 {
|
| 148 |
+
color: #333;
|
| 149 |
+
margin-bottom: 20px;
|
| 150 |
+
}
|
| 151 |
+
video, canvas {
|
| 152 |
+
width: 100%;
|
| 153 |
+
max-width: 500px;
|
| 154 |
+
border-radius: 10px;
|
| 155 |
+
border: 2px solid #ccc;
|
| 156 |
+
margin-bottom: 15px;
|
| 157 |
+
}
|
| 158 |
+
button {
|
| 159 |
+
padding: 10px 20px;
|
| 160 |
+
font-size: 16px;
|
| 161 |
+
background-color: #007bff;
|
| 162 |
+
color: white;
|
| 163 |
+
border: none;
|
| 164 |
+
border-radius: 6px;
|
| 165 |
+
margin: 5px;
|
| 166 |
+
cursor: pointer;
|
| 167 |
+
transition: background-color 0.3s;
|
| 168 |
+
}
|
| 169 |
+
button:hover {
|
| 170 |
+
background-color: #0056b3;
|
| 171 |
+
}
|
| 172 |
+
#result img {
|
| 173 |
+
max-width: 100%;
|
| 174 |
+
border-radius: 10px;
|
| 175 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
|
| 176 |
+
margin-top: 10px;
|
| 177 |
+
}
|
| 178 |
</style>
|
| 179 |
</head>
|
| 180 |
<body>
|
| 181 |
+
<h2>Live Gesture Detection via Laptop Camera</h2>
|
| 182 |
<video id="video" autoplay muted playsinline></video>
|
| 183 |
<canvas id="canvas" style="display:none;"></canvas>
|
| 184 |
<br>
|
| 185 |
<button id="start">Start Detection</button>
|
| 186 |
<button id="stop">Stop</button>
|
|
|
|
| 187 |
<div id="result"></div>
|
|
|
|
| 188 |
<script>
|
| 189 |
const video = document.getElementById('video');
|
| 190 |
const canvas = document.getElementById('canvas');
|
|
|
|
| 204 |
canvas.width = video.videoWidth;
|
| 205 |
canvas.height = video.videoHeight;
|
| 206 |
canvas.getContext('2d').drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
|
|
| 207 |
canvas.toBlob(async (blob) => {
|
| 208 |
const formData = new FormData();
|
| 209 |
formData.append("image", blob, "frame.jpg");
|
|
|
|
| 210 |
const res = await fetch("/detect", {
|
| 211 |
method: "POST",
|
| 212 |
body: formData
|
| 213 |
});
|
|
|
|
| 214 |
if (res.ok) {
|
| 215 |
const data = await res.json();
|
| 216 |
resultDiv.innerHTML = `
|
|
|
|
| 221 |
<img src="${data.saved_to}" />
|
| 222 |
`;
|
| 223 |
} else {
|
| 224 |
+
resultDiv.innerHTML = "<p style='color:red;'>Detection failed.</p>";
|
| 225 |
}
|
| 226 |
}, "image/jpeg");
|
| 227 |
}, 1500);
|
|
|
|
| 229 |
|
| 230 |
document.getElementById("stop").onclick = () => {
|
| 231 |
clearInterval(intervalId);
|
| 232 |
+
resultDiv.innerHTML = "<p style='color:gray;'>Stopped.</p>";
|
| 233 |
};
|
| 234 |
</script>
|
| 235 |
</body>
|
| 236 |
</html>
|
| 237 |
"""
|
| 238 |
|
|
|
|
| 239 |
if __name__ == "__main__":
|
| 240 |
app.run(host="0.0.0.0", port=5000)
|