Add 2 files
Browse files- README.md +7 -5
- index.html +916 -19
README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
|
|
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 1 |
---
|
| 2 |
+
title: test
|
| 3 |
+
emoji: 🐳
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: blue
|
| 6 |
sdk: static
|
| 7 |
pinned: false
|
| 8 |
+
tags:
|
| 9 |
+
- deepsite
|
| 10 |
---
|
| 11 |
|
| 12 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
index.html
CHANGED
|
@@ -1,19 +1,916 @@
|
|
| 1 |
-
<!
|
| 2 |
-
<html>
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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ta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>VisionAI - Interactive Object Detection</title>
|
| 7 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
| 8 |
+
<style>
|
| 9 |
+
:root {
|
| 10 |
+
--primary: #4361ee;
|
| 11 |
+
--secondary: #3f37c9;
|
| 12 |
+
--accent: #4cc9f0;
|
| 13 |
+
--light: #f8f9fa;
|
| 14 |
+
--dark: #212529;
|
| 15 |
+
--success: #4caf50;
|
| 16 |
+
--warning: #ff9800;
|
| 17 |
+
--danger: #f44336;
|
| 18 |
+
--shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
| 19 |
+
--transition: all 0.3s ease;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
* {
|
| 23 |
+
margin: 0;
|
| 24 |
+
padding: 0;
|
| 25 |
+
box-sizing: border-box;
|
| 26 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
body {
|
| 30 |
+
background-color: #f5f7fa;
|
| 31 |
+
color: var(--dark);
|
| 32 |
+
line-height: 1.6;
|
| 33 |
+
overflow-x: hidden;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
.container {
|
| 37 |
+
max-width: 1200px;
|
| 38 |
+
margin: 0 auto;
|
| 39 |
+
padding: 20px;
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
header {
|
| 43 |
+
background: linear-gradient(135deg, var(--primary), var(--secondary));
|
| 44 |
+
color: white;
|
| 45 |
+
padding: 20px 0;
|
| 46 |
+
text-align: center;
|
| 47 |
+
border-radius: 0 0 20px 20px;
|
| 48 |
+
box-shadow: var(--shadow);
|
| 49 |
+
margin-bottom: 30px;
|
| 50 |
+
position: relative;
|
| 51 |
+
overflow: hidden;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
header::before {
|
| 55 |
+
content: '';
|
| 56 |
+
position: absolute;
|
| 57 |
+
top: 0;
|
| 58 |
+
left: 0;
|
| 59 |
+
width: 100%;
|
| 60 |
+
height: 100%;
|
| 61 |
+
background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiPjxkZWZzPjxwYXR0ZXJuIGlkPSJwYXR0ZXJuIiB3aWR0aD0iNDAiIGhlaWdodD0iNDAiIHBhdHRlcm5Vbml0cz0idXNlclNwYWNlT25Vc2UiIHBhdHRlcm5UcmFuc2Zvcm09InJvdGF0ZSg0NSkiPjxyZWN0IHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgZmlsbD0icmdiYSgyNTUsMjU1LDI1NSwwLjAzKSIvPjwvcGF0dGVybj48L2RlZnM+PHJlY3QgZmlsbD0idXJsKCNwYXR0ZXJuKSIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIvPjwvc3ZnPg==');
|
| 62 |
+
opacity: 0.5;
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
header h1 {
|
| 66 |
+
font-size: 2.5rem;
|
| 67 |
+
margin-bottom: 10px;
|
| 68 |
+
position: relative;
|
| 69 |
+
animation: fadeInDown 0.8s ease;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
header p {
|
| 73 |
+
font-size: 1.1rem;
|
| 74 |
+
opacity: 0.9;
|
| 75 |
+
position: relative;
|
| 76 |
+
animation: fadeInUp 0.8s ease;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
@keyframes fadeInDown {
|
| 80 |
+
from {
|
| 81 |
+
opacity: 0;
|
| 82 |
+
transform: translateY(-30px);
|
| 83 |
+
}
|
| 84 |
+
to {
|
| 85 |
+
opacity: 1;
|
| 86 |
+
transform: translateY(0);
|
| 87 |
+
}
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
@keyframes fadeInUp {
|
| 91 |
+
from {
|
| 92 |
+
opacity: 0;
|
| 93 |
+
transform: translateY(30px);
|
| 94 |
+
}
|
| 95 |
+
to {
|
| 96 |
+
opacity: 1;
|
| 97 |
+
transform: translateY(0);
|
| 98 |
+
}
|
| 99 |
+
}
|
| 100 |
+
|
| 101 |
+
.main-content {
|
| 102 |
+
display: flex;
|
| 103 |
+
flex-direction: column;
|
| 104 |
+
gap: 30px;
|
| 105 |
+
}
|
| 106 |
+
|
| 107 |
+
.detection-section {
|
| 108 |
+
background-color: white;
|
| 109 |
+
border-radius: 15px;
|
| 110 |
+
box-shadow: var(--shadow);
|
| 111 |
+
padding: 25px;
|
| 112 |
+
display: flex;
|
| 113 |
+
flex-direction: column;
|
| 114 |
+
gap: 20px;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
.section-title {
|
| 118 |
+
font-size: 1.5rem;
|
| 119 |
+
color: var(--primary);
|
| 120 |
+
margin-bottom: 10px;
|
| 121 |
+
display: flex;
|
| 122 |
+
align-items: center;
|
| 123 |
+
gap: 10px;
|
| 124 |
+
}
|
| 125 |
+
|
| 126 |
+
.section-title i {
|
| 127 |
+
font-size: 1.8rem;
|
| 128 |
+
}
|
| 129 |
+
|
| 130 |
+
.controls {
|
| 131 |
+
display: flex;
|
| 132 |
+
flex-wrap: wrap;
|
| 133 |
+
gap: 15px;
|
| 134 |
+
margin-bottom: 20px;
|
| 135 |
+
}
|
| 136 |
+
|
| 137 |
+
.btn {
|
| 138 |
+
background-color: var(--primary);
|
| 139 |
+
color: white;
|
| 140 |
+
border: none;
|
| 141 |
+
padding: 10px 20px;
|
| 142 |
+
border-radius: 50px;
|
| 143 |
+
cursor: pointer;
|
| 144 |
+
font-size: 1rem;
|
| 145 |
+
font-weight: 600;
|
| 146 |
+
transition: var(--transition);
|
| 147 |
+
display: flex;
|
| 148 |
+
align-items: center;
|
| 149 |
+
gap: 8px;
|
| 150 |
+
box-shadow: var(--shadow);
|
| 151 |
+
}
|
| 152 |
+
|
| 153 |
+
.btn:hover {
|
| 154 |
+
background-color: var(--secondary);
|
| 155 |
+
transform: translateY(-2px);
|
| 156 |
+
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
.btn:active {
|
| 160 |
+
transform: translateY(0);
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
.btn.btn-outline {
|
| 164 |
+
background-color: transparent;
|
| 165 |
+
border: 2px solid var(--primary);
|
| 166 |
+
color: var(--primary);
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
.btn.btn-outline:hover {
|
| 170 |
+
background-color: var(--primary);
|
| 171 |
+
color: white;
|
| 172 |
+
}
|
| 173 |
+
|
| 174 |
+
.btn.btn-success {
|
| 175 |
+
background-color: var(--success);
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
.btn.btn-warning {
|
| 179 |
+
background-color: var(--warning);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
.btn.btn-danger {
|
| 183 |
+
background-color: var(--danger);
|
| 184 |
+
}
|
| 185 |
+
|
| 186 |
+
.btn.btn-accent {
|
| 187 |
+
background-color: var(--accent);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
.btn:disabled {
|
| 191 |
+
background-color: #cccccc;
|
| 192 |
+
cursor: not-allowed;
|
| 193 |
+
transform: none;
|
| 194 |
+
box-shadow: none;
|
| 195 |
+
}
|
| 196 |
+
|
| 197 |
+
.video-container {
|
| 198 |
+
position: relative;
|
| 199 |
+
width: 100%;
|
| 200 |
+
max-width: 800px;
|
| 201 |
+
margin: 0 auto;
|
| 202 |
+
border-radius: 10px;
|
| 203 |
+
overflow: hidden;
|
| 204 |
+
box-shadow: var(--shadow);
|
| 205 |
+
}
|
| 206 |
+
|
| 207 |
+
#video {
|
| 208 |
+
width: 100%;
|
| 209 |
+
display: block;
|
| 210 |
+
background-color: #e9ecef;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
#canvas {
|
| 214 |
+
position: absolute;
|
| 215 |
+
top: 0;
|
| 216 |
+
left: 0;
|
| 217 |
+
width: 100%;
|
| 218 |
+
height: 100%;
|
| 219 |
+
}
|
| 220 |
+
|
| 221 |
+
.file-input {
|
| 222 |
+
display: none;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
.file-label {
|
| 226 |
+
display: flex;
|
| 227 |
+
align-items: center;
|
| 228 |
+
justify-content: center;
|
| 229 |
+
padding: 12px 20px;
|
| 230 |
+
background-color: var(--primary);
|
| 231 |
+
color: white;
|
| 232 |
+
border-radius: 50px;
|
| 233 |
+
cursor: pointer;
|
| 234 |
+
transition: var(--transition);
|
| 235 |
+
box-shadow: var(--shadow);
|
| 236 |
+
max-width: 300px;
|
| 237 |
+
}
|
| 238 |
+
|
| 239 |
+
.file-label:hover {
|
| 240 |
+
background-color: var(--secondary);
|
| 241 |
+
transform: translateY(-2px);
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
.detection-results {
|
| 245 |
+
margin-top: 20px;
|
| 246 |
+
display: grid;
|
| 247 |
+
grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
|
| 248 |
+
gap: 15px;
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
.detection-card {
|
| 252 |
+
background-color: white;
|
| 253 |
+
border-radius: 10px;
|
| 254 |
+
padding: 15px;
|
| 255 |
+
box-shadow: var(--shadow);
|
| 256 |
+
transition: var(--transition);
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
.detection-card:hover {
|
| 260 |
+
transform: translateY(-5px);
|
| 261 |
+
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.1);
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
.detection-label {
|
| 265 |
+
font-weight: bold;
|
| 266 |
+
color: var(--primary);
|
| 267 |
+
display: flex;
|
| 268 |
+
align-items: center;
|
| 269 |
+
gap: 8px;
|
| 270 |
+
margin-bottom: 5px;
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
.detection-confidence {
|
| 274 |
+
height: 6px;
|
| 275 |
+
background-color: #e9ecef;
|
| 276 |
+
border-radius: 3px;
|
| 277 |
+
margin-bottom: 8px;
|
| 278 |
+
overflow: hidden;
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
.confidence-bar {
|
| 282 |
+
height: 100%;
|
| 283 |
+
background: linear-gradient(90deg, var(--accent), var(--primary));
|
| 284 |
+
border-radius: 3px;
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
.detection-stats {
|
| 288 |
+
display: flex;
|
| 289 |
+
justify-content: space-between;
|
| 290 |
+
font-size: 0.8rem;
|
| 291 |
+
color: #6c757d;
|
| 292 |
+
}
|
| 293 |
+
|
| 294 |
+
.loading {
|
| 295 |
+
display: flex;
|
| 296 |
+
flex-direction: column;
|
| 297 |
+
align-items: center;
|
| 298 |
+
justify-content: center;
|
| 299 |
+
gap: 15px;
|
| 300 |
+
padding: 30px;
|
| 301 |
+
background-color: rgba(255, 255, 255, 0.8);
|
| 302 |
+
border-radius: 10px;
|
| 303 |
+
margin: 20px 0;
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
.spinner {
|
| 307 |
+
width: 40px;
|
| 308 |
+
height: 40px;
|
| 309 |
+
border: 4px solid rgba(67, 97, 238, 0.2);
|
| 310 |
+
border-top-color: var(--primary);
|
| 311 |
+
border-radius: 50%;
|
| 312 |
+
animation: spin 1s linear infinite;
|
| 313 |
+
}
|
| 314 |
+
|
| 315 |
+
@keyframes spin {
|
| 316 |
+
to {
|
| 317 |
+
transform: rotate(360deg);
|
| 318 |
+
}
|
| 319 |
+
}
|
| 320 |
+
|
| 321 |
+
.stats-container {
|
| 322 |
+
display: flex;
|
| 323 |
+
gap: 20px;
|
| 324 |
+
flex-wrap: wrap;
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
.stat-card {
|
| 328 |
+
flex: 1;
|
| 329 |
+
min-width: 150px;
|
| 330 |
+
background-color: white;
|
| 331 |
+
border-radius: 10px;
|
| 332 |
+
padding: 20px;
|
| 333 |
+
display: flex;
|
| 334 |
+
flex-direction: column;
|
| 335 |
+
align-items: center;
|
| 336 |
+
box-shadow: var(--shadow);
|
| 337 |
+
transition: var(--transition);
|
| 338 |
+
}
|
| 339 |
+
|
| 340 |
+
.stat-card:hover {
|
| 341 |
+
transform: translateY(-5px);
|
| 342 |
+
box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
|
| 343 |
+
}
|
| 344 |
+
|
| 345 |
+
.stat-value {
|
| 346 |
+
font-size: 2.5rem;
|
| 347 |
+
font-weight: bold;
|
| 348 |
+
color: var(--primary);
|
| 349 |
+
line-height: 1;
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
.stat-label {
|
| 353 |
+
font-size: 0.9rem;
|
| 354 |
+
color: #6c757d;
|
| 355 |
+
text-align: center;
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
footer {
|
| 359 |
+
text-align: center;
|
| 360 |
+
padding: 30px 0;
|
| 361 |
+
margin-top: 50px;
|
| 362 |
+
color: #6c757d;
|
| 363 |
+
font-size: 0.9rem;
|
| 364 |
+
}
|
| 365 |
+
|
| 366 |
+
@media (max-width: 768px) {
|
| 367 |
+
header h1 {
|
| 368 |
+
font-size: 2rem;
|
| 369 |
+
}
|
| 370 |
+
|
| 371 |
+
.controls {
|
| 372 |
+
flex-direction: column;
|
| 373 |
+
align-items: stretch;
|
| 374 |
+
}
|
| 375 |
+
|
| 376 |
+
.file-label {
|
| 377 |
+
max-width: 100%;
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
.detection-results {
|
| 381 |
+
grid-template-columns: 1fr 1fr;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
.stats-container {
|
| 385 |
+
flex-direction: column;
|
| 386 |
+
}
|
| 387 |
+
}
|
| 388 |
+
|
| 389 |
+
/* Toggle switch */
|
| 390 |
+
.toggle-container {
|
| 391 |
+
display: flex;
|
| 392 |
+
align-items: center;
|
| 393 |
+
gap: 10px;
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
.switch {
|
| 397 |
+
position: relative;
|
| 398 |
+
display: inline-block;
|
| 399 |
+
width: 60px;
|
| 400 |
+
height: 34px;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
.switch input {
|
| 404 |
+
opacity: 0;
|
| 405 |
+
width: 0;
|
| 406 |
+
height: 0;
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
.slider {
|
| 410 |
+
position: absolute;
|
| 411 |
+
cursor: pointer;
|
| 412 |
+
top: 0;
|
| 413 |
+
left: 0;
|
| 414 |
+
right: 0;
|
| 415 |
+
bottom: 0;
|
| 416 |
+
background-color: #ccc;
|
| 417 |
+
transition: .4s;
|
| 418 |
+
border-radius: 34px;
|
| 419 |
+
}
|
| 420 |
+
|
| 421 |
+
.slider:before {
|
| 422 |
+
position: absolute;
|
| 423 |
+
content: "";
|
| 424 |
+
height: 26px;
|
| 425 |
+
width: 26px;
|
| 426 |
+
left: 4px;
|
| 427 |
+
bottom: 4px;
|
| 428 |
+
background-color: white;
|
| 429 |
+
transition: .4s;
|
| 430 |
+
border-radius: 50%;
|
| 431 |
+
}
|
| 432 |
+
|
| 433 |
+
input:checked + .slider {
|
| 434 |
+
background-color: var(--primary);
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
input:focus + .slider {
|
| 438 |
+
box-shadow: 0 0 1px var(--primary);
|
| 439 |
+
}
|
| 440 |
+
|
| 441 |
+
input:checked + .slider:before {
|
| 442 |
+
transform: translateX(26px);
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
/* Custom select */
|
| 446 |
+
.select-container {
|
| 447 |
+
position: relative;
|
| 448 |
+
min-width: 200px;
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
.custom-select {
|
| 452 |
+
appearance: none;
|
| 453 |
+
-webkit-appearance: none;
|
| 454 |
+
-moz-appearance: none;
|
| 455 |
+
width: 100%;
|
| 456 |
+
padding: 10px 20px;
|
| 457 |
+
border: 2px solid #e9ecef;
|
| 458 |
+
border-radius: 50px;
|
| 459 |
+
background-color: white;
|
| 460 |
+
font-size: 1rem;
|
| 461 |
+
font-weight: 600;
|
| 462 |
+
color: var(--dark);
|
| 463 |
+
cursor: pointer;
|
| 464 |
+
transition: var(--transition);
|
| 465 |
+
box-shadow: var(--shadow);
|
| 466 |
+
}
|
| 467 |
+
|
| 468 |
+
.custom-select:focus {
|
| 469 |
+
outline: none;
|
| 470 |
+
border-color: var(--primary);
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
.select-container::after {
|
| 474 |
+
content: "\f078";
|
| 475 |
+
font-family: "Font Awesome 6 Free";
|
| 476 |
+
font-weight: 900;
|
| 477 |
+
position: absolute;
|
| 478 |
+
top: 50%;
|
| 479 |
+
right: 20px;
|
| 480 |
+
transform: translateY(-50%);
|
| 481 |
+
pointer-events: none;
|
| 482 |
+
color: var(--primary);
|
| 483 |
+
}
|
| 484 |
+
</style>
|
| 485 |
+
</head>
|
| 486 |
+
<body>
|
| 487 |
+
<header>
|
| 488 |
+
<div class="container">
|
| 489 |
+
<h1><i class="fas fa-eye"></i> VisionAI</h1>
|
| 490 |
+
<p>Real-time interactive object detection powered by TensorFlow.js</p>
|
| 491 |
+
</div>
|
| 492 |
+
</header>
|
| 493 |
+
|
| 494 |
+
<div class="container">
|
| 495 |
+
<div class="main-content">
|
| 496 |
+
<section class="detection-section">
|
| 497 |
+
<h2 class="section-title"><i class="fas fa-camera"></i> Real-time Detection</h2>
|
| 498 |
+
<div class="controls">
|
| 499 |
+
<button id="startBtn" class="btn btn-success">
|
| 500 |
+
<i class="fas fa-play"></i> Start Webcam
|
| 501 |
+
</button>
|
| 502 |
+
<button id="stopBtn" class="btn btn-danger" disabled>
|
| 503 |
+
<i class="fas fa-stop"></i> Stop Webcam
|
| 504 |
+
</button>
|
| 505 |
+
<div class="toggle-container">
|
| 506 |
+
<span>Detection:</span>
|
| 507 |
+
<label class="switch">
|
| 508 |
+
<input type="checkbox" id="detectToggle" checked>
|
| 509 |
+
<span class="slider"></span>
|
| 510 |
+
</label>
|
| 511 |
+
</div>
|
| 512 |
+
<div class="select-container">
|
| 513 |
+
<select id="modelSelect" class="custom-select">
|
| 514 |
+
<option value="lite">Lite Model (Fast)</option>
|
| 515 |
+
<option value="default" selected>Default Model (Balanced)</option>
|
| 516 |
+
<option value="heavy">Heavy Model (Accurate)</option>
|
| 517 |
+
</select>
|
| 518 |
+
</div>
|
| 519 |
+
</div>
|
| 520 |
+
<div class="video-container">
|
| 521 |
+
<video id="video" autoplay muted playsinline></video>
|
| 522 |
+
<canvas id="canvas"></canvas>
|
| 523 |
+
</div>
|
| 524 |
+
<div class="loading" id="modelLoading" style="display: none;">
|
| 525 |
+
<div class="spinner"></div>
|
| 526 |
+
<p>Loading AI model. Please wait...</p>
|
| 527 |
+
</div>
|
| 528 |
+
<div id="statsContainer" class="stats-container">
|
| 529 |
+
<div class="stat-card">
|
| 530 |
+
<div class="stat-value" id="detectionCount">0</div>
|
| 531 |
+
<div class="stat-label">Objects Detected</div>
|
| 532 |
+
</div>
|
| 533 |
+
<div class="stat-card">
|
| 534 |
+
<div class="stat-value" id="fpsCount">0</div>
|
| 535 |
+
<div class="stat-label">FPS</div>
|
| 536 |
+
</div>
|
| 537 |
+
<div class="stat-card">
|
| 538 |
+
<div class="stat-value" id="avgConfidence">0%</div>
|
| 539 |
+
<div class="stat-label">Avg Confidence</div>
|
| 540 |
+
</div>
|
| 541 |
+
</div>
|
| 542 |
+
</section>
|
| 543 |
+
|
| 544 |
+
<section class="detection-section">
|
| 545 |
+
<h2 class="section-title"><i class="fas fa-image"></i> Image Detection</h2>
|
| 546 |
+
<div class="controls">
|
| 547 |
+
<label for="fileInput" class="file-label">
|
| 548 |
+
<i class="fas fa-upload"></i> Upload Image
|
| 549 |
+
</label>
|
| 550 |
+
<input type="file" id="fileInput" accept="image/*" class="file-input">
|
| 551 |
+
<button id="detectBtn" class="btn btn-accent" disabled>
|
| 552 |
+
<i class="fas fa-search"></i> Detect Objects
|
| 553 |
+
</button>
|
| 554 |
+
<button id="clearBtn" class="btn btn-outline">
|
| 555 |
+
<i class="fas fa-trash-alt"></i> Clear
|
| 556 |
+
</button>
|
| 557 |
+
</div>
|
| 558 |
+
<div id="imageContainer" style="display: flex; justify-content: center; margin-bottom: 20px;">
|
| 559 |
+
<img id="uploadedImage" style="max-width: 100%; border-radius: 10px; display: none; box-shadow: var(--shadow);">
|
| 560 |
+
<canvas id="imageCanvas" style="display: none; max-width: 100%; border-radius: 10px; box-shadow: var(--shadow);"></canvas>
|
| 561 |
+
</div>
|
| 562 |
+
<div class="loading" id="imageLoading" style="display: none;">
|
| 563 |
+
<div class="spinner"></div>
|
| 564 |
+
<p>Detecting objects in image...</p>
|
| 565 |
+
</div>
|
| 566 |
+
<div id="imageResultsContainer">
|
| 567 |
+
<h3 class="section-title"><i class="fas fa-list"></i> Detection Results</h3>
|
| 568 |
+
<div id="detectionResults" class="detection-results"></div>
|
| 569 |
+
</div>
|
| 570 |
+
</section>
|
| 571 |
+
</div>
|
| 572 |
+
</div>
|
| 573 |
+
|
| 574 |
+
<footer>
|
| 575 |
+
<div class="container">
|
| 576 |
+
<p>Interactive Object Detection Demo using TensorFlow.js COCO-SSD model</p>
|
| 577 |
+
<p>Created with <i class="fas fa-heart" style="color: var(--danger);"></i> for computer vision enthusiasts</p>
|
| 578 |
+
</div>
|
| 579 |
+
</footer>
|
| 580 |
+
|
| 581 |
+
<!-- Load TensorFlow.js and COCO-SSD model -->
|
| 582 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs@3.11.0/dist/tf.min.js"></script>
|
| 583 |
+
<script src="https://cdn.jsdelivr.net/npm/@tensorflow-models/coco-ssd@2.2.2/dist/coco-ssd.min.js"></script>
|
| 584 |
+
|
| 585 |
+
<script>
|
| 586 |
+
// DOM Elements
|
| 587 |
+
const video = document.getElementById('video');
|
| 588 |
+
const canvas = document.getElementById('canvas');
|
| 589 |
+
const ctx = canvas.getContext('2d');
|
| 590 |
+
const startBtn = document.getElementById('startBtn');
|
| 591 |
+
const stopBtn = document.getElementById('stopBtn');
|
| 592 |
+
const detectToggle = document.getElementById('detectToggle');
|
| 593 |
+
const modelSelect = document.getElementById('modelSelect');
|
| 594 |
+
const modelLoading = document.getElementById('modelLoading');
|
| 595 |
+
const detectionCount = document.getElementById('detectionCount');
|
| 596 |
+
const fpsCount = document.getElementById('fpsCount');
|
| 597 |
+
const avgConfidence = document.getElementById('avgConfidence');
|
| 598 |
+
const fileInput = document.getElementById('fileInput');
|
| 599 |
+
const uploadedImage = document.getElementById('uploadedImage');
|
| 600 |
+
const imageCanvas = document.getElementById('imageCanvas');
|
| 601 |
+
const imageCtx = imageCanvas.getContext('2d');
|
| 602 |
+
const detectBtn = document.getElementById('detectBtn');
|
| 603 |
+
const clearBtn = document.getElementById('clearBtn');
|
| 604 |
+
const imageLoading = document.getElementById('imageLoading');
|
| 605 |
+
const detectionResults = document.getElementById('detectionResults');
|
| 606 |
+
|
| 607 |
+
// Variables
|
| 608 |
+
let model = null;
|
| 609 |
+
let stream = null;
|
| 610 |
+
let detectionActive = true;
|
| 611 |
+
let lastTime = 0;
|
| 612 |
+
let frameCount = 0;
|
| 613 |
+
let fps = 0;
|
| 614 |
+
let objectsDetected = 0;
|
| 615 |
+
let totalConfidence = 0;
|
| 616 |
+
|
| 617 |
+
// Initialize
|
| 618 |
+
async function init() {
|
| 619 |
+
// Load model
|
| 620 |
+
modelLoading.style.display = 'flex';
|
| 621 |
+
try {
|
| 622 |
+
model = await cocoSsd.load({
|
| 623 |
+
base: modelSelect.value
|
| 624 |
+
});
|
| 625 |
+
console.log('Model loaded successfully');
|
| 626 |
+
} catch (error) {
|
| 627 |
+
console.error('Error loading model:', error);
|
| 628 |
+
alert('Failed to load the AI model. Please try again.');
|
| 629 |
+
}
|
| 630 |
+
modelLoading.style.display = 'none';
|
| 631 |
+
|
| 632 |
+
// Add event listeners
|
| 633 |
+
startBtn.addEventListener('click', startWebcam);
|
| 634 |
+
stopBtn.addEventListener('click', stopWebcam);
|
| 635 |
+
detectToggle.addEventListener('change', toggleDetection);
|
| 636 |
+
modelSelect.addEventListener('change', reloadModel);
|
| 637 |
+
|
| 638 |
+
fileInput.addEventListener('change', handleFileUpload);
|
| 639 |
+
detectBtn.addEventListener('click', detectInImage);
|
| 640 |
+
clearBtn.addEventListener('click', clearImageDetection);
|
| 641 |
+
|
| 642 |
+
// Start animate loop for FPS calculation
|
| 643 |
+
requestAnimationFrame(updateFPS);
|
| 644 |
+
}
|
| 645 |
+
|
| 646 |
+
// Webcam functions
|
| 647 |
+
async function startWebcam() {
|
| 648 |
+
try {
|
| 649 |
+
stream = await navigator.mediaDevices.getUserMedia({
|
| 650 |
+
video: {
|
| 651 |
+
facingMode: 'environment',
|
| 652 |
+
width: { ideal: 1280 },
|
| 653 |
+
height: { ideal: 720 }
|
| 654 |
+
},
|
| 655 |
+
audio: false
|
| 656 |
+
});
|
| 657 |
+
video.srcObject = stream;
|
| 658 |
+
startBtn.disabled = true;
|
| 659 |
+
stopBtn.disabled = false;
|
| 660 |
+
|
| 661 |
+
// Wait for video to be ready
|
| 662 |
+
video.onloadedmetadata = () => {
|
| 663 |
+
// Set canvas dimensions to match video
|
| 664 |
+
canvas.width = video.videoWidth;
|
| 665 |
+
canvas.height = video.videoHeight;
|
| 666 |
+
|
| 667 |
+
// Start detection loop
|
| 668 |
+
detectObjectsInVideo();
|
| 669 |
+
};
|
| 670 |
+
} catch (error) {
|
| 671 |
+
console.error('Error accessing webcam:', error);
|
| 672 |
+
alert('Could not access the webcam. Make sure you have granted camera permissions.');
|
| 673 |
+
}
|
| 674 |
+
}
|
| 675 |
+
|
| 676 |
+
function stopWebcam() {
|
| 677 |
+
if (stream) {
|
| 678 |
+
stream.getTracks().forEach(track => track.stop());
|
| 679 |
+
video.srcObject = null;
|
| 680 |
+
startBtn.disabled = false;
|
| 681 |
+
stopBtn.disabled = true;
|
| 682 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 683 |
+
}
|
| 684 |
+
}
|
| 685 |
+
|
| 686 |
+
// Object detection in video
|
| 687 |
+
async function detectObjectsInVideo() {
|
| 688 |
+
if (!stream || !detectionActive || !model) return;
|
| 689 |
+
|
| 690 |
+
try {
|
| 691 |
+
// Perform detection
|
| 692 |
+
const predictions = await model.detect(video);
|
| 693 |
+
|
| 694 |
+
// Clear previous drawings
|
| 695 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 696 |
+
|
| 697 |
+
// Draw new detections
|
| 698 |
+
drawDetections(predictions, ctx);
|
| 699 |
+
|
| 700 |
+
// Update stats
|
| 701 |
+
objectsDetected = predictions.length;
|
| 702 |
+
detectionCount.textContent = objectsDetected;
|
| 703 |
+
|
| 704 |
+
// Calculate average confidence
|
| 705 |
+
if (predictions.length > 0) {
|
| 706 |
+
totalConfidence = predictions.reduce((sum, pred) => sum + pred.score, 0);
|
| 707 |
+
avgConfidence.textContent = Math.round((totalConfidence / predictions.length) * 100) + '%';
|
| 708 |
+
} else {
|
| 709 |
+
avgConfidence.textContent = '0%';
|
| 710 |
+
}
|
| 711 |
+
|
| 712 |
+
// Call next frame
|
| 713 |
+
requestAnimationFrame(detectObjectsInVideo);
|
| 714 |
+
} catch (error) {
|
| 715 |
+
console.error('Detection error:', error);
|
| 716 |
+
setTimeout(detectObjectsInVideo, 1000); // Try again after delay
|
| 717 |
+
}
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
// Object detection in image
|
| 721 |
+
async function detectInImage() {
|
| 722 |
+
if (!uploadedImage.style.display || !model) return;
|
| 723 |
+
|
| 724 |
+
imageLoading.style.display = 'flex';
|
| 725 |
+
detectBtn.disabled = true;
|
| 726 |
+
|
| 727 |
+
try {
|
| 728 |
+
// Set canvas dimensions to match image
|
| 729 |
+
imageCanvas.width = uploadedImage.width;
|
| 730 |
+
imageCanvas.height = uploadedImage.height;
|
| 731 |
+
|
| 732 |
+
// Draw image on canvas
|
| 733 |
+
imageCtx.drawImage(uploadedImage, 0, 0, imageCanvas.width, imageCanvas.height);
|
| 734 |
+
|
| 735 |
+
// Perform detection
|
| 736 |
+
const predictions = await model.detect(imageCanvas);
|
| 737 |
+
|
| 738 |
+
// Show canvas (with detections)
|
| 739 |
+
uploadedImage.style.display = 'none';
|
| 740 |
+
imageCanvas.style.display = 'block';
|
| 741 |
+
|
| 742 |
+
// Draw detections
|
| 743 |
+
drawDetections(predictions, imageCtx);
|
| 744 |
+
|
| 745 |
+
// Display results
|
| 746 |
+
displayDetectionResults(predictions);
|
| 747 |
+
} catch (error) {
|
| 748 |
+
console.error('Image detection error:', error);
|
| 749 |
+
alert('Error detecting objects in image. Please try again.');
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
imageLoading.style.display = 'none';
|
| 753 |
+
detectBtn.disabled = false;
|
| 754 |
+
}
|
| 755 |
+
|
| 756 |
+
// Helper functions
|
| 757 |
+
function drawDetections(predictions, context) {
|
| 758 |
+
predictions.forEach(prediction => {
|
| 759 |
+
// Draw bounding box
|
| 760 |
+
context.beginPath();
|
| 761 |
+
context.rect(
|
| 762 |
+
prediction.bbox[0],
|
| 763 |
+
prediction.bbox[1],
|
| 764 |
+
prediction.bbox[2],
|
| 765 |
+
prediction.bbox[3]
|
| 766 |
+
);
|
| 767 |
+
context.lineWidth = 3;
|
| 768 |
+
context.strokeStyle = '#' + Math.floor(Math.random()*16777215).toString(16);
|
| 769 |
+
context.fillStyle = '#' + Math.floor(Math.random()*16777215).toString(16);
|
| 770 |
+
context.stroke();
|
| 771 |
+
|
| 772 |
+
// Draw label background
|
| 773 |
+
context.font = '16px Arial';
|
| 774 |
+
const textWidth = context.measureText(`${prediction.class} ${(prediction.score * 100).toFixed(1)}%`).width;
|
| 775 |
+
context.fillRect(
|
| 776 |
+
prediction.bbox[0],
|
| 777 |
+
prediction.bbox[1] - 25,
|
| 778 |
+
textWidth + 10,
|
| 779 |
+
25
|
| 780 |
+
);
|
| 781 |
+
|
| 782 |
+
// Draw label text
|
| 783 |
+
context.fillStyle = '#ffffff';
|
| 784 |
+
context.fillText(
|
| 785 |
+
`${prediction.class} ${(prediction.score * 100).toFixed(1)}%`,
|
| 786 |
+
prediction.bbox[0] + 5,
|
| 787 |
+
prediction.bbox[1] - 7
|
| 788 |
+
);
|
| 789 |
+
});
|
| 790 |
+
}
|
| 791 |
+
|
| 792 |
+
function displayDetectionResults(predictions) {
|
| 793 |
+
// Clear previous results
|
| 794 |
+
detectionResults.innerHTML = '';
|
| 795 |
+
|
| 796 |
+
// Group predictions by class and count occurrences
|
| 797 |
+
const classCounts = {};
|
| 798 |
+
const classConfidences = {};
|
| 799 |
+
|
| 800 |
+
predictions.forEach(pred => {
|
| 801 |
+
if (!classCounts[pred.class]) {
|
| 802 |
+
classCounts[pred.class] = 0;
|
| 803 |
+
classConfidences[pred.class] = 0;
|
| 804 |
+
}
|
| 805 |
+
classCounts[pred.class]++;
|
| 806 |
+
classConfidences[pred.class] += pred.score;
|
| 807 |
+
});
|
| 808 |
+
|
| 809 |
+
// Create cards for each detected class
|
| 810 |
+
Object.keys(classCounts).forEach(className => {
|
| 811 |
+
const count = classCounts[className];
|
| 812 |
+
const avgConfidence = (classConfidences[className] / count) * 100;
|
| 813 |
+
|
| 814 |
+
const card = document.createElement('div');
|
| 815 |
+
card.className = 'detection-card';
|
| 816 |
+
card.innerHTML = `
|
| 817 |
+
<div class="detection-label">
|
| 818 |
+
<i class="fas fa-tag"></i> ${className}
|
| 819 |
+
</div>
|
| 820 |
+
<div class="detection-confidence">
|
| 821 |
+
<div class="confidence-bar" style="width: ${avgConfidence}%"></div>
|
| 822 |
+
</div>
|
| 823 |
+
<div class="detection-stats">
|
| 824 |
+
<span>${count}x</span>
|
| 825 |
+
<span>${avgConfidence.toFixed(1)}%</span>
|
| 826 |
+
</div>
|
| 827 |
+
`;
|
| 828 |
+
|
| 829 |
+
detectionResults.appendChild(card);
|
| 830 |
+
});
|
| 831 |
+
|
| 832 |
+
// If no objects detected
|
| 833 |
+
if (predictions.length === 0) {
|
| 834 |
+
const noResults = document.createElement('div');
|
| 835 |
+
noResults.className = 'detection-card';
|
| 836 |
+
noResults.textContent = 'No objects detected';
|
| 837 |
+
detectionResults.appendChild(noResults);
|
| 838 |
+
}
|
| 839 |
+
}
|
| 840 |
+
|
| 841 |
+
function toggleDetection() {
|
| 842 |
+
detectionActive = detectToggle.checked;
|
| 843 |
+
if (detectionActive && stream) {
|
| 844 |
+
detectObjectsInVideo();
|
| 845 |
+
} else {
|
| 846 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 847 |
+
}
|
| 848 |
+
}
|
| 849 |
+
|
| 850 |
+
async function reloadModel() {
|
| 851 |
+
modelLoading.style.display = 'flex';
|
| 852 |
+
if (model) {
|
| 853 |
+
model.dispose(); // Clean up previous model
|
| 854 |
+
}
|
| 855 |
+
try {
|
| 856 |
+
model = await cocoSsd.load({
|
| 857 |
+
base: modelSelect.value
|
| 858 |
+
});
|
| 859 |
+
console.log('Model reloaded with:', modelSelect.value);
|
| 860 |
+
} catch (error) {
|
| 861 |
+
console.error('Error reloading model:', error);
|
| 862 |
+
}
|
| 863 |
+
modelLoading.style.display = 'none';
|
| 864 |
+
|
| 865 |
+
// Restart detection if active
|
| 866 |
+
if (detectionActive && stream) {
|
| 867 |
+
detectObjectsInVideo();
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
// Redetect image if one is loaded
|
| 871 |
+
if (uploadedImage.style.display === 'block') {
|
| 872 |
+
detectInImage();
|
| 873 |
+
}
|
| 874 |
+
}
|
| 875 |
+
|
| 876 |
+
function handleFileUpload(event) {
|
| 877 |
+
const file = event.target.files[0];
|
| 878 |
+
if (file) {
|
| 879 |
+
const reader = new FileReader();
|
| 880 |
+
reader.onload = function(e) {
|
| 881 |
+
uploadedImage.src = e.target.result;
|
| 882 |
+
uploadedImage.style.display = 'block';
|
| 883 |
+
imageCanvas.style.display = 'none';
|
| 884 |
+
detectBtn.disabled = false;
|
| 885 |
+
};
|
| 886 |
+
reader.readAsDataURL(file);
|
| 887 |
+
}
|
| 888 |
+
}
|
| 889 |
+
|
| 890 |
+
function clearImageDetection() {
|
| 891 |
+
uploadedImage.src = '';
|
| 892 |
+
uploadedImage.style.display = 'none';
|
| 893 |
+
imageCanvas.style.display = 'none';
|
| 894 |
+
detectBtn.disabled = true;
|
| 895 |
+
fileInput.value = '';
|
| 896 |
+
detectionResults.innerHTML = '';
|
| 897 |
+
}
|
| 898 |
+
|
| 899 |
+
function updateFPS(timestamp) {
|
| 900 |
+
frameCount++;
|
| 901 |
+
|
| 902 |
+
if (timestamp >= lastTime + 1000) {
|
| 903 |
+
fps = Math.round((frameCount * 1000) / (timestamp - lastTime));
|
| 904 |
+
fpsCount.textContent = fps;
|
| 905 |
+
frameCount = 0;
|
| 906 |
+
lastTime = timestamp;
|
| 907 |
+
}
|
| 908 |
+
|
| 909 |
+
requestAnimationFrame(updateFPS);
|
| 910 |
+
}
|
| 911 |
+
|
| 912 |
+
// Initialize the app
|
| 913 |
+
document.addEventListener('DOMContentLoaded', init);
|
| 914 |
+
</script>
|
| 915 |
+
<p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <a href="https://enzostvs-deepsite.hf.space" style="color: #fff;" target="_blank" >DeepSite</a> <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;"></p></body>
|
| 916 |
+
</html>
|