import React from 'react'; import { motion } from 'framer-motion'; import { Pause, Play, Square, Loader2, AlertTriangle, Cpu, Activity, Database, Server } from 'lucide-react'; import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip as RechartsTooltip, ResponsiveContainer, Legend } from 'recharts'; import { CVTrainingJob } from '@/types/cv'; import { useUserStore } from '@/store/userStore'; interface Props { job: CVTrainingJob; onPause: () => void; onResume: () => void; onStop: () => void; } const CVTrainingMonitor: React.FC = ({ job, onPause, onResume, onStop }) => { const { isDark } = useUserStore(); const progress = job.progress || {}; const totalEpochs = progress.totalEpochs || 1; const currentEpoch = progress.epoch || 0; let percentComplete = Math.round((currentEpoch / totalEpochs) * 100) || 0; if (job.status === 'failed') percentComplete = 0; const systemStats = progress.systemStats || { gpuUsage: 0, vramUsage: '0GB', cpuUsage: 0, ramUsage: '0GB' }; const metrics = progress.metrics || {}; const logs = progress.logs || []; // Training history is produced by the trainer. Do not display synthetic curves. const chartData = (((metrics as any).loss_history || (progress as any).history || []) as any[]).map((point: any, index: number) => ({ epoch: point.epoch ?? index + 1, loss: point.loss ?? point.train_loss ?? 0, map: point.mAP50 ?? point.map ?? 0, })); if (!chartData.length && currentEpoch > 0) { chartData.push({ epoch: currentEpoch, loss: progress.loss ?? 0, map: metrics.mAP50 ?? 0 }); } return (
{job.status === 'failed' && (

Training Failed

{job.error || 'An unknown error occurred during training.'}

)} {/* Top Status Bar */}
{job.status === 'running' ? ( ) : job.status === 'paused' ? ( ) : job.status === 'completed' ? (
) : ( )}

{percentComplete}% Complete

Epoch {currentEpoch} of {totalEpochs} • {job.mode?.toUpperCase() || 'FAST'} Mode

{job.status === 'running' && ( )} {job.status === 'paused' && ( )} {(job.status === 'running' || job.status === 'paused') && ( )}
{/* Main Charts Area */}

Training Metrics

training_logs.sh

{logs.map((log, i) => (
$ {log}
))} {job.status === 'running' && (
$_
)}
{/* System Stats Sidebar */}

System Monitor

GPU Usage {systemStats.gpuUsage}%
VRAM {systemStats.vramUsage} / 16GB
CPU {systemStats.cpuUsage}%
{/* Current Metrics Snapshot */}

Current Performance

Loss
{(progress.loss || 0).toFixed(3)}
mAP50
{(metrics.mAP50 || 0).toFixed(3)}
Precision
{(metrics.precision || 0).toFixed(3)}
Recall
{(metrics.recall || 0).toFixed(3)}
); }; export default CVTrainingMonitor;