StillWorking commited on
Commit
95f0899
Β·
verified Β·
1 Parent(s): 947c5b0

Upload frontend/src/routes/index.tsx with huggingface_hub

Browse files
Files changed (1) hide show
  1. frontend/src/routes/index.tsx +1475 -0
frontend/src/routes/index.tsx ADDED
@@ -0,0 +1,1475 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import { createFileRoute } from "@tanstack/react-router";
2
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
+ import { motion, AnimatePresence } from "motion/react";
4
+ import {
5
+ Activity,
6
+ AlertTriangle,
7
+ BrainCircuit,
8
+ CheckCircle2,
9
+ Cpu,
10
+ DollarSign,
11
+ Gauge,
12
+ ImageUp,
13
+ Loader2,
14
+ Radar,
15
+ ScanFace,
16
+ Search,
17
+ ShieldCheck,
18
+ Sparkles,
19
+ Timer,
20
+ Upload,
21
+ X,
22
+ Zap,
23
+ } from "lucide-react";
24
+ import {
25
+ Bar,
26
+ BarChart,
27
+ CartesianGrid,
28
+ Line,
29
+ LineChart,
30
+ ResponsiveContainer,
31
+ Tooltip,
32
+ XAxis,
33
+ YAxis,
34
+ } from "recharts";
35
+ import { Button } from "@/components/ui/button";
36
+ import { Input } from "@/components/ui/input";
37
+ import { Badge } from "@/components/ui/badge";
38
+ import {
39
+ analyzeFrame,
40
+ semanticSearch,
41
+ ApiError,
42
+ getHealth,
43
+ imageUrl,
44
+ type AnalyzeFrameResponse,
45
+ type HealthResponse,
46
+ type SemanticSearchResponse,
47
+ } from "@/lib/api";
48
+
49
+ // Import face images from assets
50
+ import face1 from "@/assets/face-1.jpg";
51
+ import face2 from "@/assets/face-2.jpg";
52
+ import face3 from "@/assets/face-3.jpg";
53
+ import face4 from "@/assets/face-4.jpg";
54
+
55
+ export const Route = createFileRoute("/")({
56
+ component: Dashboard,
57
+ });
58
+
59
+ // ─── Static placeholder assets (generated inline so missing files never crash) ─
60
+
61
+ /** A neutral 1Γ—1 dark SVG used wherever a real image is unavailable. */
62
+ const PLACEHOLDER_SVG =
63
+ "data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400' " +
64
+ "viewBox='0 0 400 400'%3E%3Crect width='400' height='400' fill='%230d1117'/%3E" +
65
+ "%3Ccircle cx='200' cy='155' r='60' fill='%231e2d3d'/%3E" +
66
+ "%3Cellipse cx='200' cy='310' rx='100' ry='70' fill='%231e2d3d'/%3E%3C/svg%3E";
67
+
68
+ // Decorative imagery only β€” never presented as a real database match.
69
+ const FACE_PLACEHOLDERS = [face2, face3, face4, face1];
70
+
71
+ const SUGGESTIONS = [
72
+ "young male with wavy hair and eyeglasses",
73
+ "older person with gray hair and a goatee",
74
+ "smiling woman with blond hair",
75
+ "man with a mustache wearing a necktie",
76
+ ];
77
+
78
+ // ─── Live telemetry shapes (filled from real API responses) ──────────────────
79
+
80
+ interface TelemetryPoint {
81
+ t: string;
82
+ ms: number;
83
+ cost: number;
84
+ }
85
+
86
+ interface AttributeCount {
87
+ name: string;
88
+ v: number;
89
+ }
90
+
91
+ // ─── Analyse result shape (normalised from AnalyzeFrameResponse) ──────────────
92
+
93
+ interface AnalysisResult {
94
+ confidence: number;
95
+ attributes: string[];
96
+ report: string;
97
+ latency: number;
98
+ cost: number;
99
+ facesDetected: number;
100
+ status: string;
101
+ }
102
+
103
+ // ─── Search result shape (normalised from SemanticSearchResponse) ─────────────
104
+
105
+ interface SearchResult {
106
+ id: string;
107
+ src: string;
108
+ tag: string;
109
+ attributes: string[];
110
+ }
111
+
112
+ // ─── Progress ticker ─────────────────────────────────────────────────────────
113
+
114
+ function useProgressTicker() {
115
+ const [progress, setProgress] = useState(0);
116
+ const ivRef = useRef<ReturnType<typeof setInterval> | null>(null);
117
+
118
+ const stop = useCallback(() => {
119
+ if (ivRef.current) {
120
+ clearInterval(ivRef.current);
121
+ ivRef.current = null;
122
+ }
123
+ }, []);
124
+
125
+ // Never leave an interval running after the component unmounts.
126
+ useEffect(() => stop, [stop]);
127
+
128
+ const start = useCallback(() => {
129
+ stop();
130
+ setProgress(0);
131
+ ivRef.current = setInterval(() => {
132
+ setProgress((p) => {
133
+ // Asymptotically approaches 90 while waiting for the real response
134
+ if (p >= 90) return p;
135
+ return p + Math.max(1, (90 - p) * 0.08);
136
+ });
137
+ }, 80);
138
+ }, [stop]);
139
+
140
+ const finish = useCallback(() => {
141
+ stop();
142
+ setProgress(100);
143
+ }, [stop]);
144
+
145
+ const reset = useCallback(() => {
146
+ stop();
147
+ setProgress(0);
148
+ }, [stop]);
149
+
150
+ return { progress, start, finish, reset };
151
+ }
152
+
153
+ // ─── Dashboard ────────────────────────────────────────────────────────────────
154
+
155
+ function Dashboard() {
156
+ const [file, setFile] = useState<File | null>(null);
157
+ const [preview, setPreview] = useState<string | null>(null);
158
+ const [analyzing, setAnalyzing] = useState(false);
159
+ const {
160
+ progress,
161
+ start: startProgress,
162
+ finish: finishProgress,
163
+ reset: resetProgress,
164
+ } = useProgressTicker();
165
+ const [result, setResult] = useState<AnalysisResult | null>(null);
166
+ const [analyzeError, setAnalyzeError] = useState<string | null>(null);
167
+
168
+ const [query, setQuery] = useState("");
169
+ const [searching, setSearching] = useState(false);
170
+ const [searchResults, setSearchResults] = useState<SearchResult[]>([]);
171
+ const [extractedAttrs, setExtractedAttrs] = useState<string[]>([]);
172
+ const [excludedAttrs, setExcludedAttrs] = useState<string[]>([]);
173
+ const [searchMeta, setSearchMeta] = useState<{
174
+ latency: number;
175
+ cost: number;
176
+ } | null>(null);
177
+ const [searchError, setSearchError] = useState<string | null>(null);
178
+ const [searchStatus, setSearchStatus] = useState<string | null>(null);
179
+
180
+ const [dragOver, setDragOver] = useState(false);
181
+ const fileRef = useRef<HTMLInputElement>(null);
182
+
183
+ const [health, setHealth] = useState<HealthResponse | null>(null);
184
+ const [healthError, setHealthError] = useState(false);
185
+ const [telemetry, setTelemetry] = useState<TelemetryPoint[]>([]);
186
+
187
+ // Poll the real backend health endpoint instead of showing a hard-coded
188
+ // "SYSTEM ONLINE" badge.
189
+ useEffect(() => {
190
+ let cancelled = false;
191
+
192
+ const check = async () => {
193
+ try {
194
+ const next = await getHealth();
195
+ if (!cancelled) {
196
+ setHealth(next);
197
+ setHealthError(false);
198
+ }
199
+ } catch {
200
+ if (!cancelled) {
201
+ setHealth(null);
202
+ setHealthError(true);
203
+ }
204
+ }
205
+ };
206
+
207
+ void check();
208
+ const id = setInterval(check, 15_000);
209
+ return () => {
210
+ cancelled = true;
211
+ clearInterval(id);
212
+ };
213
+ }, []);
214
+
215
+ // Release the object URL when the preview changes or the page unmounts.
216
+ useEffect(() => {
217
+ return () => {
218
+ if (preview) URL.revokeObjectURL(preview);
219
+ };
220
+ }, [preview]);
221
+
222
+ const recordTelemetry = useCallback((latencyMs: number, costUsd: number) => {
223
+ if (!Number.isFinite(latencyMs) || latencyMs <= 0) return;
224
+ setTelemetry((prev) => {
225
+ const point: TelemetryPoint = {
226
+ t: new Date().toLocaleTimeString([], {
227
+ hour: "2-digit",
228
+ minute: "2-digit",
229
+ second: "2-digit",
230
+ }),
231
+ ms: Math.round(latencyMs),
232
+ cost: costUsd,
233
+ };
234
+ return [...prev, point].slice(-20);
235
+ });
236
+ }, []);
237
+
238
+ const backendOnline = health?.status === "ok";
239
+ const statusLabel = backendOnline
240
+ ? "SYSTEM ONLINE"
241
+ : healthError
242
+ ? "SYSTEM OFFLINE"
243
+ : "CONNECTING…";
244
+
245
+ const indexedLabel =
246
+ health?.index_vectors != null ? health.index_vectors.toLocaleString() : "β€”";
247
+ const indexedShort =
248
+ health?.index_vectors != null
249
+ ? health.index_vectors >= 1000
250
+ ? `${Math.round(health.index_vectors / 1000)}k`
251
+ : String(health.index_vectors)
252
+ : "β€”";
253
+
254
+ const avgLatency = useMemo(() => {
255
+ if (telemetry.length === 0) return null;
256
+ return Math.round(
257
+ telemetry.reduce((sum, point) => sum + point.ms, 0) / telemetry.length,
258
+ );
259
+ }, [telemetry]);
260
+
261
+ // Attribute distribution derived from the current result and search results.
262
+ const attrDist = useMemo<AttributeCount[]>(() => {
263
+ const counts = new Map<string, number>();
264
+ const add = (attrs: string[]) => {
265
+ for (const attr of attrs) {
266
+ counts.set(attr, (counts.get(attr) ?? 0) + 1);
267
+ }
268
+ };
269
+ if (result) add(result.attributes);
270
+ for (const r of searchResults) add(r.attributes);
271
+
272
+ return Array.from(counts.entries())
273
+ .sort((a, b) => b[1] - a[1])
274
+ .slice(0, 6)
275
+ .map(([name, v]) => ({ name: name.replace(/_/g, " "), v }));
276
+ }, [result, searchResults]);
277
+
278
+ const onFile = useCallback(
279
+ (f: File | undefined | null) => {
280
+ if (!f) return;
281
+ if (!f.type.startsWith("image/")) return;
282
+ setFile(f);
283
+ setPreview(URL.createObjectURL(f));
284
+ setResult(null);
285
+ setAnalyzeError(null);
286
+ resetProgress();
287
+ },
288
+ [resetProgress],
289
+ );
290
+
291
+ // ── Analyze: POST /api/v1/analyze-frame ────────────────────────────────────
292
+ const analyze = useCallback(async () => {
293
+ if (!file) return;
294
+ setAnalyzing(true);
295
+ setResult(null);
296
+ setAnalyzeError(null);
297
+ startProgress();
298
+
299
+ try {
300
+ const data: AnalyzeFrameResponse = await analyzeFrame(file);
301
+ finishProgress();
302
+ recordTelemetry(
303
+ data.cascadeflow_metrics?.latency_ms ?? 0,
304
+ data.cascadeflow_metrics?.cost_usd ?? 0,
305
+ );
306
+
307
+ const confidence = data.match_confidence ?? 0;
308
+ const latency = data.cascadeflow_metrics?.latency_ms ?? 0;
309
+ const cost = data.cascadeflow_metrics?.cost_usd ?? 0;
310
+
311
+ let report = data.agent_report ?? "";
312
+ if (data.status === "no_face_detected") {
313
+ report =
314
+ "No face detected in the uploaded image. Please try a clearer, front-facing photo.";
315
+ } else if (data.status === "no_match_found") {
316
+ report =
317
+ data.agent_report ?? "No matching record found in the database.";
318
+ }
319
+
320
+ setResult({
321
+ confidence,
322
+ attributes: data.matched_attributes,
323
+ report,
324
+ latency: Math.round(latency),
325
+ cost,
326
+ facesDetected: data.faces_detected,
327
+ status: data.status,
328
+ });
329
+ } catch (err) {
330
+ finishProgress();
331
+ if (err instanceof ApiError) {
332
+ if (err.kind === "connection") {
333
+ setAnalyzeError(
334
+ "🚨 Connection Refused: Is the FastAPI backend running on port 8000?",
335
+ );
336
+ } else if (err.kind === "timeout") {
337
+ setAnalyzeError(
338
+ "⏳ Request Timed Out: The GPU or Gemini API took too long to respond.",
339
+ );
340
+ } else if (err.kind === "http" && err.httpStatus === 422) {
341
+ setAnalyzeError(
342
+ "⚠️ Unprocessable Entity (422): The server could not parse the image upload.",
343
+ );
344
+ } else {
345
+ setAnalyzeError(`⚠️ ${err.message}`);
346
+ }
347
+ } else {
348
+ setAnalyzeError(`⚠️ An unexpected error occurred: ${String(err)}`);
349
+ }
350
+ } finally {
351
+ setAnalyzing(false);
352
+ }
353
+ }, [file, startProgress, finishProgress, recordTelemetry]);
354
+
355
+ // ── Semantic search: POST /api/v1/semantic-search ─────────────────────────
356
+ const runSearch = useCallback(async () => {
357
+ if (!query.trim()) return;
358
+ setSearching(true);
359
+ setSearchResults([]);
360
+ setExtractedAttrs([]);
361
+ setExcludedAttrs([]);
362
+ setSearchMeta(null);
363
+ setSearchError(null);
364
+ setSearchStatus(null);
365
+
366
+ try {
367
+ const data: SemanticSearchResponse = await semanticSearch(
368
+ query.trim(),
369
+ 12,
370
+ );
371
+ setExtractedAttrs(data.extracted_attrs);
372
+ setExcludedAttrs(data.excluded_attrs ?? []);
373
+ setSearchStatus(data.status);
374
+ const latency = Math.round(data.cascadeflow_metrics?.latency_ms ?? 0);
375
+ const cost = data.cascadeflow_metrics?.cost_usd ?? 0;
376
+ setSearchMeta({ latency, cost });
377
+ recordTelemetry(latency, cost);
378
+
379
+ // Always show the real CelebA image served by the backend. Stock
380
+ // photos are never substituted for database matches.
381
+ setSearchResults(
382
+ data.matches.map((m) => ({
383
+ id: m.image_id.replace(/\D/g, "").slice(-6) || m.faiss_id.toString(),
384
+ src: imageUrl(m.image_id),
385
+ tag: `FAISS #${m.faiss_id}`,
386
+ attributes: m.attributes,
387
+ })),
388
+ );
389
+ } catch (err) {
390
+ if (err instanceof ApiError) {
391
+ if (err.kind === "connection") {
392
+ setSearchError(
393
+ "🚨 Connection Refused: Is the FastAPI backend running on port 8000?",
394
+ );
395
+ } else if (err.kind === "timeout") {
396
+ setSearchError(
397
+ "⏳ Request Timed Out: Gemini attribute extraction took too long.",
398
+ );
399
+ } else {
400
+ setSearchError(`⚠️ ${err.message}`);
401
+ }
402
+ } else {
403
+ setSearchError(`⚠️ An unexpected error occurred: ${String(err)}`);
404
+ }
405
+ } finally {
406
+ setSearching(false);
407
+ }
408
+ }, [query, recordTelemetry]);
409
+
410
+ const confidencePct = result ? Math.round(result.confidence * 100) : 0;
411
+ const isMatchSuccess = result?.status === "success";
412
+ const isNoFace = result?.status === "no_face_detected";
413
+ const isNoMatch = result?.status === "no_match_found";
414
+ const featuredResult = searchResults[0] ?? null;
415
+ const galleryRest = searchResults.slice(1, 5);
416
+
417
+ return (
418
+ <div className="min-h-screen bg-background text-foreground">
419
+ {/* NAV */}
420
+ <header className="sticky top-0 z-40 border-b border-border/40 bg-background/70 backdrop-blur-xl">
421
+ <div className="mx-auto flex max-w-7xl items-center justify-between px-6 py-4">
422
+ <div className="flex items-center gap-3">
423
+ <div className="relative flex h-9 w-9 items-center justify-center rounded-lg bg-gradient-to-br from-primary to-primary/40 text-primary-foreground">
424
+ <Radar className="h-5 w-5" />
425
+ <span className="absolute -right-0.5 -top-0.5 h-2 w-2 rounded-full bg-[var(--success-glow)] pulse-dot" />
426
+ </div>
427
+ <div>
428
+ <p className="text-sm font-semibold tracking-wide">SENTINEL-AI</p>
429
+ <p className="text-[10px] uppercase tracking-[0.2em] text-muted-foreground">
430
+ Face Intelligence Console
431
+ </p>
432
+ </div>
433
+ </div>
434
+ <nav className="hidden items-center gap-8 text-sm text-muted-foreground md:flex">
435
+ <a href="#analyze" className="hover:text-foreground">
436
+ Analyze
437
+ </a>
438
+ <a href="#search" className="hover:text-foreground">
439
+ Semantic Search
440
+ </a>
441
+ <a href="#intel" className="hover:text-foreground">
442
+ Intelligence
443
+ </a>
444
+ <a href="#gallery" className="hover:text-foreground">
445
+ Gallery
446
+ </a>
447
+ </nav>
448
+ <div className="flex items-center gap-2 rounded-full border border-border/60 bg-surface-1/60 px-3 py-1.5 text-xs">
449
+ <span
450
+ className={`h-1.5 w-1.5 rounded-full ${
451
+ backendOnline
452
+ ? "bg-[var(--success-glow)] pulse-dot"
453
+ : healthError
454
+ ? "bg-[var(--danger-glow)]"
455
+ : "bg-[var(--amber-glow)]"
456
+ }`}
457
+ />
458
+ <span className="font-mono">{statusLabel}</span>
459
+ </div>
460
+ </div>
461
+ </header>
462
+
463
+ {/* HERO */}
464
+ <section className="relative overflow-hidden border-b border-border/40">
465
+ <div
466
+ className="absolute inset-0"
467
+ style={{ background: "var(--gradient-hero)" }}
468
+ aria-hidden
469
+ />
470
+ <div className="absolute inset-0 grid-bg opacity-60" aria-hidden />
471
+
472
+ <div className="relative mx-auto grid max-w-7xl gap-10 px-6 py-20 lg:grid-cols-[1.15fr_1fr] lg:py-28">
473
+ <div>
474
+ <motion.div
475
+ initial={{ opacity: 0, y: 12 }}
476
+ animate={{ opacity: 1, y: 0 }}
477
+ transition={{ duration: 0.6 }}
478
+ className="mb-6 inline-flex items-center gap-2 rounded-full border border-primary/30 bg-primary/10 px-3 py-1 text-xs font-medium text-primary"
479
+ >
480
+ <Sparkles className="h-3.5 w-3.5" />
481
+ Edge-cloud hybrid Β· FAISS + Gemini
482
+ </motion.div>
483
+ <motion.h1
484
+ initial={{ opacity: 0, y: 14 }}
485
+ animate={{ opacity: 1, y: 0 }}
486
+ transition={{ duration: 0.7, delay: 0.05 }}
487
+ className="text-5xl font-semibold leading-[1.05] tracking-tight md:text-6xl lg:text-7xl"
488
+ >
489
+ Security intelligence <br />
490
+ from a <span className="text-gradient-cyan">single image.</span>
491
+ </motion.h1>
492
+ <motion.p
493
+ initial={{ opacity: 0, y: 14 }}
494
+ animate={{ opacity: 1, y: 0 }}
495
+ transition={{ duration: 0.7, delay: 0.15 }}
496
+ className="mt-6 max-w-xl text-base leading-relaxed text-muted-foreground md:text-lg"
497
+ >
498
+ Upload a face, explore semantic attributes in plain English, and
499
+ receive a professional AI-generated assessment β€” with latency and
500
+ cost telemetry on every call.
501
+ </motion.p>
502
+ <motion.div
503
+ initial={{ opacity: 0, y: 14 }}
504
+ animate={{ opacity: 1, y: 0 }}
505
+ transition={{ duration: 0.7, delay: 0.25 }}
506
+ className="mt-8 flex flex-wrap gap-3"
507
+ >
508
+ <Button
509
+ size="lg"
510
+ className="h-12 gap-2 bg-primary px-6 text-primary-foreground shadow-[var(--shadow-glow-cyan)] hover:bg-primary/90"
511
+ onClick={() =>
512
+ document
513
+ .getElementById("analyze")
514
+ ?.scrollIntoView({ behavior: "smooth" })
515
+ }
516
+ >
517
+ <ScanFace className="h-4 w-4" /> Analyze Image
518
+ </Button>
519
+ <Button
520
+ size="lg"
521
+ variant="outline"
522
+ className="h-12 gap-2 border-border/60 bg-surface-1/60 px-6 backdrop-blur hover:bg-surface-2"
523
+ onClick={() =>
524
+ document
525
+ .getElementById("search")
526
+ ?.scrollIntoView({ behavior: "smooth" })
527
+ }
528
+ >
529
+ <Search className="h-4 w-4" /> Run Semantic Search
530
+ </Button>
531
+ </motion.div>
532
+
533
+ <div className="mt-10 grid max-w-lg grid-cols-3 gap-3 text-sm">
534
+ {[
535
+ { k: "Faces indexed", v: indexedShort, i: BrainCircuit },
536
+ {
537
+ k: "Avg latency",
538
+ v: avgLatency != null ? `${avgLatency}ms` : "β€”",
539
+ i: Timer,
540
+ },
541
+ {
542
+ k: "Detector",
543
+ v: health?.detector_ready ? "MTCNN" : "β€”",
544
+ i: ShieldCheck,
545
+ },
546
+ ].map((s) => (
547
+ <div key={s.k} className="glass-card px-4 py-3">
548
+ <s.i className="h-4 w-4 text-primary" />
549
+ <p className="mt-2 font-mono text-lg font-semibold">{s.v}</p>
550
+ <p className="text-[11px] uppercase tracking-wider text-muted-foreground">
551
+ {s.k}
552
+ </p>
553
+ </div>
554
+ ))}
555
+ </div>
556
+ </div>
557
+
558
+ {/* Hero visual collage */}
559
+ <div className="relative hidden lg:block">
560
+ <motion.div
561
+ className="absolute right-0 top-0 h-64 w-52 overflow-hidden rounded-2xl glass-card glow-border float-slow"
562
+ style={{ animationDelay: "0s" }}
563
+ >
564
+ <img
565
+ src={FACE_PLACEHOLDERS[0]}
566
+ alt=""
567
+ className="h-full w-full object-cover opacity-90"
568
+ />
569
+ <div className="absolute inset-0 scan-line" />
570
+ <div className="absolute bottom-3 left-3 rounded-md bg-background/70 px-2 py-1 font-mono text-[10px] backdrop-blur">
571
+ Sample imagery
572
+ </div>
573
+ </motion.div>
574
+ <motion.div
575
+ className="absolute right-56 top-24 h-56 w-44 overflow-hidden rounded-2xl glass-card glow-border float-slow"
576
+ style={{ animationDelay: "1.2s" }}
577
+ >
578
+ <img
579
+ src={FACE_PLACEHOLDERS[1]}
580
+ alt=""
581
+ className="h-full w-full object-cover opacity-90"
582
+ />
583
+ <div className="absolute inset-0 scan-line" />
584
+ <div className="absolute bottom-3 left-3 rounded-md bg-background/70 px-2 py-1 font-mono text-[10px] backdrop-blur">
585
+ Sample imagery
586
+ </div>
587
+ </motion.div>
588
+ <motion.div
589
+ className="absolute right-16 top-72 h-52 w-48 overflow-hidden rounded-2xl glass-card glow-border float-slow"
590
+ style={{ animationDelay: "2.4s" }}
591
+ >
592
+ <img
593
+ src={FACE_PLACEHOLDERS[3]}
594
+ alt=""
595
+ className="h-full w-full object-cover opacity-90"
596
+ />
597
+ <div className="absolute inset-0 scan-line" />
598
+ <div className="absolute bottom-3 left-3 rounded-md bg-background/70 px-2 py-1 font-mono text-[10px] backdrop-blur">
599
+ Sample imagery
600
+ </div>
601
+ </motion.div>
602
+ <div className="absolute -bottom-4 right-4 flex items-center gap-2 rounded-full glass-card px-4 py-2 text-xs">
603
+ <Activity className="h-3.5 w-3.5 text-[var(--success-glow)]" />{" "}
604
+ {health?.index_ready
605
+ ? `FAISS index ready Β· ${indexedLabel} vectors`
606
+ : "FAISS index unavailable"}
607
+ </div>
608
+ </div>
609
+ </div>
610
+ </section>
611
+
612
+ <main className="mx-auto max-w-7xl px-6 py-16">
613
+ {/* Status strip */}
614
+ <section
615
+ aria-label="System status"
616
+ className="mb-16 grid gap-4 md:grid-cols-4"
617
+ >
618
+ <StatCard
619
+ i={ShieldCheck}
620
+ label="API Health"
621
+ value={
622
+ backendOnline
623
+ ? "Operational"
624
+ : healthError
625
+ ? "Offline"
626
+ : "Connecting"
627
+ }
628
+ tone={backendOnline ? "success" : healthError ? "danger" : "amber"}
629
+ />
630
+ <StatCard
631
+ i={Cpu}
632
+ label="Embedder"
633
+ value={health?.embedder_ready ? "AdaFace IR-50" : "Loading…"}
634
+ tone={health?.embedder_ready ? "cyan" : "amber"}
635
+ />
636
+ <StatCard
637
+ i={BrainCircuit}
638
+ label="FAISS Index"
639
+ value={
640
+ health?.index_ready ? `Ready Β· ${indexedShort}` : "Unavailable"
641
+ }
642
+ tone={health?.index_ready ? "cyan" : "danger"}
643
+ />
644
+ <StatCard
645
+ i={Zap}
646
+ label="LLM gateway"
647
+ value={health?.model ?? "Gemini"}
648
+ tone="amber"
649
+ />
650
+ </section>
651
+
652
+ {/* ANALYZE + INTELLIGENCE */}
653
+ <section
654
+ id="analyze"
655
+ className="mb-20 grid gap-6 lg:grid-cols-[1.05fr_1fr]"
656
+ >
657
+ <div className="glass-card glow-border relative overflow-hidden p-6">
658
+ <div className="mb-5 flex items-center justify-between">
659
+ <div>
660
+ <p className="text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
661
+ Step 01
662
+ </p>
663
+ <h2 className="mt-1 text-2xl font-semibold">
664
+ Upload &amp; Analyze
665
+ </h2>
666
+ </div>
667
+ <Badge
668
+ variant="outline"
669
+ className="border-primary/40 bg-primary/10 text-primary"
670
+ >
671
+ POST /api/v1/analyze-frame
672
+ </Badge>
673
+ </div>
674
+
675
+ <label
676
+ onDragOver={(e) => {
677
+ e.preventDefault();
678
+ setDragOver(true);
679
+ }}
680
+ onDragLeave={() => setDragOver(false)}
681
+ onDrop={(e) => {
682
+ e.preventDefault();
683
+ setDragOver(false);
684
+ onFile(e.dataTransfer.files?.[0]);
685
+ }}
686
+ className={`relative flex min-h-[280px] cursor-pointer flex-col items-center justify-center overflow-hidden rounded-xl border-2 border-dashed transition-all ${
687
+ dragOver
688
+ ? "border-primary bg-primary/5"
689
+ : "border-border/70 bg-surface-1/40 hover:border-primary/50"
690
+ }`}
691
+ >
692
+ <input
693
+ ref={fileRef}
694
+ type="file"
695
+ accept="image/*"
696
+ className="hidden"
697
+ onChange={(e) => onFile(e.target.files?.[0])}
698
+ />
699
+ {preview ? (
700
+ <div className="relative w-full">
701
+ <img
702
+ src={preview}
703
+ alt="preview"
704
+ className="mx-auto max-h-[360px] w-full rounded-lg object-contain"
705
+ />
706
+ {analyzing && (
707
+ <div
708
+ className="absolute inset-0 scan-line rounded-lg"
709
+ aria-hidden
710
+ />
711
+ )}
712
+ <button
713
+ type="button"
714
+ onClick={(e) => {
715
+ e.preventDefault();
716
+ setFile(null);
717
+ setPreview(null);
718
+ setResult(null);
719
+ setAnalyzeError(null);
720
+ resetProgress();
721
+ }}
722
+ className="absolute right-3 top-3 rounded-full bg-background/80 p-1.5 backdrop-blur hover:bg-background"
723
+ aria-label="Remove image"
724
+ >
725
+ <X className="h-3.5 w-3.5" />
726
+ </button>
727
+ </div>
728
+ ) : (
729
+ <div className="flex flex-col items-center gap-3 px-6 py-10 text-center">
730
+ <div className="flex h-14 w-14 items-center justify-center rounded-full bg-primary/10 text-primary">
731
+ <ImageUp className="h-6 w-6" />
732
+ </div>
733
+ <div>
734
+ <p className="text-base font-medium">
735
+ Drop an image here, or click to browse
736
+ </p>
737
+ <p className="mt-1 text-sm text-muted-foreground">
738
+ JPG, PNG, or WEBP Β· up to 10MB
739
+ </p>
740
+ </div>
741
+ </div>
742
+ )}
743
+ </label>
744
+
745
+ <div className="mt-5 flex items-center gap-3">
746
+ <Button
747
+ onClick={() => fileRef.current?.click()}
748
+ variant="outline"
749
+ className="gap-2 border-border/60 bg-surface-1"
750
+ >
751
+ <Upload className="h-4 w-4" />{" "}
752
+ {file ? "Replace" : "Choose file"}
753
+ </Button>
754
+ <Button
755
+ onClick={() => void analyze()}
756
+ disabled={!file || analyzing}
757
+ className="gap-2 bg-primary text-primary-foreground shadow-[var(--shadow-glow-cyan)] hover:bg-primary/90 disabled:opacity-50"
758
+ >
759
+ {analyzing ? (
760
+ <Loader2 className="h-4 w-4 animate-spin" />
761
+ ) : (
762
+ <ScanFace className="h-4 w-4" />
763
+ )}
764
+ {analyzing ? "Analyzing…" : "Analyze"}
765
+ </Button>
766
+ {analyzing && (
767
+ <div className="flex-1">
768
+ <div className="h-1.5 overflow-hidden rounded-full bg-surface-2">
769
+ <div
770
+ className="h-full bg-primary transition-all duration-300"
771
+ style={{ width: `${progress}%` }}
772
+ />
773
+ </div>
774
+ </div>
775
+ )}
776
+ </div>
777
+
778
+ {/* Analyze error banner */}
779
+ {analyzeError && !analyzing && (
780
+ <motion.div
781
+ initial={{ opacity: 0, y: 6 }}
782
+ animate={{ opacity: 1, y: 0 }}
783
+ className="mt-4 flex items-start gap-3 rounded-xl border border-[var(--danger-glow)]/30 bg-[var(--danger-glow)]/10 p-4 text-sm text-[var(--danger-glow)]"
784
+ >
785
+ <AlertTriangle className="mt-0.5 h-4 w-4 shrink-0" />
786
+ <span>{analyzeError}</span>
787
+ </motion.div>
788
+ )}
789
+ </div>
790
+
791
+ {/* Intelligence panel */}
792
+ <div
793
+ id="intel"
794
+ className="glass-card glow-border relative overflow-hidden p-6"
795
+ >
796
+ <div className="mb-5 flex items-center justify-between">
797
+ <div>
798
+ <p className="text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
799
+ Step 02
800
+ </p>
801
+ <h2 className="mt-1 text-2xl font-semibold">
802
+ Result Intelligence
803
+ </h2>
804
+ </div>
805
+ {result && isMatchSuccess ? (
806
+ <Badge className="gap-1 border-[var(--success-glow)]/40 bg-[var(--success-glow)]/10 text-[var(--success-glow)]">
807
+ <CheckCircle2 className="h-3 w-3" /> Match found
808
+ </Badge>
809
+ ) : result && (isNoFace || isNoMatch) ? (
810
+ <Badge
811
+ variant="outline"
812
+ className="border-[var(--amber-glow)]/40 text-[var(--amber-glow)]"
813
+ >
814
+ <AlertTriangle className="mr-1 h-3 w-3" />
815
+ {isNoFace ? "No face" : "No match"}
816
+ </Badge>
817
+ ) : (
818
+ <Badge
819
+ variant="outline"
820
+ className="border-border/60 text-muted-foreground"
821
+ >
822
+ Awaiting analysis
823
+ </Badge>
824
+ )}
825
+ </div>
826
+
827
+ <AnimatePresence mode="wait">
828
+ {result ? (
829
+ <motion.div
830
+ key="result"
831
+ initial={{ opacity: 0, y: 8 }}
832
+ animate={{ opacity: 1, y: 0 }}
833
+ exit={{ opacity: 0 }}
834
+ className="space-y-5"
835
+ >
836
+ {isMatchSuccess && (
837
+ <div className="flex items-center gap-5">
838
+ <ConfidenceGauge value={confidencePct} />
839
+ <div className="flex-1">
840
+ <p className="text-[11px] uppercase tracking-widest text-muted-foreground">
841
+ Match confidence
842
+ </p>
843
+ <p className="mt-1 font-mono text-4xl font-semibold text-gradient-cyan">
844
+ {confidencePct}%
845
+ </p>
846
+ <p className="mt-1 text-xs text-muted-foreground">
847
+ {result.facesDetected} face
848
+ {result.facesDetected !== 1 ? "s" : ""} detected Β·
849
+ top-1 FAISS similarity
850
+ </p>
851
+ </div>
852
+ </div>
853
+ )}
854
+
855
+ {result.attributes.length > 0 && (
856
+ <div>
857
+ <p className="mb-2 text-[11px] uppercase tracking-widest text-muted-foreground">
858
+ Detected attributes
859
+ </p>
860
+ <div className="flex flex-wrap gap-2">
861
+ {result.attributes.map((a) => (
862
+ <span
863
+ key={a}
864
+ className="rounded-full border border-primary/30 bg-primary/10 px-3 py-1 text-xs font-medium text-primary"
865
+ >
866
+ {a}
867
+ </span>
868
+ ))}
869
+ </div>
870
+ </div>
871
+ )}
872
+
873
+ <div className="rounded-xl border border-primary/20 bg-gradient-to-br from-primary/10 to-transparent p-4">
874
+ <div className="mb-2 flex items-center gap-2 text-xs font-semibold uppercase tracking-widest text-primary">
875
+ <BrainCircuit className="h-3.5 w-3.5" /> Gemini agent
876
+ report
877
+ </div>
878
+ <p className="text-sm leading-relaxed text-foreground/90">
879
+ {result.report}
880
+ </p>
881
+ </div>
882
+
883
+ <div className="grid grid-cols-2 gap-3">
884
+ <MetricPill
885
+ i={Timer}
886
+ label="Latency"
887
+ value={result.latency > 0 ? `${result.latency} ms` : "β€”"}
888
+ />
889
+ <MetricPill
890
+ i={DollarSign}
891
+ label="Est. cost"
892
+ value={
893
+ result.cost > 0 ? `$${result.cost.toFixed(6)}` : "β€”"
894
+ }
895
+ />
896
+ </div>
897
+ </motion.div>
898
+ ) : (
899
+ <motion.div
900
+ key="empty"
901
+ initial={{ opacity: 0 }}
902
+ animate={{ opacity: 1 }}
903
+ className="flex min-h-[360px] flex-col items-center justify-center rounded-xl border border-dashed border-border/60 bg-surface-1/30 text-center"
904
+ >
905
+ <div className="mb-3 flex h-12 w-12 items-center justify-center rounded-full bg-surface-2 text-muted-foreground">
906
+ <Radar className="h-5 w-5" />
907
+ </div>
908
+ <p className="text-sm font-medium">No analysis yet</p>
909
+ <p className="mt-1 max-w-xs text-xs text-muted-foreground">
910
+ Upload a face image and press Analyze to receive confidence,
911
+ attributes, and a Gemini-generated report.
912
+ </p>
913
+ </motion.div>
914
+ )}
915
+ </AnimatePresence>
916
+ </div>
917
+ </section>
918
+
919
+ {/* SEMANTIC SEARCH */}
920
+ <section id="search" className="mb-20">
921
+ <div className="glass-card glow-border overflow-hidden p-6">
922
+ <div className="mb-6 flex flex-wrap items-end justify-between gap-3">
923
+ <div>
924
+ <p className="text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
925
+ Step 03
926
+ </p>
927
+ <h2 className="mt-1 text-2xl font-semibold">Semantic Search</h2>
928
+ <p className="mt-1 text-sm text-muted-foreground">
929
+ Describe a face in plain English β€” Sentinel extracts
930
+ attributes and queries the FAISS index.
931
+ </p>
932
+ </div>
933
+ <Badge
934
+ variant="outline"
935
+ className="border-primary/40 bg-primary/10 text-primary"
936
+ >
937
+ POST /api/v1/semantic-search
938
+ </Badge>
939
+ </div>
940
+
941
+ <div className="flex flex-col gap-3 md:flex-row">
942
+ <div className="relative flex-1">
943
+ <Search className="pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground" />
944
+ <Input
945
+ value={query}
946
+ onChange={(e) => setQuery(e.target.value)}
947
+ onKeyDown={(e) => {
948
+ if (e.key === "Enter") void runSearch();
949
+ }}
950
+ placeholder="e.g. young male with wavy hair and eyeglasses"
951
+ aria-label="Describe a face in plain English"
952
+ className="h-12 border-border/60 bg-surface-1/60 pl-10 text-base"
953
+ />
954
+ </div>
955
+ <Button
956
+ onClick={() => void runSearch()}
957
+ disabled={!query || searching}
958
+ className="h-12 gap-2 bg-primary px-6 text-primary-foreground shadow-[var(--shadow-glow-cyan)] hover:bg-primary/90"
959
+ >
960
+ {searching ? (
961
+ <Loader2 className="h-4 w-4 animate-spin" />
962
+ ) : (
963
+ <Search className="h-4 w-4" />
964
+ )}
965
+ Search
966
+ </Button>
967
+ </div>
968
+
969
+ <div className="mt-4 flex flex-wrap gap-2">
970
+ {SUGGESTIONS.map((s) => (
971
+ <button
972
+ key={s}
973
+ onClick={() => setQuery(s)}
974
+ className="rounded-full border border-border/60 bg-surface-1/60 px-3 py-1 text-xs text-muted-foreground transition hover:border-primary/50 hover:text-foreground"
975
+ >
976
+ {s}
977
+ </button>
978
+ ))}
979
+ </div>
980
+
981
+ {/* Search error banner */}
982
+ {searchError && !searching && (
983
+ <motion.div
984
+ initial={{ opacity: 0, y: 6 }}
985
+ animate={{ opacity: 1, y: 0 }}
986
+ className="mt-4 flex items-start gap-3 rounded-xl border border-[var(--danger-glow)]/30 bg-[var(--danger-glow)]/10 p-4 text-sm text-[var(--danger-glow)]"
987
+ >
988
+ <AlertTriangle className="mt-0.5 h-4 w-4 shrink-0" />
989
+ <span>{searchError}</span>
990
+ </motion.div>
991
+ )}
992
+
993
+ {(extractedAttrs.length > 0 || excludedAttrs.length > 0) && (
994
+ <div className="mt-6 rounded-xl border border-primary/20 bg-primary/5 p-4">
995
+ <div className="mb-2 flex items-center justify-between">
996
+ <p className="text-[11px] uppercase tracking-widest text-primary">
997
+ Attribute filter
998
+ </p>
999
+ {searchMeta && (
1000
+ <div className="flex gap-3 text-[11px] text-muted-foreground font-mono">
1001
+ <span>{searchMeta.latency} ms</span>
1002
+ <span>${searchMeta.cost.toFixed(6)}</span>
1003
+ </div>
1004
+ )}
1005
+ </div>
1006
+ <div className="flex flex-wrap gap-2">
1007
+ {extractedAttrs.map((a) => (
1008
+ <span
1009
+ key={`require-${a}`}
1010
+ className="rounded-full bg-primary/15 px-3 py-1 text-xs font-medium text-primary"
1011
+ >
1012
+ {a}
1013
+ </span>
1014
+ ))}
1015
+ {excludedAttrs.map((a) => (
1016
+ <span
1017
+ key={`exclude-${a}`}
1018
+ className="rounded-full border border-border/60 bg-surface-1/60 px-3 py-1 text-xs font-medium text-muted-foreground line-through"
1019
+ title="Excluded from results"
1020
+ >
1021
+ not {a}
1022
+ </span>
1023
+ ))}
1024
+ </div>
1025
+ </div>
1026
+ )}
1027
+
1028
+ {searchResults.length > 0 && (
1029
+ <div className="mt-6">
1030
+ <p className="mb-3 text-xs text-muted-foreground">
1031
+ <span className="font-mono text-foreground">
1032
+ {searchResults.length}
1033
+ </span>{" "}
1034
+ matches from FAISS index
1035
+ </p>
1036
+ <div className="grid gap-4 sm:grid-cols-2 lg:grid-cols-4">
1037
+ {searchResults.map((r) => (
1038
+ <SearchResultCard key={r.id + r.tag} result={r} />
1039
+ ))}
1040
+ </div>
1041
+ </div>
1042
+ )}
1043
+
1044
+ {!searching &&
1045
+ !searchError &&
1046
+ searchResults.length === 0 &&
1047
+ searchStatus && (
1048
+ <p className="mt-6 text-center text-sm text-muted-foreground">
1049
+ {searchStatus === "no_attributes_extracted"
1050
+ ? "Could not extract any CelebA attributes from that description. Try naming visible traits such as glasses, blond hair, or smiling."
1051
+ : "No matches found in the FAISS index for these attributes."}
1052
+ </p>
1053
+ )}
1054
+ </div>
1055
+ </section>
1056
+
1057
+ {/* ANALYTICS */}
1058
+ <section className="mb-20 grid gap-6 lg:grid-cols-3">
1059
+ <div className="glass-card p-6 lg:col-span-2">
1060
+ <div className="mb-4 flex items-center justify-between">
1061
+ <div>
1062
+ <p className="text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
1063
+ Performance
1064
+ </p>
1065
+ <h3 className="text-lg font-semibold">
1066
+ Latency &amp; cost trend
1067
+ </h3>
1068
+ </div>
1069
+ <div className="flex gap-4 text-xs">
1070
+ <LegendDot color="var(--cyan-glow)" label="Latency (ms)" />
1071
+ <LegendDot color="var(--amber-glow)" label="Cost ($)" />
1072
+ </div>
1073
+ </div>
1074
+ <div className="h-64">
1075
+ {telemetry.length === 0 ? (
1076
+ <div className="flex h-full items-center justify-center rounded-lg border border-dashed border-border/60 text-sm text-muted-foreground">
1077
+ Run an analysis or semantic search to collect live telemetry.
1078
+ </div>
1079
+ ) : (
1080
+ <ResponsiveContainer width="100%" height="100%">
1081
+ <LineChart
1082
+ data={telemetry}
1083
+ margin={{ top: 10, right: 10, left: -10, bottom: 0 }}
1084
+ >
1085
+ <CartesianGrid
1086
+ stroke="oklch(0.32 0.035 252 / 0.4)"
1087
+ strokeDasharray="3 3"
1088
+ />
1089
+ <XAxis
1090
+ dataKey="t"
1091
+ stroke="oklch(0.72 0.02 240)"
1092
+ fontSize={11}
1093
+ tickLine={false}
1094
+ axisLine={false}
1095
+ />
1096
+ <YAxis
1097
+ yAxisId="latency"
1098
+ stroke="oklch(0.72 0.02 240)"
1099
+ fontSize={11}
1100
+ tickLine={false}
1101
+ axisLine={false}
1102
+ />
1103
+ <YAxis
1104
+ yAxisId="cost"
1105
+ orientation="right"
1106
+ stroke="oklch(0.80 0.17 75)"
1107
+ fontSize={11}
1108
+ tickLine={false}
1109
+ axisLine={false}
1110
+ tickFormatter={(value: number) => `$${value.toFixed(4)}`}
1111
+ />
1112
+ <Tooltip
1113
+ contentStyle={{
1114
+ background: "oklch(0.18 0.035 252)",
1115
+ border: "1px solid oklch(0.82 0.18 200 / 0.3)",
1116
+ borderRadius: 10,
1117
+ fontSize: 12,
1118
+ }}
1119
+ />
1120
+ <Line
1121
+ yAxisId="latency"
1122
+ type="monotone"
1123
+ dataKey="ms"
1124
+ stroke="oklch(0.82 0.18 200)"
1125
+ strokeWidth={2.5}
1126
+ dot={false}
1127
+ />
1128
+ <Line
1129
+ yAxisId="cost"
1130
+ type="monotone"
1131
+ dataKey="cost"
1132
+ stroke="oklch(0.80 0.17 75)"
1133
+ strokeWidth={2}
1134
+ strokeDasharray="4 4"
1135
+ dot={false}
1136
+ />
1137
+ </LineChart>
1138
+ </ResponsiveContainer>
1139
+ )}
1140
+ </div>
1141
+ </div>
1142
+
1143
+ <div className="glass-card p-6">
1144
+ <p className="text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
1145
+ Semantics
1146
+ </p>
1147
+ <h3 className="mb-4 text-lg font-semibold">
1148
+ Attribute distribution
1149
+ </h3>
1150
+ <div className="h-64">
1151
+ {attrDist.length === 0 ? (
1152
+ <div className="flex h-full items-center justify-center rounded-lg border border-dashed border-border/60 text-sm text-muted-foreground">
1153
+ Attributes from real matches will appear here.
1154
+ </div>
1155
+ ) : (
1156
+ <ResponsiveContainer width="100%" height="100%">
1157
+ <BarChart
1158
+ data={attrDist}
1159
+ layout="vertical"
1160
+ margin={{ left: 10, right: 10 }}
1161
+ >
1162
+ <CartesianGrid
1163
+ stroke="oklch(0.32 0.035 252 / 0.3)"
1164
+ strokeDasharray="3 3"
1165
+ horizontal={false}
1166
+ />
1167
+ <XAxis
1168
+ type="number"
1169
+ allowDecimals={false}
1170
+ stroke="oklch(0.72 0.02 240)"
1171
+ fontSize={11}
1172
+ tickLine={false}
1173
+ axisLine={false}
1174
+ />
1175
+ <YAxis
1176
+ type="category"
1177
+ dataKey="name"
1178
+ stroke="oklch(0.72 0.02 240)"
1179
+ fontSize={11}
1180
+ width={90}
1181
+ tickLine={false}
1182
+ axisLine={false}
1183
+ />
1184
+ <Tooltip
1185
+ contentStyle={{
1186
+ background: "oklch(0.18 0.035 252)",
1187
+ border: "1px solid oklch(0.82 0.18 200 / 0.3)",
1188
+ borderRadius: 10,
1189
+ fontSize: 12,
1190
+ }}
1191
+ />
1192
+ <Bar
1193
+ dataKey="v"
1194
+ fill="oklch(0.82 0.18 200)"
1195
+ radius={[0, 4, 4, 0]}
1196
+ />
1197
+ </BarChart>
1198
+ </ResponsiveContainer>
1199
+ )}
1200
+ </div>
1201
+ </div>
1202
+ </section>
1203
+
1204
+ {/* GALLERY */}
1205
+ <section id="gallery" className="mb-24">
1206
+ <div className="mb-6 flex items-end justify-between">
1207
+ <div>
1208
+ <p className="text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
1209
+ Explorer
1210
+ </p>
1211
+ <h2 className="text-2xl font-semibold">Match gallery</h2>
1212
+ <p className="mt-1 text-sm text-muted-foreground">
1213
+ {searchResults.length > 0
1214
+ ? `${searchResults.length} real matches from the most recent semantic search.`
1215
+ : "Real indexed faces appear here after a semantic search."}
1216
+ </p>
1217
+ </div>
1218
+ </div>
1219
+
1220
+ {featuredResult ? (
1221
+ <div className="grid gap-6 lg:grid-cols-[1.4fr_1fr]">
1222
+ <div className="glass-card glow-border relative overflow-hidden">
1223
+ <img
1224
+ src={featuredResult.src}
1225
+ alt={`Match ${featuredResult.id}`}
1226
+ className="h-[440px] w-full object-cover"
1227
+ loading="lazy"
1228
+ />
1229
+ <div className="absolute inset-0 bg-gradient-to-t from-black/80 via-black/20 to-transparent" />
1230
+ <div className="absolute bottom-0 left-0 right-0 p-6">
1231
+ <Badge className="mb-3 border-primary/40 bg-primary/20 text-primary">
1232
+ Top result
1233
+ </Badge>
1234
+ <h3 className="text-2xl font-semibold text-white">
1235
+ Reference ID {featuredResult.id}
1236
+ </h3>
1237
+ <p className="mt-1 max-w-md text-sm text-gray-200">
1238
+ {featuredResult.attributes.length > 0
1239
+ ? featuredResult.attributes.join(" Β· ")
1240
+ : "No positive attributes recorded for this subject."}
1241
+ </p>
1242
+ </div>
1243
+ </div>
1244
+ <div className="grid grid-cols-2 gap-4">
1245
+ {galleryRest.map((g) => (
1246
+ <div
1247
+ key={`${g.id}-${g.tag}`}
1248
+ className="group glass-card relative overflow-hidden"
1249
+ >
1250
+ <img
1251
+ src={g.src}
1252
+ alt={`Match ${g.id}`}
1253
+ className="h-44 w-full object-cover transition-transform duration-500 group-hover:scale-105"
1254
+ loading="lazy"
1255
+ />
1256
+ <div className="absolute inset-x-0 bottom-0 flex items-center justify-between bg-gradient-to-t from-background/95 to-transparent px-3 py-2 text-xs">
1257
+ <span className="font-mono text-muted-foreground">
1258
+ #{g.id}
1259
+ </span>
1260
+ <span className="font-medium text-primary">{g.tag}</span>
1261
+ </div>
1262
+ </div>
1263
+ ))}
1264
+ </div>
1265
+ </div>
1266
+ ) : (
1267
+ <div className="glass-card flex min-h-[220px] flex-col items-center justify-center gap-2 p-10 text-center">
1268
+ <Radar className="h-8 w-8 text-muted-foreground" />
1269
+ <p className="text-sm font-medium">No matches to display</p>
1270
+ <p className="max-w-md text-xs text-muted-foreground">
1271
+ Run a semantic search above. Results are served directly from
1272
+ the FAISS-indexed CelebA dataset β€” no stock photos are used.
1273
+ </p>
1274
+ </div>
1275
+ )}
1276
+ </section>
1277
+ </main>
1278
+
1279
+ <footer className="border-t border-border/40 bg-surface-1/40">
1280
+ <div className="mx-auto flex max-w-7xl flex-wrap items-center justify-between gap-4 px-6 py-8 text-xs text-muted-foreground">
1281
+ <div className="flex items-center gap-2">
1282
+ <Radar className="h-4 w-4 text-primary" />
1283
+ <span>Sentinel-AI Β· Hybrid edge-cloud face intelligence</span>
1284
+ </div>
1285
+ <div className="font-mono">
1286
+ v1.0.0 Β· cascadeflow gateway Β· Gemini agent
1287
+ </div>
1288
+ </div>
1289
+ </footer>
1290
+ </div>
1291
+ );
1292
+ }
1293
+
1294
+ // ─── Sub-components ───────────────────────────────────────────────────────────
1295
+
1296
+ function StatCard({
1297
+ i: Icon,
1298
+ label,
1299
+ value,
1300
+ tone,
1301
+ }: {
1302
+ i: React.ComponentType<{ className?: string }>;
1303
+ label: string;
1304
+ value: string;
1305
+ tone: "cyan" | "amber" | "success" | "danger";
1306
+ }) {
1307
+ const toneMap = {
1308
+ cyan: "text-primary bg-primary/10 border-primary/30",
1309
+ amber:
1310
+ "text-[var(--amber-glow)] bg-[var(--amber-glow)]/10 border-[var(--amber-glow)]/30",
1311
+ success:
1312
+ "text-[var(--success-glow)] bg-[var(--success-glow)]/10 border-[var(--success-glow)]/30",
1313
+ danger:
1314
+ "text-[var(--danger-glow)] bg-[var(--danger-glow)]/10 border-[var(--danger-glow)]/30",
1315
+ } as const;
1316
+ return (
1317
+ <div className="glass-card flex items-center gap-4 p-5">
1318
+ <div
1319
+ className={`flex h-11 w-11 items-center justify-center rounded-lg border ${toneMap[tone]}`}
1320
+ >
1321
+ <Icon className="h-5 w-5" />
1322
+ </div>
1323
+ <div>
1324
+ <p className="text-[11px] uppercase tracking-widest text-muted-foreground">
1325
+ {label}
1326
+ </p>
1327
+ <p className="mt-0.5 font-mono text-sm font-medium">{value}</p>
1328
+ </div>
1329
+ </div>
1330
+ );
1331
+ }
1332
+
1333
+ function MetricPill({
1334
+ i: Icon,
1335
+ label,
1336
+ value,
1337
+ }: {
1338
+ i: React.ComponentType<{ className?: string }>;
1339
+ label: string;
1340
+ value: string;
1341
+ }) {
1342
+ return (
1343
+ <div className="flex items-center gap-3 rounded-xl border border-border/60 bg-surface-1/60 p-3">
1344
+ <Icon className="h-4 w-4 text-primary" />
1345
+ <div>
1346
+ <p className="text-[10px] uppercase tracking-widest text-muted-foreground">
1347
+ {label}
1348
+ </p>
1349
+ <p className="font-mono text-sm font-semibold">{value}</p>
1350
+ </div>
1351
+ </div>
1352
+ );
1353
+ }
1354
+
1355
+ function ConfidenceGauge({ value }: { value: number }) {
1356
+ const size = 96;
1357
+ const stroke = 8;
1358
+ const r = (size - stroke) / 2;
1359
+ const c = 2 * Math.PI * r;
1360
+ const offset = c - (value / 100) * c;
1361
+ return (
1362
+ <div className="relative" style={{ width: size, height: size }}>
1363
+ <svg width={size} height={size} className="-rotate-90">
1364
+ <circle
1365
+ cx={size / 2}
1366
+ cy={size / 2}
1367
+ r={r}
1368
+ stroke="oklch(0.28 0.04 252)"
1369
+ strokeWidth={stroke}
1370
+ fill="none"
1371
+ />
1372
+ <circle
1373
+ cx={size / 2}
1374
+ cy={size / 2}
1375
+ r={r}
1376
+ stroke="oklch(0.82 0.18 200)"
1377
+ strokeWidth={stroke}
1378
+ fill="none"
1379
+ strokeDasharray={c}
1380
+ strokeDashoffset={offset}
1381
+ strokeLinecap="round"
1382
+ style={{
1383
+ filter: "drop-shadow(0 0 6px oklch(0.82 0.18 200 / 0.6))",
1384
+ transition: "stroke-dashoffset 0.8s ease",
1385
+ }}
1386
+ />
1387
+ </svg>
1388
+ <div className="absolute inset-0 flex flex-col items-center justify-center">
1389
+ <Gauge className="h-3.5 w-3.5 text-primary" />
1390
+ <span className="mt-0.5 font-mono text-xs text-muted-foreground">
1391
+ score
1392
+ </span>
1393
+ </div>
1394
+ </div>
1395
+ );
1396
+ }
1397
+
1398
+ function LegendDot({ color, label }: { color: string; label: string }) {
1399
+ return (
1400
+ <div className="flex items-center gap-1.5 text-muted-foreground">
1401
+ <span className="h-2 w-2 rounded-full" style={{ background: color }} />
1402
+ {label}
1403
+ </div>
1404
+ );
1405
+ }
1406
+
1407
+ function ResultCard({
1408
+ img,
1409
+ id,
1410
+ tag,
1411
+ }: {
1412
+ img: string;
1413
+ id: string;
1414
+ tag: string;
1415
+ }) {
1416
+ return (
1417
+ <div className="group glass-card relative overflow-hidden">
1418
+ <div className="relative aspect-square overflow-hidden">
1419
+ <img
1420
+ src={img}
1421
+ alt={`Result ${id}`}
1422
+ className="h-full w-full object-cover transition-transform duration-500 group-hover:scale-105"
1423
+ loading="lazy"
1424
+ />
1425
+ <div className="absolute inset-0 bg-gradient-to-t from-background/90 to-transparent opacity-80" />
1426
+ <div className="absolute right-2 top-2 rounded-md bg-background/70 px-2 py-0.5 font-mono text-[10px] backdrop-blur">
1427
+ FAISS #{id}
1428
+ </div>
1429
+ </div>
1430
+ <div className="flex items-center justify-between p-3 text-xs">
1431
+ <span className="font-medium text-primary">{tag}</span>
1432
+ <span className="text-muted-foreground">view β†’</span>
1433
+ </div>
1434
+ </div>
1435
+ );
1436
+ }
1437
+
1438
+ function SearchResultCard({ result }: { result: SearchResult }) {
1439
+ return (
1440
+ <div className="group glass-card relative overflow-hidden">
1441
+ <div className="relative aspect-square overflow-hidden">
1442
+ <img
1443
+ src={result.src}
1444
+ alt={`Result ${result.id}`}
1445
+ className="h-full w-full object-cover transition-transform duration-500 group-hover:scale-105"
1446
+ loading="lazy"
1447
+ />
1448
+ <div className="absolute inset-0 bg-gradient-to-t from-background/90 to-transparent opacity-80" />
1449
+ <div className="absolute right-2 top-2 rounded-md bg-background/70 px-2 py-0.5 font-mono text-[10px] backdrop-blur">
1450
+ {result.tag}
1451
+ </div>
1452
+ </div>
1453
+ <div className="p-3">
1454
+ <p className="font-mono text-xs font-medium text-primary">
1455
+ #{result.id}
1456
+ </p>
1457
+ <div className="mt-1 flex flex-wrap gap-1">
1458
+ {result.attributes.slice(0, 4).map((a) => (
1459
+ <span
1460
+ key={a}
1461
+ className="rounded-full bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground"
1462
+ >
1463
+ {a}
1464
+ </span>
1465
+ ))}
1466
+ {result.attributes.length > 4 && (
1467
+ <span className="rounded-full bg-surface-2 px-1.5 py-0.5 text-[10px] text-muted-foreground">
1468
+ +{result.attributes.length - 4}
1469
+ </span>
1470
+ )}
1471
+ </div>
1472
+ </div>
1473
+ </div>
1474
+ );
1475
+ }