Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | 'use client' import { useState } from 'react' import Link from 'next/link' import { css } from '../../../../../../../styled-system/css' import { ModelTester } from '../../ModelTester' import { useTrainingDiagnostics, type DiagnosticReason } from '../../TrainingDiagnosticsContext' import { isColumnClassifierResult, isBoundaryDetectorResult, type TrainingResult } from '../types' interface ResultsCardProps { result: TrainingResult | null error: string | null configuredEpochs: number onTrainAgain: () => void onRerunTraining?: () => void } export function ResultsCard({ result, error, configuredEpochs, onTrainAgain, onRerunTraining, }: ResultsCardProps) { const [activeTab, setActiveTab] = useState<'results' | 'test'>('results') const diagnostics = useTrainingDiagnostics() if (error) { return ( <div className={css({ textAlign: 'center', py: 4 })}> <div className={css({ fontSize: '3xl', mb: 3 })}>❌</div> <div className={css({ fontSize: 'lg', fontWeight: 'bold', color: 'red.400', mb: 2, })} > Training Failed </div> <div className={css({ color: 'gray.300', fontSize: 'sm', mb: 4, p: 3, bg: 'red.900/30', border: '1px solid', borderColor: 'red.800', borderRadius: 'lg', textAlign: 'left', fontFamily: 'mono', whiteSpace: 'pre-wrap', wordBreak: 'break-word', maxHeight: '150px', overflow: 'auto', })} > {error} </div> <button type="button" onClick={onTrainAgain} className={css({ px: 6, py: 3, bg: 'blue.600', color: 'white', borderRadius: 'lg', border: 'none', cursor: 'pointer', fontWeight: 'bold', fontSize: 'md', _hover: { bg: 'blue.500' }, })} > Try Again </button> </div> ) } if (!result) { return ( <div className={css({ textAlign: 'center', py: 6 })}> <div className={css({ fontSize: '2xl', mb: 3, animation: 'spin 1s linear infinite', })} > ⏳ </div> <div className={css({ color: 'gray.400' })}>Waiting for results...</div> </div> ) } const accuracy = result.final_accuracy ?? 0 const isColumnClassifier = isColumnClassifierResult(result) const isBoundaryDetector = isBoundaryDetectorResult(result) return ( <div> {/* Tabs - only show test tab for column classifier (boundary detector testing not yet implemented) */} <div className={css({ display: 'flex', gap: 1, mb: 4, borderBottom: '1px solid', borderColor: 'gray.700', })} > <button type="button" onClick={() => setActiveTab('results')} className={css({ px: 4, py: 2, bg: 'transparent', color: activeTab === 'results' ? 'green.400' : 'gray.500', border: 'none', borderBottom: '2px solid', borderColor: activeTab === 'results' ? 'green.400' : 'transparent', cursor: 'pointer', fontWeight: 'medium', fontSize: 'sm', _hover: { color: 'gray.300' }, })} > Results </button> {isColumnClassifier && ( <button type="button" onClick={() => setActiveTab('test')} className={css({ px: 4, py: 2, bg: 'transparent', color: activeTab === 'test' ? 'purple.400' : 'gray.500', border: 'none', borderBottom: '2px solid', borderColor: activeTab === 'test' ? 'purple.400' : 'transparent', cursor: 'pointer', fontWeight: 'medium', fontSize: 'sm', _hover: { color: 'gray.300' }, })} > 🔬 Test Model </button> )} </div> {/* Tab content */} {activeTab === 'results' ? ( <div className={css({ textAlign: 'center' })}> {/* Success icon */} <div className={css({ fontSize: '3xl', mb: 2 })}>🎉</div> {/* Title */} <div className={css({ fontSize: 'lg', fontWeight: 'bold', color: 'green.400', mb: 3, })} > Training Complete! </div> {/* Main metric - pixel error for boundary detector, accuracy for column classifier */} {isBoundaryDetector && result.final_pixel_error !== undefined ? ( <> <div className={css({ fontSize: '4xl', fontWeight: 'bold', color: 'orange.400', mb: 0.5, })} > {result.final_pixel_error.toFixed(1)}px </div> <div className={css({ fontSize: 'sm', color: 'gray.500', mb: 4 })}> Avg Corner Error </div> </> ) : ( <> <div className={css({ fontSize: '4xl', fontWeight: 'bold', color: 'green.400', mb: 0.5, })} > {(accuracy * 100).toFixed(1)}% </div> <div className={css({ fontSize: 'sm', color: 'gray.500', mb: 4 })}> Final Accuracy </div> </> )} {/* Stats grid */} <div className={css({ display: 'grid', gridTemplateColumns: 'repeat(3, 1fr)', gap: 2, p: 3, bg: 'gray.900', borderRadius: 'lg', fontSize: 'sm', mb: 4, })} > <div> <div className={css({ color: 'gray.600', fontSize: 'xs' })}>Epochs</div> <div className={css({ fontFamily: 'mono', color: 'gray.300', fontWeight: 'medium', })} > {result.epochs_trained ?? '—'} {result.epochs_trained && result.epochs_trained < configuredEpochs && ( <span className={css({ color: 'gray.500' })}>/{configuredEpochs}</span> )} </div> {result.epochs_trained && result.epochs_trained < configuredEpochs && ( <div className={css({ color: 'green.500', fontSize: 'xs', fontWeight: 'medium', })} > converged </div> )} </div> <div> <div className={css({ color: 'gray.600', fontSize: 'xs' })}>Final Loss</div> <div className={css({ fontFamily: 'mono', color: 'gray.300', fontWeight: 'medium', })} > {result.final_loss?.toFixed(4) ?? '—'} </div> </div> <div> <div className={css({ color: 'gray.600', fontSize: 'xs' })}>Model</div> <div className={css({ color: 'green.400', fontWeight: 'medium' })}> {result.tfjs_exported ? '✓ Saved' : '—'} </div> </div> </div> {/* Per-head accuracy breakdown (column classifier only) */} {isColumnClassifier && result.heaven_accuracy !== undefined && result.earth_accuracy !== undefined && ( <div className={css({ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: 2, p: 3, bg: 'gray.900', borderRadius: 'lg', fontSize: 'sm', mb: 4, })} > <div> <div className={css({ color: 'gray.600', fontSize: 'xs' })}>Heaven (5s bead)</div> <div className={css({ fontFamily: 'mono', color: 'purple.400', fontWeight: 'medium', })} > {(result.heaven_accuracy * 100).toFixed(1)}% </div> </div> <div> <div className={css({ color: 'gray.600', fontSize: 'xs' })}>Earth (1s beads)</div> <div className={css({ fontFamily: 'mono', color: 'blue.400', fontWeight: 'medium', })} > {(result.earth_accuracy * 100).toFixed(1)}% </div> </div> </div> )} {/* Pixel error quality indicator (boundary detector only) */} {isBoundaryDetector && result.final_pixel_error !== undefined && ( <div className={css({ p: 3, bg: 'gray.900', borderRadius: 'lg', fontSize: 'sm', mb: 4, textAlign: 'center', })} > <div className={css({ color: 'gray.600', fontSize: 'xs', mb: 1 })}>Quality</div> <div className={css({ fontWeight: 'medium', fontSize: 'md', color: result.final_pixel_error < 5 ? 'green.400' : result.final_pixel_error < 10 ? 'yellow.400' : 'orange.400', })} > {result.final_pixel_error < 5 ? '✓ Excellent' : result.final_pixel_error < 10 ? '◐ Good' : result.final_pixel_error < 15 ? '○ Acceptable' : '⚠ Needs more data'} </div> <div className={css({ fontSize: 'xs', color: 'gray.500', mt: 1 })}> <5px excellent, <10px good, <15px acceptable </div> </div> )} {/* Model path */} {result.tfjs_exported && ( <div className={css({ fontSize: 'xs', color: 'gray.500', mb: 4 })}> Model exported and ready to use </div> )} {/* Remediation advice for poor results */} {diagnostics.shouldShowRemediation && ( <RemediationSection reasons={diagnostics.reasons} /> )} {/* Action buttons */} <div className={css({ display: 'flex', gap: 3, justifyContent: 'center', flexWrap: 'wrap', })} > {/* Re-run Training button (same config, train immediately) */} {onRerunTraining && ( <button type="button" onClick={onRerunTraining} className={css({ px: 5, py: 2.5, bg: 'green.600', color: 'white', borderRadius: 'lg', border: 'none', cursor: 'pointer', fontWeight: 'bold', fontSize: 'sm', display: 'flex', alignItems: 'center', gap: 2, _hover: { bg: 'green.500' }, })} > <span>🔄</span> <span>Re-run Training</span> </button> )} {/* Start Over button (go back to model selection) */} <button type="button" onClick={onTrainAgain} className={css({ px: 5, py: 2.5, bg: 'gray.700', color: 'white', borderRadius: 'lg', border: 'none', cursor: 'pointer', fontWeight: 'medium', fontSize: 'sm', display: 'flex', alignItems: 'center', gap: 2, _hover: { bg: 'gray.600' }, })} > <span>⏮</span> <span>Start Over</span> </button> {/* View All Sessions link */} <Link href="/vision-training/sessions" className={css({ px: 5, py: 2.5, bg: 'blue.600', color: 'white', borderRadius: 'lg', textDecoration: 'none', fontWeight: 'medium', fontSize: 'sm', display: 'flex', alignItems: 'center', gap: 2, _hover: { bg: 'blue.500' }, })} > <span>📋</span> <span>View Sessions</span> </Link> </div> </div> ) : isColumnClassifier ? ( <ModelTester columnCount={4} /> ) : ( <div className={css({ textAlign: 'center', py: 4, color: 'gray.400' })}> <div className={css({ fontSize: '2xl', mb: 2 })}>🎯</div> <div className={css({ mb: 2 })}>Boundary detector testing coming soon</div> <div className={css({ fontSize: 'xs', color: 'gray.500' })}> The model is ready to use in marker-free calibration mode </div> </div> )} </div> ) } /** Shows diagnostic reasons and remediation advice for poor training results */ function RemediationSection({ reasons }: { reasons: DiagnosticReason[] }) { if (reasons.length === 0) return null return ( <div data-element="remediation-section" className={css({ mt: 4, mb: 4, p: 3, bg: 'yellow.900/30', border: '1px solid', borderColor: 'yellow.700', borderRadius: 'lg', textAlign: 'left', })} > <div className={css({ display: 'flex', alignItems: 'center', gap: 2, mb: 2, fontWeight: 'semibold', color: 'yellow.400', fontSize: 'sm', })} > <span>⚠️</span> <span>Why is accuracy low?</span> </div> <div className={css({ display: 'flex', flexDirection: 'column', gap: 2 })}> {reasons.map((reason, i) => ( <div key={i} className={css({ fontSize: 'xs' })}> <div className={css({ color: 'gray.200', fontWeight: 'medium' })}>• {reason.title}</div> <div className={css({ color: 'gray.400', ml: 3 })}>{reason.action}</div> </div> ))} </div> </div> ) } |