'use client'; // Color palette for labels const LABEL_COLORS = [ ['bg-green-100 text-green-800', 'bg-green-400'], ['bg-blue-100 text-blue-800', 'bg-blue-400'], ['bg-purple-100 text-purple-800', 'bg-purple-400'], ['bg-yellow-100 text-yellow-800', 'bg-yellow-400'], ['bg-pink-100 text-pink-800', 'bg-pink-400'], ['bg-indigo-100 text-indigo-800', 'bg-indigo-400'], ["bg-red-100 text-red-800", "bg-red-400"], ["bg-teal-100 text-teal-800", "bg-teal-400"], ["bg-orange-100 text-orange-800", "bg-orange-400"], ]; // Deterministically assign a color to each label const labelColorMap: Record = {}; let colorIndex = 0; function getColorForLabel(label: string): string[] { if (!(label in labelColorMap)) { labelColorMap[label] = colorIndex % LABEL_COLORS.length; colorIndex++; } return LABEL_COLORS[labelColorMap[label]]; } export function ClassificationResultDisplay({ result, ready, task, }: { result: any; ready: boolean | null; task: string; // getColorForLabel: (label: string) => string[]; }) { if (ready === null) { return null; } if (!ready || !result) { return (
Results will appear here
); } if (task === 'image-classification') { return (

{result[0].label}

Confidence: {(result[0].score * 100).toFixed(2)}%
{result.slice(1).map((item: any) => (
{item.label} {(item.score * 100).toFixed(2)}%
))}
); } // Default: text-classification return (

{result[0].label}

Confidence: {(result[0].score * 100).toFixed(2)}%
{result.slice(1).map((item: any) => (
{item.label} {(item.score * 100).toFixed(2)}%
))}
); }