raidAthmaneBenlala commited on
Commit
7f92890
Β·
1 Parent(s): a4fb2bf

feat: redesign frontend UI and add odontogram fixes

Browse files
Files changed (1) hide show
  1. toothmap_frontend/src/App.jsx +366 -251
toothmap_frontend/src/App.jsx CHANGED
@@ -1,79 +1,100 @@
1
  import React, { useState, useRef, useEffect } from 'react';
2
  import axios from 'axios';
3
- import { UploadCloud, Activity, Loader2, ScanLine } from 'lucide-react';
4
 
5
- const API_BASE = "";
6
 
7
  const MODES = [
8
- { id: 'pipeline_yolo', label: '🦷 Full Pipeline (YOLO + FDI)', desc: 'Detect β†’ FDI label + per-tooth segmentation mask' },
9
- { id: 'pipeline_frcnn', label: '🦷 Full Pipeline (FRCNN + FDI)', desc: 'Detect β†’ FDI label + per-tooth segmentation mask' },
10
- { id: 'seg_yolo', label: 'πŸ”¬ Segmentation (YOLO + UNet)', desc: 'Detect teeth β†’ highlight each tooth boundary with U-Net' },
11
- { id: 'seg_frcnn', label: 'πŸ”¬ Segmentation (FRCNN + UNet)', desc: 'Detect teeth β†’ highlight each tooth boundary with U-Net' },
12
- { id: 'yolo', label: 'Detection Only (YOLOv8)', desc: 'Raw bounding boxes only' },
13
- { id: 'frcnn', label: 'Detection Only (Faster R-CNN)', desc: 'Raw bounding boxes only' },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  ];
15
 
16
- // Distinct colours for FDI quadrants 1-4
17
  const QUADRANT_COLOURS = ['#3b82f6', '#22c55e', '#f59e0b', '#ef4444'];
18
-
19
  const UPPER_TEETH = [18, 17, 16, 15, 14, 13, 12, 11, 21, 22, 23, 24, 25, 26, 27, 28];
20
  const LOWER_TEETH = [48, 47, 46, 45, 44, 43, 42, 41, 31, 32, 33, 34, 35, 36, 37, 38];
 
21
 
22
- // Calculate trigonometric absolute positioning for a true circular/horseshoe diagram
23
- function getRadialStyle(index, isUpper) {
24
- // 16 teeth per arch. Spread them across a semi-circle with slight spacing at the edges.
25
- // Distribute t linearly from 0 to 1
26
- const t = index / 15;
27
- // Sweep from 170 degrees (left) to 10 degrees (right) to leave a gap at the hinge
28
- const startAngle = 175;
29
- const endAngle = 5;
30
- const angleDeg = startAngle - t * (startAngle - endAngle);
31
- const angleRad = (angleDeg * Math.PI) / 180;
32
-
33
- // Elliptical radii
34
- const rx = 40; // width radius %
35
- const ry = 85; // height radius %
36
-
37
- const cx = 50;
38
- const cy = isUpper ? 100 : 0; // upper arch pivots from bottom, lower pivots from top
39
-
40
- const left = cx + rx * Math.cos(angleRad);
41
- const top = isUpper ? cy - ry * Math.sin(angleRad) : cy + ry * Math.sin(angleRad);
42
-
43
- // Tangent rotation so the teeth point correctly along the ring
44
- const rotation = isUpper ? (90 - angleDeg) : (angleDeg - 90);
45
-
46
- return {
47
- wrapper: {
48
- position: 'absolute',
49
- left: `${left}%`,
50
- top: `${top}%`,
51
- transform: `translate(-50%, -50%) rotate(${rotation}deg)`
52
- },
53
- text: {
54
- transform: `rotate(${-rotation}deg)`,
55
- display: 'inline-block'
56
- }
57
- };
58
- }
59
-
60
- function getToothClasses(fdi, isUpper) {
61
  const quad = Math.floor(fdi / 10);
62
- switch (quad) {
63
- case 1: return `text-blue-300 border-blue-500/60 shadow-[0_0_15px_rgba(59,130,246,0.3)] ${isUpper ? 'bg-gradient-to-b from-blue-500/20 to-blue-500/40' : 'bg-gradient-to-t from-blue-500/20 to-blue-500/40'}`;
64
- case 2: return `text-green-300 border-green-500/60 shadow-[0_0_15px_rgba(34,197,94,0.3)] ${isUpper ? 'bg-gradient-to-b from-green-500/20 to-green-500/40' : 'bg-gradient-to-t from-green-500/20 to-green-500/40'}`;
65
- case 3: return `text-amber-300 border-amber-500/60 shadow-[0_0_15px_rgba(245,158,11,0.3)] ${isUpper ? 'bg-gradient-to-b from-amber-500/20 to-amber-500/40' : 'bg-gradient-to-t from-amber-500/20 to-amber-500/40'}`;
66
- case 4: return `text-red-300 border-red-500/60 shadow-[0_0_15px_rgba(239,68,68,0.3)] ${isUpper ? 'bg-gradient-to-b from-red-500/20 to-red-500/40' : 'bg-gradient-to-t from-red-500/20 to-red-500/40'}`;
67
- default: return 'text-purple-300 border-purple-500/60 shadow-[0_0_15px_rgba(168,85,247,0.3)] bg-purple-500/20';
68
- }
69
  }
70
 
71
  function computeIoU(b1, b2) {
72
  const ix = Math.max(b1[0], b2[0]), iy = Math.max(b1[1], b2[1]);
73
  const iw = Math.min(b1[2], b2[2]) - ix, ih = Math.min(b1[3], b2[3]) - iy;
74
  if (iw <= 0 || ih <= 0) return 0;
75
- const intersection = iw * ih;
76
- return intersection / ((b1[2]-b1[0])*(b1[3]-b1[1]) + (b2[2]-b2[0])*(b2[3]-b2[1]) - intersection);
77
  }
78
 
79
  function applyNMS(results, iouThreshold = 0.35) {
@@ -91,17 +112,111 @@ function getColour(fdi) {
91
  return QUADRANT_COLOURS[Math.min(quad, 3)] ?? '#a855f7';
92
  }
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  export default function App() {
95
  const [file, setFile] = useState(null);
96
  const [imagePreview, setImagePreview] = useState(null);
97
  const [mode, setMode] = useState('pipeline_yolo');
98
- const [pipelineResults, setPipelineResults] = useState(null); // [{box,score,fdi,confidence}]
99
- const [rawBoxes, setRawBoxes] = useState(null); // {boxes,scores}
100
  const [maskSrc, setMaskSrc] = useState(null);
101
  const [loading, setLoading] = useState(false);
 
102
  const imgRef = useRef(null);
103
  const canvasRef = useRef(null);
104
 
 
 
 
 
105
  const handleFileSelect = (f) => {
106
  setFile(f);
107
  setImagePreview(URL.createObjectURL(f));
@@ -117,16 +232,10 @@ export default function App() {
117
  const fd = new FormData();
118
  fd.append("file", file);
119
  try {
120
- if (mode === 'pipeline_yolo') {
121
  const r = await axios.post(`${API_BASE}/api/pipeline/yolo`, fd);
122
  setPipelineResults(r.data.results);
123
- } else if (mode === 'pipeline_frcnn') {
124
- const r = await axios.post(`${API_BASE}/api/pipeline/frcnn`, fd);
125
- setPipelineResults(r.data.results);
126
- } else if (mode === 'seg_yolo') {
127
- const r = await axios.post(`${API_BASE}/api/pipeline/yolo`, fd);
128
- setPipelineResults(r.data.results);
129
- } else if (mode === 'seg_frcnn') {
130
  const r = await axios.post(`${API_BASE}/api/pipeline/frcnn`, fd);
131
  setPipelineResults(r.data.results);
132
  } else if (mode === 'yolo') {
@@ -138,53 +247,41 @@ export default function App() {
138
  }
139
  } catch (e) {
140
  console.error(e);
141
- alert("Error contacting the AI server. Ensure the FastAPI server is running on port 8000.");
142
  } finally {
143
  setLoading(false);
144
  }
145
  };
146
 
147
- // Draw canvas overlays
148
  useEffect(() => {
149
  if (!canvasRef.current || !imgRef.current) return;
150
  const img = imgRef.current;
151
  const ctx = canvasRef.current.getContext('2d');
152
  const { width, height } = img.getBoundingClientRect();
153
- canvasRef.current.width = width;
154
  canvasRef.current.height = height;
155
- const sx = width / img.naturalWidth;
156
  const sy = height / img.naturalHeight;
157
  ctx.clearRect(0, 0, width, height);
158
 
159
- // Pipeline / segmentation mode
160
  if (pipelineResults) {
161
- // Spatial IoU Non-Maximum Suppression to remove physically overlapping boxes
162
- // without deleting distinct teeth just because they share an FDI label!
163
  const uniqueResults = applyNMS(pipelineResults, 0.40);
164
-
165
- const showFDI = (mode === 'pipeline_yolo' || mode === 'pipeline_frcnn');
166
  uniqueResults.forEach(({ box, score, fdi, mask_base64 }) => {
167
  const [x1, y1, x2, y2] = box;
168
- const rx = x1 * sx, ry = y1 * sy, rw = (x2 - x1) * sx, rh = (y2 - y1) * sy;
169
  const col = showFDI ? getColour(fdi) : '#22d3ee';
170
-
171
- // Draw segmentation mask β€” tinted fill inside the actual tooth boundary
172
  if (mask_base64) {
173
  const maskImg = new Image();
174
  maskImg.onload = () => {
175
  const off = document.createElement('canvas');
176
  off.width = rw; off.height = rh;
177
  const octx = off.getContext('2d');
178
-
179
- // Draw solid colour background
180
  octx.fillStyle = col;
181
  octx.fillRect(0, 0, rw, rh);
182
-
183
- // Mask the solid colour using the alpha channel of the PNG
184
  octx.globalCompositeOperation = 'destination-in';
185
  octx.drawImage(maskImg, 0, 0, rw, rh);
186
-
187
- // Draw onto main canvas
188
  ctx.save();
189
  ctx.globalAlpha = 0.50;
190
  ctx.drawImage(off, rx, ry);
@@ -192,211 +289,229 @@ export default function App() {
192
  };
193
  maskImg.src = `data:image/png;base64,${mask_base64}`;
194
  }
195
-
196
- // Bounding box
197
  ctx.strokeStyle = col; ctx.lineWidth = 2;
198
  ctx.strokeRect(rx, ry, rw, rh);
199
- // Label β€” only in pipeline (FDI) modes
200
- const label = showFDI
201
- ? (fdi > 0 ? `FDI ${fdi}` : `${(score*100).toFixed(0)}%`)
202
- : `${(score*100).toFixed(0)}%`;
203
- const textW = ctx.measureText(label).width + 10;
204
  ctx.fillStyle = col;
205
- ctx.fillRect(rx, ry - 20, textW, 20);
206
  ctx.fillStyle = 'white'; ctx.font = 'bold 12px Arial';
207
  ctx.fillText(label, rx + 5, ry - 5);
208
  });
209
  }
210
 
211
- // Raw detection mode
212
  if (rawBoxes?.boxes) {
213
  rawBoxes.boxes.forEach((box, i) => {
214
  const [x1, y1, x2, y2] = box;
215
- const rx = x1 * sx, ry = y1 * sy, rw = (x2 - x1) * sx, rh = (y2 - y1) * sy;
216
  ctx.strokeStyle = '#3b82f6'; ctx.lineWidth = 2;
217
  ctx.strokeRect(rx, ry, rw, rh);
218
- const s = `${(rawBoxes.scores[i] * 100).toFixed(0)}%`;
219
  ctx.fillStyle = '#3b82f6'; ctx.fillRect(rx, ry - 20, 40, 20);
220
  ctx.fillStyle = 'white'; ctx.font = '12px Arial';
221
  ctx.fillText(s, rx + 4, ry - 5);
222
  });
223
  }
224
- }, [pipelineResults, rawBoxes]);
225
 
226
- // Legend for pipeline mode
227
- const quadrantNames = ['Q1 (Upper Right)', 'Q2 (Upper Left)', 'Q3 (Lower Left)', 'Q4 (Lower Right)'];
228
-
229
- // Spatial IoU filtered results for UI stats
230
  const uniquePipelineResults = pipelineResults ? applyNMS(pipelineResults, 0.40) : null;
 
 
 
231
 
232
  return (
233
  <div className="min-h-screen flex flex-col bg-zinc-950 font-sans text-slate-200">
234
- <header className="px-8 py-4 border-b border-zinc-800/50 flex items-center gap-3">
235
- <Activity size={22} className="text-blue-500" />
236
- <h1 className="text-lg font-bold bg-gradient-to-r from-blue-400 to-indigo-400 bg-clip-text text-transparent">
 
 
237
  ToothMap AI Dashboard
238
  </h1>
239
  </header>
240
 
241
- <main className="flex-1 flex flex-col lg:flex-row overflow-auto lg:overflow-hidden">
242
- {/* Sidebar */}
243
- <aside className="w-full lg:w-80 flex-shrink-0 bg-zinc-900/40 border-b lg:border-b-0 lg:border-r border-zinc-800/50 p-5 flex flex-col gap-4 overflow-y-auto">
244
- <div className="space-y-2">
245
- <p className="text-xs font-semibold text-slate-500 uppercase tracking-widest mb-2">AI Mode</p>
246
- {MODES.map(m => (
247
- <button key={m.id} onClick={() => setMode(m.id)}
248
- className={`w-full text-left px-3 py-2.5 rounded-lg border text-sm transition-all ${
249
- mode === m.id
250
- ? 'bg-blue-500/10 border-blue-500/50 text-blue-300'
251
- : 'bg-zinc-800/20 border-zinc-700/30 text-slate-400 hover:bg-zinc-800/40'
252
- }`}>
253
- <div className="font-medium">{m.label}</div>
254
- <div className="text-xs text-zinc-500 mt-0.5">{m.desc}</div>
255
  </button>
256
- ))}
257
- </div>
258
-
259
- <div className="border-2 border-dashed border-zinc-700/50 hover:border-blue-500/50 transition-colors rounded-xl p-6 flex flex-col items-center text-center cursor-pointer bg-zinc-900/20 group"
260
- onClick={() => document.getElementById('fu').click()}
261
- onDragOver={e => e.preventDefault()}
262
- onDrop={e => { e.preventDefault(); if (e.dataTransfer.files[0]) handleFileSelect(e.dataTransfer.files[0]); }}>
263
- <UploadCloud size={32} className="text-zinc-500 group-hover:text-blue-400 mb-2 transition-colors" />
264
- <p className="text-sm font-medium">{file ? file.name : 'Drag & Drop X-Ray'}</p>
265
- <p className="text-xs text-zinc-500 mt-1">or click to browse</p>
266
- <input type="file" id="fu" className="hidden" accept="image/*"
267
- onChange={e => handleFileSelect(e.target.files[0])} />
268
- </div>
269
-
270
- <button onClick={handleAPI} disabled={!file || loading}
271
- className={`w-full py-3 rounded-lg font-semibold flex items-center justify-center gap-2 transition-all ${
272
- !file ? 'bg-zinc-800 text-zinc-500 cursor-not-allowed' : 'bg-blue-600 hover:bg-blue-500 text-white shadow-lg shadow-blue-900/30'
273
- }`}>
274
- {loading ? <Loader2 size={18} className="animate-spin" /> : <ScanLine size={18} />}
275
- {loading ? 'Analysing...' : 'Run AI Analysis'}
276
- </button>
277
-
278
- {/* Legend */}
279
- {pipelineResults && (
280
- <div className="mt-2">
281
- <p className="text-xs text-zinc-500 uppercase tracking-widest mb-2">FDI Quadrants</p>
282
- {quadrantNames.map((name, i) => (
283
- <div key={i} className="flex items-center gap-2 text-xs mb-1">
284
- <span className="w-3 h-3 rounded-sm flex-shrink-0" style={{ background: QUADRANT_COLOURS[i] }} />
285
- <span className="text-zinc-400">{name}</span>
286
  </div>
287
- ))}
288
  </div>
289
- )}
 
 
290
 
291
- {/* Stats Panel */}
292
- {(uniquePipelineResults || rawBoxes) && (
293
- <div className="bg-zinc-800/30 rounded-lg p-3 text-sm">
294
- <p className="text-zinc-400 text-xs mb-1">Detected Teeth</p>
295
- <p className="text-2xl font-bold text-white">
296
- {uniquePipelineResults ? uniquePipelineResults.length : rawBoxes.boxes.length}
297
- </p>
298
- {uniquePipelineResults && uniquePipelineResults.slice(0,6).map((r, i) => (
299
- <div key={i} className="flex justify-between text-xs text-zinc-500 mt-1">
300
- <span style={{ color: getColour(r.fdi) }}>FDI {r.fdi > 0 ? r.fdi : '?'}</span>
301
- <span>{(r.confidence * 100).toFixed(0)}% conf</span>
302
- </div>
303
- ))}
304
- {uniquePipelineResults && uniquePipelineResults.length > 6 && (
305
- <p className="text-xs text-zinc-600 mt-1">+{uniquePipelineResults.length - 6} more...</p>
 
 
 
 
 
 
306
  )}
307
- </div>
308
- )}
309
- </aside>
310
-
311
- {/* Canvas & Main Area */}
312
- <section className="flex-1 bg-zinc-950/80 p-4 lg:p-8 flex flex-col items-center justify-start overflow-auto min-h-[50vh] relative gap-8">
313
- {!imagePreview ? (
314
- <div className="text-center text-zinc-600 my-auto">
315
- <UploadCloud size={64} className="mx-auto opacity-20 mb-4" />
316
- <p className="text-lg">No patient X-Ray selected</p>
317
  </div>
318
  ) : (
319
  <>
320
- {/* Image Container */}
321
- <div className="relative inline-block border border-zinc-800 rounded-xl overflow-hidden shadow-2xl bg-black">
322
- <img ref={imgRef} src={imagePreview} alt="X-ray"
323
- className="max-w-full max-h-[60vh] object-contain block rounded" />
324
- <canvas ref={canvasRef} className="absolute top-0 left-0 pointer-events-none" />
325
- {maskSrc && (
326
- <img src={maskSrc} className="absolute top-0 left-0 w-full h-full object-fill pointer-events-none opacity-50 mix-blend-screen" alt="Segmentation Mask" />
327
- )}
328
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
329
 
330
- {/* Dental FDI Chart (Odontogram) moved to Main Section */}
331
- {(uniquePipelineResults && mode.includes('pipeline')) && (
332
- <div className="w-full max-w-4xl bg-zinc-900/60 rounded-2xl p-8 border border-zinc-800/80 shadow-2xl mt-4">
333
- <p className="text-sm font-bold text-slate-300 uppercase tracking-widest mb-4 text-center">Comprehensive Dental Ring</p>
334
-
335
- {/* True Circular Layout Container */}
336
- <div className="relative w-full h-[500px] flex flex-col items-center justify-center my-4 opacity-90 mx-auto max-w-[600px]">
337
-
338
- {/* Upper Arch (Maxillary) */}
339
- <div className="relative w-full h-[250px]">
340
- {UPPER_TEETH.map((t, idx) => {
341
- const styleNode = getRadialStyle(idx, true);
342
- return (
343
- <div key={t}
344
- style={styleNode.wrapper}
345
- className={`w-9 h-12 rounded-t-sm rounded-b-[16px] flex items-center justify-center text-sm font-bold transition-all shadow-lg border ${
346
- uniquePipelineResults.some(r => r.fdi === t)
347
- ? getToothClasses(t, true)
348
- : 'bg-zinc-800 text-zinc-500 border-zinc-700/50'
349
- }`}>
350
- <span style={styleNode.text}>{t}</span>
351
- </div>
352
- )})}
353
- </div>
354
-
355
- {/* Lower Arch (Mandibular) */}
356
- <div className="relative w-full h-[250px]">
357
- {LOWER_TEETH.map((t, idx) => {
358
- const styleNode = getRadialStyle(idx, false);
359
- return (
360
- <div key={t}
361
- style={styleNode.wrapper}
362
- className={`w-9 h-12 rounded-b-sm rounded-t-[16px] flex items-center justify-center text-sm font-bold transition-all shadow-lg border ${
363
- uniquePipelineResults.some(r => r.fdi === t)
364
- ? getToothClasses(t, false)
365
- : 'bg-zinc-800 text-zinc-500 border-zinc-700/50'
366
- }`}>
367
- <span style={styleNode.text}>{t}</span>
368
- </div>
369
- )})}
370
- </div>
371
-
372
- {/* Central Jaw Ring Divider Line (Aesthetics) */}
373
- <div className="absolute top-1/2 left-[10%] right-[10%] h-px bg-gradient-to-r from-transparent via-zinc-700 to-transparent -translate-y-1/2 pointer-events-none" />
374
- <div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 text-[10px] text-zinc-500 font-mono tracking-widest whitespace-nowrap bg-zinc-900/60 px-4 rounded-full pointer-events-none">
375
- MAXILLARY / MANDIBULAR
376
- </div>
377
  </div>
378
-
379
- {/* Legend below chart */}
380
- <div className="flex justify-center gap-10 mt-4 text-sm text-zinc-400 font-medium">
381
- <div className="flex items-center gap-3">
382
- <div className="flex align-center -space-x-1.5 opacity-90">
383
- <span className="w-4 h-4 rounded-full bg-gradient-to-bl from-blue-400 to-blue-600 border border-zinc-900 shadow-sm relative z-40"></span>
384
- <span className="w-4 h-4 rounded-full bg-gradient-to-bl from-green-400 to-green-600 border border-zinc-900 shadow-sm relative z-30"></span>
385
- <span className="w-4 h-4 rounded-full bg-gradient-to-bl from-amber-400 to-amber-600 border border-zinc-900 shadow-sm relative z-20"></span>
386
- <span className="w-4 h-4 rounded-full bg-gradient-to-bl from-red-400 to-red-600 border border-zinc-900 shadow-sm relative z-10"></span>
387
- </div>
388
- Detected Tooth
389
- </div>
390
- <div className="flex items-center gap-2">
391
- <span className="w-4 h-4 rounded-md bg-zinc-800 border-2 border-zinc-700/50"></span>
392
- Missing Tooth
393
- </div>
394
  </div>
 
 
 
 
 
 
 
 
395
  </div>
396
  )}
397
- </>
398
- )}
399
- </section>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
400
  </main>
401
  </div>
402
  );
 
1
  import React, { useState, useRef, useEffect } from 'react';
2
  import axios from 'axios';
3
+ import { UploadCloud, Activity, Loader2, ScanLine, X } from 'lucide-react';
4
 
5
+ const API_BASE = "http://127.0.0.1:8000";
6
 
7
  const MODES = [
8
+ {
9
+ id: 'yolo',
10
+ label: 'Detection 1',
11
+ emoji: 'πŸ”',
12
+ desc: 'YOLOv8s bounding box detection',
13
+ models: 'YOLOv8s',
14
+ color: 'from-blue-500 to-cyan-500',
15
+ active: 'bg-gradient-to-r from-blue-500/20 to-cyan-500/20 border-blue-400/60 text-blue-300',
16
+ inactive: 'border-zinc-700/40 text-zinc-400 hover:border-blue-500/40 hover:text-blue-300',
17
+ type: 'detection',
18
+ },
19
+ {
20
+ id: 'frcnn',
21
+ label: 'Detection 2',
22
+ emoji: 'πŸ”Ž',
23
+ desc: 'Faster R-CNN bounding box detection',
24
+ models: 'Faster R-CNN (ResNet50-FPN)',
25
+ color: 'from-indigo-500 to-blue-500',
26
+ active: 'bg-gradient-to-r from-indigo-500/20 to-blue-500/20 border-indigo-400/60 text-indigo-300',
27
+ inactive: 'border-zinc-700/40 text-zinc-400 hover:border-indigo-500/40 hover:text-indigo-300',
28
+ type: 'detection',
29
+ },
30
+ {
31
+ id: 'seg_yolo',
32
+ label: 'Det + Seg 1',
33
+ emoji: 'πŸ”¬',
34
+ desc: 'YOLO detection + U-Net segmentation masks',
35
+ models: 'YOLOv8s + U-Net (ResNet34)',
36
+ color: 'from-violet-500 to-purple-500',
37
+ active: 'bg-gradient-to-r from-violet-500/20 to-purple-500/20 border-violet-400/60 text-violet-300',
38
+ inactive: 'border-zinc-700/40 text-zinc-400 hover:border-violet-500/40 hover:text-violet-300',
39
+ type: 'segmentation',
40
+ },
41
+ {
42
+ id: 'seg_frcnn',
43
+ label: 'Det + Seg 2',
44
+ emoji: '🧬',
45
+ desc: 'Faster R-CNN detection + U-Net segmentation masks',
46
+ models: 'Faster R-CNN + U-Net (ResNet34)',
47
+ color: 'from-fuchsia-500 to-pink-500',
48
+ active: 'bg-gradient-to-r from-fuchsia-500/20 to-pink-500/20 border-fuchsia-400/60 text-fuchsia-300',
49
+ inactive: 'border-zinc-700/40 text-zinc-400 hover:border-fuchsia-500/40 hover:text-fuchsia-300',
50
+ type: 'segmentation',
51
+ },
52
+ {
53
+ id: 'pipeline_yolo',
54
+ label: 'Full AI 1',
55
+ emoji: '🦷',
56
+ desc: 'YOLO detection + FDI classification + U-Net segmentation',
57
+ models: 'YOLOv8s + EfficientNetV2-S + U-Net',
58
+ color: 'from-emerald-500 to-teal-500',
59
+ active: 'bg-gradient-to-r from-emerald-500/20 to-teal-500/20 border-emerald-400/60 text-emerald-300',
60
+ inactive: 'border-zinc-700/40 text-zinc-400 hover:border-emerald-500/40 hover:text-emerald-300',
61
+ type: 'pipeline',
62
+ },
63
+ {
64
+ id: 'pipeline_frcnn',
65
+ label: 'Full AI 2',
66
+ emoji: '🩺',
67
+ desc: 'Faster R-CNN detection + FDI classification + U-Net segmentation',
68
+ models: 'Faster R-CNN + EfficientNetV2-S + U-Net',
69
+ color: 'from-amber-500 to-orange-500',
70
+ active: 'bg-gradient-to-r from-amber-500/20 to-orange-500/20 border-amber-400/60 text-amber-300',
71
+ inactive: 'border-zinc-700/40 text-zinc-400 hover:border-amber-500/40 hover:text-amber-300',
72
+ type: 'pipeline',
73
+ },
74
  ];
75
 
 
76
  const QUADRANT_COLOURS = ['#3b82f6', '#22c55e', '#f59e0b', '#ef4444'];
 
77
  const UPPER_TEETH = [18, 17, 16, 15, 14, 13, 12, 11, 21, 22, 23, 24, 25, 26, 27, 28];
78
  const LOWER_TEETH = [48, 47, 46, 45, 44, 43, 42, 41, 31, 32, 33, 34, 35, 36, 37, 38];
79
+ const ALL_TEETH = [...UPPER_TEETH, ...LOWER_TEETH];
80
 
81
+ function getToothStyle(fdi) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  const quad = Math.floor(fdi / 10);
83
+ const colors = {
84
+ 1: { border: '#3b82f6', bg: 'rgba(59,130,246,0.25)', text: '#93c5fd' },
85
+ 2: { border: '#22c55e', bg: 'rgba(34,197,94,0.25)', text: '#86efac' },
86
+ 3: { border: '#f59e0b', bg: 'rgba(245,158,11,0.25)', text: '#fcd34d' },
87
+ 4: { border: '#ef4444', bg: 'rgba(239,68,68,0.25)', text: '#fca5a5' },
88
+ };
89
+ return colors[quad] || { border: '#a855f7', bg: 'rgba(168,85,247,0.25)', text: '#d8b4fe' };
90
  }
91
 
92
  function computeIoU(b1, b2) {
93
  const ix = Math.max(b1[0], b2[0]), iy = Math.max(b1[1], b2[1]);
94
  const iw = Math.min(b1[2], b2[2]) - ix, ih = Math.min(b1[3], b2[3]) - iy;
95
  if (iw <= 0 || ih <= 0) return 0;
96
+ const inter = iw * ih;
97
+ return inter / ((b1[2]-b1[0])*(b1[3]-b1[1]) + (b2[2]-b2[0])*(b2[3]-b2[1]) - inter);
98
  }
99
 
100
  function applyNMS(results, iouThreshold = 0.35) {
 
112
  return QUADRANT_COLOURS[Math.min(quad, 3)] ?? '#a855f7';
113
  }
114
 
115
+ // ── Odontogram Component ──────────────────────────────────────────────────────
116
+ function Odontogram({ detectedFDIs }) {
117
+ const detected = new Set(detectedFDIs);
118
+
119
+ const ToothCell = ({ fdi, isUpper }) => {
120
+ const present = detected.has(fdi);
121
+ const style = present ? getToothStyle(fdi) : null;
122
+ return (
123
+ <div
124
+ title={present ? `FDI ${fdi} β€” detected` : `FDI ${fdi} β€” not detected`}
125
+ style={present ? {
126
+ border: `2px solid ${style.border}`,
127
+ background: style.bg,
128
+ color: style.text,
129
+ boxShadow: `0 0 12px ${style.border}55`,
130
+ } : {
131
+ border: '2px solid rgba(113,113,122,0.35)',
132
+ background: 'rgba(39,39,42,0.6)',
133
+ color: 'transparent',
134
+ position: 'relative',
135
+ }}
136
+ className={`flex items-center justify-center font-bold text-xs rounded-md transition-all select-none
137
+ ${isUpper ? 'rounded-t-full' : 'rounded-b-full'}
138
+ w-8 h-10 sm:w-9 sm:h-12 md:w-10 md:h-12 lg:w-9 lg:h-12`}
139
+ >
140
+ {present ? (
141
+ <span>{fdi}</span>
142
+ ) : (
143
+ <>
144
+ {/* Red X cross for missing teeth */}
145
+ <svg viewBox="0 0 24 24" className="w-4 h-4 absolute" fill="none" stroke="#ef4444" strokeWidth="2.5" strokeLinecap="round">
146
+ <line x1="6" y1="6" x2="18" y2="18" />
147
+ <line x1="18" y1="6" x2="6" y2="18" />
148
+ </svg>
149
+ <span className="text-zinc-600 text-[9px] absolute bottom-0.5">{fdi}</span>
150
+ </>
151
+ )}
152
+ </div>
153
+ );
154
+ };
155
+
156
+ return (
157
+ <div className="w-full bg-zinc-900/60 rounded-2xl p-4 sm:p-6 border border-zinc-800/80 shadow-2xl">
158
+ <p className="text-xs font-bold text-slate-400 uppercase tracking-widest mb-4 text-center">
159
+ FDI Odontogram β€” Dental Chart
160
+ </p>
161
+
162
+ {/* Upper arch */}
163
+ <div className="flex justify-center flex-wrap gap-1 sm:gap-1.5 mb-2">
164
+ {UPPER_TEETH.map(t => <ToothCell key={t} fdi={t} isUpper={true} />)}
165
+ </div>
166
+
167
+ {/* Maxillary / Mandibular divider */}
168
+ <div className="flex items-center gap-2 my-2">
169
+ <div className="flex-1 h-px bg-gradient-to-r from-transparent via-zinc-700 to-transparent" />
170
+ <span className="text-[9px] text-zinc-600 font-mono tracking-widest whitespace-nowrap">
171
+ MAXILLARY / MANDIBULAR
172
+ </span>
173
+ <div className="flex-1 h-px bg-gradient-to-r from-transparent via-zinc-700 to-transparent" />
174
+ </div>
175
+
176
+ {/* Lower arch */}
177
+ <div className="flex justify-center flex-wrap gap-1 sm:gap-1.5 mt-2">
178
+ {LOWER_TEETH.map(t => <ToothCell key={t} fdi={t} isUpper={false} />)}
179
+ </div>
180
+
181
+ {/* Legend */}
182
+ <div className="flex flex-wrap justify-center gap-4 sm:gap-8 mt-4 text-xs text-zinc-400">
183
+ <div className="flex items-center gap-2">
184
+ <div className="flex -space-x-1">
185
+ {['bg-blue-500','bg-green-500','bg-amber-500','bg-red-500'].map((c,i) => (
186
+ <span key={i} className={`w-3 h-3 rounded-full ${c} border border-zinc-900`} />
187
+ ))}
188
+ </div>
189
+ <span>Detected (Q1–Q4)</span>
190
+ </div>
191
+ <div className="flex items-center gap-2">
192
+ <svg viewBox="0 0 16 16" className="w-3 h-3" fill="none" stroke="#ef4444" strokeWidth="2.5" strokeLinecap="round">
193
+ <line x1="3" y1="3" x2="13" y2="13" />
194
+ <line x1="13" y1="3" x2="3" y2="13" />
195
+ </svg>
196
+ <span>Not detected / Missing</span>
197
+ </div>
198
+ </div>
199
+ </div>
200
+ );
201
+ }
202
+
203
+ // ── Main App ──────────────────────────────────────────────────────────────────
204
  export default function App() {
205
  const [file, setFile] = useState(null);
206
  const [imagePreview, setImagePreview] = useState(null);
207
  const [mode, setMode] = useState('pipeline_yolo');
208
+ const [pipelineResults, setPipelineResults] = useState(null);
209
+ const [rawBoxes, setRawBoxes] = useState(null);
210
  const [maskSrc, setMaskSrc] = useState(null);
211
  const [loading, setLoading] = useState(false);
212
+ const [hoveredMode, setHoveredMode] = useState(null);
213
  const imgRef = useRef(null);
214
  const canvasRef = useRef(null);
215
 
216
+ const currentMode = MODES.find(m => m.id === mode);
217
+ const isPipeline = currentMode?.type === 'pipeline';
218
+ const isDetection = currentMode?.type === 'detection';
219
+
220
  const handleFileSelect = (f) => {
221
  setFile(f);
222
  setImagePreview(URL.createObjectURL(f));
 
232
  const fd = new FormData();
233
  fd.append("file", file);
234
  try {
235
+ if (mode === 'pipeline_yolo' || mode === 'seg_yolo') {
236
  const r = await axios.post(`${API_BASE}/api/pipeline/yolo`, fd);
237
  setPipelineResults(r.data.results);
238
+ } else if (mode === 'pipeline_frcnn' || mode === 'seg_frcnn') {
 
 
 
 
 
 
239
  const r = await axios.post(`${API_BASE}/api/pipeline/frcnn`, fd);
240
  setPipelineResults(r.data.results);
241
  } else if (mode === 'yolo') {
 
247
  }
248
  } catch (e) {
249
  console.error(e);
250
+ alert("Error contacting the AI server. Ensure FastAPI is running on port 8000.");
251
  } finally {
252
  setLoading(false);
253
  }
254
  };
255
 
256
+ // Draw bounding boxes + segmentation masks on canvas
257
  useEffect(() => {
258
  if (!canvasRef.current || !imgRef.current) return;
259
  const img = imgRef.current;
260
  const ctx = canvasRef.current.getContext('2d');
261
  const { width, height } = img.getBoundingClientRect();
262
+ canvasRef.current.width = width;
263
  canvasRef.current.height = height;
264
+ const sx = width / img.naturalWidth;
265
  const sy = height / img.naturalHeight;
266
  ctx.clearRect(0, 0, width, height);
267
 
 
268
  if (pipelineResults) {
269
+ const showFDI = isPipeline;
 
270
  const uniqueResults = applyNMS(pipelineResults, 0.40);
 
 
271
  uniqueResults.forEach(({ box, score, fdi, mask_base64 }) => {
272
  const [x1, y1, x2, y2] = box;
273
+ const rx = x1*sx, ry = y1*sy, rw = (x2-x1)*sx, rh = (y2-y1)*sy;
274
  const col = showFDI ? getColour(fdi) : '#22d3ee';
 
 
275
  if (mask_base64) {
276
  const maskImg = new Image();
277
  maskImg.onload = () => {
278
  const off = document.createElement('canvas');
279
  off.width = rw; off.height = rh;
280
  const octx = off.getContext('2d');
 
 
281
  octx.fillStyle = col;
282
  octx.fillRect(0, 0, rw, rh);
 
 
283
  octx.globalCompositeOperation = 'destination-in';
284
  octx.drawImage(maskImg, 0, 0, rw, rh);
 
 
285
  ctx.save();
286
  ctx.globalAlpha = 0.50;
287
  ctx.drawImage(off, rx, ry);
 
289
  };
290
  maskImg.src = `data:image/png;base64,${mask_base64}`;
291
  }
 
 
292
  ctx.strokeStyle = col; ctx.lineWidth = 2;
293
  ctx.strokeRect(rx, ry, rw, rh);
294
+ const label = showFDI ? (fdi > 0 ? `FDI ${fdi}` : `${(score*100).toFixed(0)}%`) : `${(score*100).toFixed(0)}%`;
295
+ const tw = ctx.measureText(label).width + 10;
 
 
 
296
  ctx.fillStyle = col;
297
+ ctx.fillRect(rx, ry - 20, tw, 20);
298
  ctx.fillStyle = 'white'; ctx.font = 'bold 12px Arial';
299
  ctx.fillText(label, rx + 5, ry - 5);
300
  });
301
  }
302
 
 
303
  if (rawBoxes?.boxes) {
304
  rawBoxes.boxes.forEach((box, i) => {
305
  const [x1, y1, x2, y2] = box;
306
+ const rx = x1*sx, ry = y1*sy, rw = (x2-x1)*sx, rh = (y2-y1)*sy;
307
  ctx.strokeStyle = '#3b82f6'; ctx.lineWidth = 2;
308
  ctx.strokeRect(rx, ry, rw, rh);
309
+ const s = `${(rawBoxes.scores[i]*100).toFixed(0)}%`;
310
  ctx.fillStyle = '#3b82f6'; ctx.fillRect(rx, ry - 20, 40, 20);
311
  ctx.fillStyle = 'white'; ctx.font = '12px Arial';
312
  ctx.fillText(s, rx + 4, ry - 5);
313
  });
314
  }
315
+ }, [pipelineResults, rawBoxes, isPipeline]);
316
 
 
 
 
 
317
  const uniquePipelineResults = pipelineResults ? applyNMS(pipelineResults, 0.40) : null;
318
+ const detectedFDIs = uniquePipelineResults ? uniquePipelineResults.filter(r => r.fdi > 0).map(r => r.fdi) : [];
319
+ const totalDetected = uniquePipelineResults ? uniquePipelineResults.length : (rawBoxes?.boxes?.length ?? 0);
320
+ const hasResults = uniquePipelineResults || rawBoxes;
321
 
322
  return (
323
  <div className="min-h-screen flex flex-col bg-zinc-950 font-sans text-slate-200">
324
+
325
+ {/* ── Header ─────────────────────────────────────────────────────────── */}
326
+ <header className="px-4 sm:px-8 py-3 border-b border-zinc-800/50 flex items-center gap-3">
327
+ <Activity size={20} className="text-blue-500 flex-shrink-0" />
328
+ <h1 className="text-base sm:text-lg font-bold bg-gradient-to-r from-blue-400 to-indigo-400 bg-clip-text text-transparent">
329
  ToothMap AI Dashboard
330
  </h1>
331
  </header>
332
 
333
+ {/* ── Mode Selection Bar ─────────────────────────────────────────────── */}
334
+ <div className="border-b border-zinc-800/50 px-3 sm:px-6 py-3 bg-zinc-900/30">
335
+ <div className="flex flex-wrap gap-2 justify-center">
336
+ {MODES.map(m => (
337
+ <div key={m.id} className="relative"
338
+ onMouseEnter={() => setHoveredMode(m.id)}
339
+ onMouseLeave={() => setHoveredMode(null)}>
340
+ <button
341
+ onClick={() => { setMode(m.id); setPipelineResults(null); setRawBoxes(null); setMaskSrc(null); }}
342
+ className={`px-3 sm:px-4 py-2 rounded-xl border text-xs sm:text-sm font-semibold transition-all duration-200 whitespace-nowrap ${
343
+ mode === m.id ? m.active : m.inactive
344
+ }`}
345
+ >
346
+ <span className="mr-1.5">{m.emoji}</span>{m.label}
347
  </button>
348
+ {/* Hover tooltip */}
349
+ {hoveredMode === m.id && (
350
+ <div className="absolute top-full left-1/2 -translate-x-1/2 mt-2 z-50 w-56 bg-zinc-800 border border-zinc-700/60 rounded-xl p-3 shadow-2xl pointer-events-none">
351
+ <p className="text-xs font-bold text-white mb-1">{m.emoji} {m.label}</p>
352
+ <p className="text-xs text-zinc-300 mb-2">{m.desc}</p>
353
+ <div className="flex flex-wrap gap-1">
354
+ {m.models.split(' + ').map((mdl, i) => (
355
+ <span key={i} className={`text-[10px] px-2 py-0.5 rounded-full bg-gradient-to-r ${m.color} text-white font-medium`}>
356
+ {mdl}
357
+ </span>
358
+ ))}
359
+ </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
360
  </div>
361
+ )}
362
  </div>
363
+ ))}
364
+ </div>
365
+ </div>
366
 
367
+ {/* ── Main Content ───────────────────────────────────────────────────── */}
368
+ <main className="flex-1 flex flex-col items-center px-3 sm:px-6 py-6 gap-5 overflow-auto">
369
+
370
+ {/* Image Upload zone */}
371
+ <div
372
+ className={`w-full max-w-3xl border-2 border-dashed rounded-2xl transition-all duration-200 cursor-pointer group
373
+ ${imagePreview
374
+ ? 'border-zinc-700/50 bg-zinc-900/30 p-2'
375
+ : 'border-zinc-700/50 hover:border-blue-500/50 bg-zinc-900/20 p-8 flex flex-col items-center justify-center min-h-[220px]'
376
+ }`}
377
+ onClick={() => !imagePreview && document.getElementById('fu').click()}
378
+ onDragOver={e => e.preventDefault()}
379
+ onDrop={e => { e.preventDefault(); if (e.dataTransfer.files[0]) handleFileSelect(e.dataTransfer.files[0]); }}
380
+ >
381
+ {imagePreview ? (
382
+ <div className="relative inline-block w-full">
383
+ <img ref={imgRef} src={imagePreview} alt="X-ray"
384
+ className="w-full max-h-[55vh] object-contain rounded-xl block bg-black" />
385
+ <canvas ref={canvasRef} className="absolute top-0 left-0 w-full h-full pointer-events-none rounded-xl" />
386
+ {maskSrc && (
387
+ <img src={maskSrc} className="absolute top-0 left-0 w-full h-full object-fill pointer-events-none opacity-50 mix-blend-screen rounded-xl" alt="Mask" />
388
  )}
389
+ {/* Replace image button */}
390
+ <button
391
+ onClick={e => { e.stopPropagation(); document.getElementById('fu').click(); }}
392
+ className="absolute top-2 right-2 bg-zinc-800/80 hover:bg-zinc-700 text-zinc-300 rounded-lg px-2 py-1 text-xs border border-zinc-700/50 backdrop-blur-sm"
393
+ >
394
+ Replace
395
+ </button>
 
 
 
396
  </div>
397
  ) : (
398
  <>
399
+ <UploadCloud size={48} className="text-zinc-600 group-hover:text-blue-400 mb-3 transition-colors" />
400
+ <p className="text-base font-medium text-zinc-400 group-hover:text-zinc-200 transition-colors">
401
+ Drag & drop an X-ray here
402
+ </p>
403
+ <p className="text-xs text-zinc-600 mt-1">or click to browse</p>
404
+ </>
405
+ )}
406
+ <input type="file" id="fu" className="hidden" accept="image/*"
407
+ onChange={e => handleFileSelect(e.target.files[0])} />
408
+ </div>
409
+
410
+ {/* Analyze Button β€” full width under uploader */}
411
+ <div className="w-full max-w-3xl">
412
+ <button
413
+ onClick={handleAPI}
414
+ disabled={!file || loading}
415
+ className={`w-full py-3.5 rounded-xl font-bold text-base flex items-center justify-center gap-2 transition-all duration-200 shadow-lg ${
416
+ !file
417
+ ? 'bg-zinc-800 text-zinc-500 cursor-not-allowed'
418
+ : loading
419
+ ? 'bg-blue-700 text-white cursor-wait'
420
+ : 'bg-gradient-to-r from-blue-600 to-indigo-600 hover:from-blue-500 hover:to-indigo-500 text-white shadow-blue-900/40'
421
+ }`}
422
+ >
423
+ {loading ? <Loader2 size={20} className="animate-spin" /> : <ScanLine size={20} />}
424
+ {loading ? 'Analysing…' : `Run AI Analysis β€” ${currentMode?.label}`}
425
+ </button>
426
+ </div>
427
 
428
+ {/* ── Results ───────────────────────────────────────────────────────── */}
429
+ {hasResults && (
430
+ <div className="w-full max-w-3xl flex flex-col gap-4 animate-fade-in">
431
+
432
+ {/* Stats row */}
433
+ <div className="flex flex-wrap gap-3 justify-center">
434
+ <div className="bg-zinc-900/60 border border-zinc-800/60 rounded-xl px-5 py-3 text-center">
435
+ <p className="text-3xl font-black text-white">{totalDetected}</p>
436
+ <p className="text-xs text-zinc-500 mt-0.5">Teeth Detected</p>
437
+ </div>
438
+ {isPipeline && (
439
+ <>
440
+ <div className="bg-zinc-900/60 border border-zinc-800/60 rounded-xl px-5 py-3 text-center">
441
+ <p className="text-3xl font-black text-white">{detectedFDIs.length}</p>
442
+ <p className="text-xs text-zinc-500 mt-0.5">FDI Labels</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
443
  </div>
444
+ <div className="bg-zinc-900/60 border border-zinc-800/60 rounded-xl px-5 py-3 text-center">
445
+ <p className="text-3xl font-black text-amber-400">{32 - detectedFDIs.length}</p>
446
+ <p className="text-xs text-zinc-500 mt-0.5">Missing</p>
 
 
 
 
 
 
 
 
 
 
 
 
 
447
  </div>
448
+ </>
449
+ )}
450
+ {uniquePipelineResults && (
451
+ <div className="bg-zinc-900/60 border border-zinc-800/60 rounded-xl px-5 py-3 text-center">
452
+ <p className="text-3xl font-black text-emerald-400">
453
+ {(uniquePipelineResults.reduce((s, r) => s + (r.confidence ?? r.score ?? 0), 0) / uniquePipelineResults.length * 100).toFixed(0)}%
454
+ </p>
455
+ <p className="text-xs text-zinc-500 mt-0.5">Avg. Confidence</p>
456
  </div>
457
  )}
458
+ </div>
459
+
460
+ {/* FDI Legend β€” only for pipeline/classification modes */}
461
+ {isPipeline && (
462
+ <div className="flex flex-wrap justify-center gap-4 text-xs">
463
+ {['Q1 Upper Right', 'Q2 Upper Left', 'Q3 Lower Left', 'Q4 Lower Right'].map((name, i) => (
464
+ <div key={i} className="flex items-center gap-1.5 text-zinc-400">
465
+ <span className="w-3 h-3 rounded-sm flex-shrink-0" style={{ background: QUADRANT_COLOURS[i] }} />
466
+ {name}
467
+ </div>
468
+ ))}
469
+ </div>
470
+ )}
471
+
472
+ {/* Detection results list (for non-pipeline modes) */}
473
+ {rawBoxes && (
474
+ <div className="bg-zinc-900/60 border border-zinc-800/60 rounded-xl p-4">
475
+ <p className="text-xs font-bold text-zinc-400 uppercase tracking-widest mb-3">Detection Results</p>
476
+ <div className="flex flex-wrap gap-2">
477
+ {rawBoxes.boxes.map((_, i) => (
478
+ <span key={i} className="px-2 py-1 rounded-lg bg-blue-500/10 border border-blue-500/30 text-blue-300 text-xs font-medium">
479
+ Tooth #{i+1} β€” {(rawBoxes.scores[i]*100).toFixed(0)}%
480
+ </span>
481
+ ))}
482
+ </div>
483
+ </div>
484
+ )}
485
+
486
+ {/* Pipeline detection brief list */}
487
+ {uniquePipelineResults && (
488
+ <div className="bg-zinc-900/60 border border-zinc-800/60 rounded-xl p-4">
489
+ <p className="text-xs font-bold text-zinc-400 uppercase tracking-widest mb-3">
490
+ {isPipeline ? 'FDI Classification Results' : 'Segmentation Results'}
491
+ </p>
492
+ <div className="flex flex-wrap gap-2">
493
+ {uniquePipelineResults.map((r, i) => {
494
+ const col = getColour(r.fdi);
495
+ return (
496
+ <span key={i}
497
+ style={{ borderColor: col+'55', color: col, background: col+'15' }}
498
+ className="px-2 py-1 rounded-lg border text-xs font-medium"
499
+ >
500
+ {isPipeline && r.fdi > 0 ? `FDI ${r.fdi}` : `Tooth ${i+1}`}
501
+ {' '}β€” {((r.confidence ?? r.score) * 100).toFixed(0)}%
502
+ </span>
503
+ );
504
+ })}
505
+ </div>
506
+ </div>
507
+ )}
508
+
509
+ {/* Odontogram β€” ONLY for full pipeline modes (requires FDI classification) */}
510
+ {isPipeline && detectedFDIs.length > 0 && (
511
+ <Odontogram detectedFDIs={detectedFDIs} />
512
+ )}
513
+ </div>
514
+ )}
515
  </main>
516
  </div>
517
  );