-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplatform.html
More file actions
524 lines (467 loc) · 27.7 KB
/
platform.html
File metadata and controls
524 lines (467 loc) · 27.7 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Video Face Scanner</title>
<script src="https://cdn.tailwindcss.com"></script>
<!-- Import face-api.js -->
<script src="https://cdn.jsdelivr.net/npm/face-api.js@0.22.2/dist/face-api.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
body {
font-family: 'Inter', sans-serif;
background-color: #111827;
color: #f3f4f6;
}
.loader {
border: 4px solid #f3f3f3;
border-top: 4px solid #3498db;
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.auth-form input[type="email"], .auth-form input[type="password"] {
background-color: #374151;
border: 1px solid #4b5563;
}
#privacy-shield-video-container {
position: relative;
width: 480px;
height: 360px;
}
#privacy-shield-video, #privacy-shield-overlay {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
border-radius: 1rem;
}
#privacy-shield-video {
transform: scaleX(-1); /* Mirror the video */
}
</style>
</head>
<body class="bg-gray-900 text-gray-100 flex items-center justify-center min-h-screen p-4">
<!-- Auth Container -->
<div id="auth-container" class="container mx-auto max-w-md w-full">
<!-- Login View -->
<div id="login-view" class="bg-gray-800 rounded-2xl shadow-lg p-8">
<h2 class="text-3xl font-bold text-center text-white mb-6">Login</h2>
<form id="login-form" class="space-y-4 auth-form">
<input type="email" id="login-email" placeholder="Email ID" class="w-full rounded-lg p-3 text-white focus:outline-none focus:ring-2 focus:ring-blue-500" required>
<input type="password" id="login-password" placeholder="Password" class="w-full rounded-lg p-3 text-white focus:outline-none focus:ring-2 focus:ring-blue-500" required>
<button type="submit" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 rounded-lg transition-transform duration-200 hover:scale-105">Login</button>
</form>
<p id="login-error" class="text-red-400 text-center mt-3 text-sm"></p>
<p class="text-center text-gray-400 mt-4 text-sm">
New user? <a href="#" id="show-register" class="text-blue-400 hover:underline">Register</a>
</p>
</div>
<!-- Register View -->
<div id="register-view" class="bg-gray-800 rounded-2xl shadow-lg p-8 hidden">
<h2 class="text-3xl font-bold text-center text-white mb-6">Register</h2>
<form id="register-form" class="space-y-4 auth-form">
<input type="email" id="register-email" placeholder="Enter Email ID" class="w-full rounded-lg p-3 text-white focus:outline-none focus:ring-2 focus:ring-blue-500" required>
<input type="password" id="register-password" placeholder="Password" class="w-full rounded-lg p-3 text-white focus:outline-none focus:ring-2 focus:ring-blue-500" required>
<input type="password" id="register-reenter-password" placeholder="Re-enter Password" class="w-full rounded-lg p-3 text-white focus:outline-none focus:ring-2 focus:ring-blue-500" required>
<button type="submit" class="w-full bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 rounded-lg transition-transform duration-200 hover:scale-105">Register</button>
</form>
<p id="register-error" class="text-red-400 text-center mt-3 text-sm"></p>
<p class="text-center text-gray-400 mt-4 text-sm">
Already have an account? <a href="#" id="show-login" class="text-blue-400 hover:underline">Login</a>
</p>
</div>
</div>
<!-- App Container -->
<div id="app-container" class="container mx-auto max-w-4xl w-full bg-gray-800 rounded-2xl shadow-lg p-6 md:p-8 hidden">
<div class="flex justify-between items-center mb-8">
<h1 class="text-3xl md:text-4xl font-bold text-white">AI Video Face Scanner</h1>
<div class="relative">
<button id="profile-button" class="bg-gray-700 hover:bg-gray-600 text-white font-bold py-2 px-4 rounded-lg flex items-center space-x-2">
<span>Profile</span>
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path></svg>
</button>
<div id="profile-dropdown" class="absolute right-0 mt-2 w-48 bg-gray-700 rounded-lg shadow-xl hidden z-10">
<a href="#" id="enable-privacy-shield-btn" class="block px-4 py-2 text-sm text-gray-200 hover:bg-gray-600">Enable PrivacyShieldAI</a>
<a href="#" id="logout-button" class="block px-4 py-2 text-sm text-gray-200 hover:bg-gray-600">Logout</a>
</div>
</div>
</div>
<div id="main-content">
<div class="bg-gray-700/50 rounded-lg p-6">
<label for="video-upload" class="cursor-pointer bg-blue-600 hover:bg-blue-700 text-white font-bold py-3 px-5 rounded-lg inline-block transition-transform duration-200 hover:scale-105">
Choose Video File
</label>
<input type="file" id="video-upload" class="hidden" accept="video/*">
<p id="file-name" class="text-gray-400 mt-3 text-sm">No file selected.</p>
</div>
<video id="video-player" class="hidden" muted controls></video>
<canvas id="frame-canvas" class="hidden"></canvas>
</div>
<div id="status-container" class="text-center my-6 hidden">
<div class="flex items-center justify-center space-x-3">
<div id="loader" class="loader"></div>
<p id="status-message" class="text-lg font-medium text-gray-300"></p>
</div>
<div class="w-full bg-gray-700 rounded-full h-2.5 mt-4">
<div id="progress-bar" class="bg-blue-600 h-2.5 rounded-full" style="width: 0%"></div>
</div>
</div>
<div id="results-container" class="hidden mt-8">
<h2 class="text-2xl font-bold mb-4 text-center">Detected People</h2>
<div id="results-grid" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6"></div>
<div class="text-center mt-8">
<button id="reset-button" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded-lg transition-colors">
Scan Another Video
</button>
</div>
</div>
</div>
<!-- Post-Registration PrivacyShieldAI Prompt -->
<div id="privacy-prompt-modal" class="fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center hidden z-50">
<div class="bg-gray-800 rounded-2xl shadow-2xl p-8 text-center space-y-6 max-w-md w-full">
<h2 class="text-2xl font-bold text-blue-400">Secure Your Account</h2>
<p class="text-gray-400">Enable PrivacyShieldAI to create a secure facial profile. This adds an extra layer of security to your account.</p>
<div class="flex justify-center space-x-4">
<button id="privacy-prompt-accept" class="bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-6 rounded-lg">Yes, Secure My Account</button>
<button id="privacy-prompt-decline" class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-6 rounded-lg">Maybe Later</button>
</div>
</div>
</div>
<!-- PrivacyShieldAI Scanning Modal -->
<div id="privacy-shield-modal" class="fixed inset-0 bg-black bg-opacity-75 flex items-center justify-center hidden z-50">
<div class="bg-gray-800 rounded-2xl shadow-2xl p-8 text-center space-y-6 max-w-lg w-full">
<h2 class="text-2xl font-bold text-blue-400">PrivacyShieldAI Setup</h2>
<div id="privacy-shield-scanner">
<div id="privacy-shield-video-container" class="mx-auto bg-gray-900 rounded-xl overflow-hidden shadow-lg mb-4">
<video id="privacy-shield-video" autoplay muted playsinline></video>
<canvas id="privacy-shield-overlay"></canvas>
</div>
<div id="privacy-shield-loading" class="flex flex-col items-center justify-center space-y-3">
<div class="loader ease-linear rounded-full border-4 border-t-4 border-gray-600 h-12 w-12"></div>
<p id="privacy-shield-loading-text" class="text-gray-400 font-medium">Loading AI Models...</p>
</div>
<div id="privacy-shield-instructions" class="hidden">
<p id="privacy-shield-instruction-text" class="text-xl font-semibold text-teal-300 h-8"></p>
<div class="w-full bg-gray-700 rounded-full h-2.5 mt-4">
<div id="privacy-shield-progress-bar" class="bg-teal-400 h-2.5 rounded-full" style="width: 0%"></div>
</div>
</div>
</div>
<div id="privacy-shield-success" class="hidden">
<p class="text-2xl font-semibold text-green-400">Thank you for opting in for PrivacyShieldAI!</p>
<p class="text-gray-400 mt-2">Your secure facial profile has been created.</p>
<button id="privacy-shield-close-btn" class="mt-4 bg-blue-600 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-lg">Close</button>
</div>
</div>
</div>
<script>
let loggedInUserEmail = null;
// --- AUTH ELEMENTS ---
const authContainer = document.getElementById('auth-container');
const appContainer = document.getElementById('app-container');
const loginView = document.getElementById('login-view');
const registerView = document.getElementById('register-view');
const loginForm = document.getElementById('login-form');
const registerForm = document.getElementById('register-form');
const showRegister = document.getElementById('show-register');
const showLogin = document.getElementById('show-login');
const loginError = document.getElementById('login-error');
const registerError = document.getElementById('register-error');
const logoutButton = document.getElementById('logout-button');
const profileButton = document.getElementById('profile-button');
const profileDropdown = document.getElementById('profile-dropdown');
const enablePrivacyShieldBtn = document.getElementById('enable-privacy-shield-btn');
// --- PRIVACY PROMPT ELEMENTS ---
const privacyPromptModal = document.getElementById('privacy-prompt-modal');
const privacyPromptAccept = document.getElementById('privacy-prompt-accept');
const privacyPromptDecline = document.getElementById('privacy-prompt-decline');
// --- PRIVACY SHIELD SCANNING ELEMENTS ---
const privacyShieldModal = document.getElementById('privacy-shield-modal');
const privacyShieldScanner = document.getElementById('privacy-shield-scanner');
const privacyShieldVideo = document.getElementById('privacy-shield-video');
const privacyShieldOverlay = document.getElementById('privacy-shield-overlay');
const privacyShieldLoading = document.getElementById('privacy-shield-loading');
const privacyShieldLoadingText = document.getElementById('privacy-shield-loading-text');
const privacyShieldInstructions = document.getElementById('privacy-shield-instructions');
const privacyShieldInstructionText = document.getElementById('privacy-shield-instruction-text');
const privacyShieldProgressBar = document.getElementById('privacy-shield-progress-bar');
const privacyShieldSuccess = document.getElementById('privacy-shield-success');
const privacyShieldCloseBtn = document.getElementById('privacy-shield-close-btn');
// --- VIDEO SCANNER ELEMENTS ---
const videoUpload = document.getElementById('video-upload');
const fileNameDisplay = document.getElementById('file-name');
const videoPlayer = document.getElementById('video-player');
const frameCanvas = document.getElementById('frame-canvas');
const statusContainer = document.getElementById('status-container');
const loader = document.getElementById('loader');
const statusMessage = document.getElementById('status-message');
const progressBar = document.getElementById('progress-bar');
const mainContent = document.getElementById('main-content');
const resultsContainer = document.getElementById('results-container');
const resultsGrid = document.getElementById('results-grid');
const resetButton = document.getElementById('reset-button');
const MODEL_URL = 'https://cdn.jsdelivr.net/gh/justadudewhohacks/face-api.js@0.22.2/weights';
const FACE_SIMILARITY_THRESHOLD = 0.5;
// --- AUTH LOGIC ---
function getUsers() { return JSON.parse(localStorage.getItem('users_db')) || []; }
function saveUsers(users) { localStorage.setItem('users_db', JSON.stringify(users)); }
function updateUser(email, updatedData) {
let users = getUsers();
const userIndex = users.findIndex(u => u.email === email);
if (userIndex !== -1) {
users[userIndex] = { ...users[userIndex], ...updatedData };
saveUsers(users);
}
}
function checkPrivacyShieldStatus(email) {
const user = getUsers().find(u => u.email === email);
if (user && user.privacyShieldOptIn) {
enablePrivacyShieldBtn.classList.add('hidden');
} else {
enablePrivacyShieldBtn.classList.remove('hidden');
}
}
showRegister.addEventListener('click', (e) => { e.preventDefault(); loginView.classList.add('hidden'); registerView.classList.remove('hidden'); });
showLogin.addEventListener('click', (e) => { e.preventDefault(); registerView.classList.add('hidden'); loginView.classList.remove('hidden'); });
registerForm.addEventListener('submit', (e) => {
e.preventDefault();
registerError.textContent = '';
const email = document.getElementById('register-email').value;
const password = document.getElementById('register-password').value;
const reenterPassword = document.getElementById('register-reenter-password').value;
if (password !== reenterPassword) { registerError.textContent = "Passwords do not match."; return; }
if (getUsers().find(user => user.email === email)) { registerError.textContent = "An account with this email already exists."; return; }
const newUser = { email, password, privacyShieldOptIn: false, faceDescriptors: [] };
saveUsers([...getUsers(), newUser]);
loggedInUserEmail = email;
authContainer.classList.add('hidden');
appContainer.classList.remove('hidden');
checkPrivacyShieldStatus(email);
// Show the opt-in prompt after registration
privacyPromptModal.classList.remove('hidden');
});
loginForm.addEventListener('submit', (e) => {
e.preventDefault();
const email = document.getElementById('login-email').value;
const password = document.getElementById('login-password').value;
const user = getUsers().find(u => u.email === email && u.password === password);
if (user) {
loggedInUserEmail = email;
authContainer.classList.add('hidden');
appContainer.classList.remove('hidden');
checkPrivacyShieldStatus(email);
} else {
loginError.textContent = "Invalid email or password.";
}
});
logoutButton.addEventListener('click', () => {
loggedInUserEmail = null;
appContainer.classList.add('hidden');
authContainer.classList.remove('hidden');
profileDropdown.classList.add('hidden');
loginForm.reset();
registerForm.reset();
resultsContainer.classList.add('hidden');
mainContent.classList.remove('hidden');
if(videoPlayer.src) URL.revokeObjectURL(videoPlayer.src);
});
profileButton.addEventListener('click', () => { profileDropdown.classList.toggle('hidden'); });
// --- PRIVACY SHIELD PROMPT & SCANNING LOGIC ---
privacyPromptAccept.addEventListener('click', () => {
privacyPromptModal.classList.add('hidden');
startPrivacyShieldScan();
});
privacyPromptDecline.addEventListener('click', () => {
privacyPromptModal.classList.add('hidden');
});
enablePrivacyShieldBtn.addEventListener('click', startPrivacyShieldScan);
privacyShieldCloseBtn.addEventListener('click', () => privacyShieldModal.classList.add('hidden'));
let privacyShieldInterval = null;
const scanSteps = [
{ instruction: 'Please look straight ahead', duration: 2 },
{ instruction: 'Slowly look up', duration: 3 },
{ instruction: 'Slowly look down', duration: 3 },
{ instruction: 'Slowly turn your head to your left', duration: 4 },
{ instruction: 'Slowly turn your head to your right', duration: 4 },
];
let currentStep = 0;
let stepTimer = 0;
async function startPrivacyShieldScan() {
privacyShieldModal.classList.remove('hidden');
privacyShieldScanner.classList.remove('hidden');
privacyShieldSuccess.classList.add('hidden');
privacyShieldLoading.classList.remove('hidden');
privacyShieldInstructions.classList.add('hidden');
profileDropdown.classList.add('hidden');
privacyShieldLoadingText.textContent = 'Loading AI Models...';
await Promise.all([
faceapi.nets.ssdMobilenetv1.loadFromUri(MODEL_URL),
faceapi.nets.faceLandmark68Net.loadFromUri(MODEL_URL),
faceapi.nets.faceRecognitionNet.loadFromUri(MODEL_URL)
]);
privacyShieldLoadingText.textContent = 'Starting Camera...';
try {
const stream = await navigator.mediaDevices.getUserMedia({ video: true });
privacyShieldVideo.srcObject = stream;
await new Promise(resolve => privacyShieldVideo.onloadedmetadata = resolve);
} catch (err) {
alert("Camera access is required. Please enable it and try again.");
privacyShieldModal.classList.add('hidden');
return;
}
privacyShieldLoading.classList.add('hidden');
privacyShieldInstructions.classList.remove('hidden');
const collectedDescriptors = [];
currentStep = 0;
stepTimer = 0;
privacyShieldInterval = setInterval(async () => {
if (currentStep >= scanSteps.length) {
privacyShieldInstructionText.textContent = 'Processing...';
privacyShieldProgressBar.style.width = '100%';
stopPrivacyShieldScan();
// Simulate storing embeddings in FAISS by saving to local storage
updateUser(loggedInUserEmail, { faceDescriptors: collectedDescriptors, privacyShieldOptIn: true });
checkPrivacyShieldStatus(loggedInUserEmail);
privacyShieldScanner.classList.add('hidden');
privacyShieldSuccess.classList.remove('hidden');
return;
}
const step = scanSteps[currentStep];
privacyShieldInstructionText.textContent = step.instruction;
const progress = ((currentStep / scanSteps.length) + (stepTimer / step.duration) / scanSteps.length) * 100;
privacyShieldProgressBar.style.width = `${progress}%`;
stepTimer++;
if (stepTimer > step.duration) {
stepTimer = 0;
currentStep++;
}
const detection = await faceapi.detectSingleFace(privacyShieldVideo).withFaceLandmarks().withFaceDescriptor();
drawFaceOutline(detection);
if (detection) {
collectedDescriptors.push(detection.descriptor);
}
}, 1000);
}
function stopPrivacyShieldScan() {
clearInterval(privacyShieldInterval);
if (privacyShieldVideo.srcObject) {
privacyShieldVideo.srcObject.getTracks().forEach(track => track.stop());
}
privacyShieldOverlay.getContext('2d').clearRect(0, 0, privacyShieldOverlay.width, privacyShieldOverlay.height);
}
function drawFaceOutline(detection) {
const canvas = privacyShieldOverlay;
const dims = faceapi.matchDimensions(canvas, privacyShieldVideo, true);
const context = canvas.getContext('2d');
context.clearRect(0, 0, canvas.width, canvas.height);
if (detection) {
const resizedDetection = faceapi.resizeResults(detection, dims);
if (resizedDetection && resizedDetection.detection) {
const box = resizedDetection.detection.box;
context.beginPath();
context.ellipse(box.x + box.width / 2, box.y + box.height / 2, box.width / 2 + 10, box.height/2 + 20, 0, 0, 2 * Math.PI);
context.strokeStyle = '#00FF00';
context.lineWidth = 3;
context.stroke();
}
}
}
// --- VIDEO SCANNING LOGIC ---
async function loadVideoModels() {
statusMessage.textContent = 'Loading AI Models...';
statusContainer.classList.remove('hidden');
await Promise.all([
faceapi.nets.tinyFaceDetector.loadFromUri(MODEL_URL),
faceapi.nets.faceLandmark68Net.loadFromUri(MODEL_URL),
faceapi.nets.faceRecognitionNet.loadFromUri(MODEL_URL),
]);
}
videoUpload.addEventListener('change', async (event) => {
const file = event.target.files[0];
if (!file) return;
fileNameDisplay.textContent = file.name;
mainContent.classList.add('hidden');
videoPlayer.src = URL.createObjectURL(file);
await loadVideoModels();
processVideo();
});
async function processVideo() {
videoPlayer.play();
statusContainer.classList.remove('hidden');
loader.classList.remove('hidden');
const detectedPeople = [];
const canvasCtx = frameCanvas.getContext('2d');
videoPlayer.onseeked = async () => {
if (videoPlayer.paused) return;
const progress = (videoPlayer.currentTime / videoPlayer.duration) * 100;
progressBar.style.width = `${progress}%`;
statusMessage.textContent = `Processing Video... ${Math.round(progress)}%`;
frameCanvas.width = videoPlayer.videoWidth;
frameCanvas.height = videoPlayer.videoHeight;
canvasCtx.drawImage(videoPlayer, 0, 0, frameCanvas.width, frameCanvas.height);
const detections = await faceapi.detectAllFaces(frameCanvas, new faceapi.TinyFaceDetectorOptions()).withFaceLandmarks().withFaceDescriptors();
for (const detection of detections) {
const { descriptor, detection: { box } } = detection;
const faceCanvas = document.createElement('canvas');
const faceCtx = faceCanvas.getContext('2d');
const margin = box.width * 0.15;
faceCanvas.width = box.width + margin * 2;
faceCanvas.height = box.height + margin * 2;
faceCtx.drawImage(frameCanvas, box.x - margin, box.y - margin, box.width + margin * 2, box.height + margin * 2, 0, 0, faceCanvas.width, faceCanvas.height);
const faceImage = faceCanvas.toDataURL('image/jpeg');
let bestMatch = { distance: Infinity, person: null };
for (const person of detectedPeople) {
const distance = faceapi.euclideanDistance(descriptor, person.descriptor);
if (distance < bestMatch.distance) bestMatch = { distance, person };
}
if (bestMatch.person && bestMatch.distance < FACE_SIMILARITY_THRESHOLD) {
bestMatch.person.faces.push({ image: faceImage, box });
} else {
detectedPeople.push({ id: detectedPeople.length + 1, descriptor: descriptor, faces: [{ image: faceImage, box }] });
}
}
if (videoPlayer.currentTime < videoPlayer.duration) {
videoPlayer.currentTime = Math.min(videoPlayer.currentTime + 1, videoPlayer.duration);
} else {
videoPlayer.pause();
finalizeProcessing(detectedPeople);
}
};
videoPlayer.currentTime = 0;
}
function finalizeProcessing(people) {
statusContainer.classList.add('hidden');
resultsContainer.classList.remove('hidden');
if (people.length === 0) {
resultsGrid.innerHTML = `<p class="text-center text-gray-400 col-span-full">No faces were detected in this video.</p>`;
return;
}
resultsGrid.innerHTML = '';
people.forEach(person => {
const mainFace = person.faces.reduce((a, b) => (a.box.width > b.box.width ? a : b));
const personCard = document.createElement('div');
personCard.className = 'bg-gray-700/50 rounded-lg p-4 flex flex-col items-center';
personCard.innerHTML = `<h3 class="text-xl font-bold mb-3 text-white">Person #${person.id}</h3><img src="${mainFace.image}" alt="Person ${person.id}" class="w-32 h-32 rounded-full object-cover border-4 border-blue-500 mb-4"><p class="text-sm text-gray-400 mb-3">${person.faces.length} appearances found</p><div class="grid grid-cols-4 sm:grid-cols-5 gap-2 w-full">${person.faces.map(face => `<img src="${face.image}" class="w-full h-auto rounded-md object-cover aspect-square">`).join('')}</div>`;
resultsGrid.appendChild(personCard);
});
}
resetButton.addEventListener('click', () => {
resultsContainer.classList.add('hidden');
mainContent.classList.remove('hidden');
resultsGrid.innerHTML = '';
fileNameDisplay.textContent = 'No file selected.';
videoUpload.value = '';
progressBar.style.width = '0%';
if(videoPlayer.src) { URL.revokeObjectURL(videoPlayer.src); videoPlayer.src = ''; }
});
</script>
</body>
</html>