File size: 6,133 Bytes
ea15c76 263280b ea15c76 263280b ea15c76 263280b ea15c76 263280b ea15c76 263280b ea15c76 263280b ea15c76 263280b ea15c76 263280b ea15c76 263280b ea15c76 263280b ea15c76 263280b ea15c76 263280b | 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 | import { Copy, Info, MessageSquareText, Play, RotateCcw, Save } from 'lucide-react';
interface TranslationOutputProps {
currentStep: number;
isProcessing: boolean;
onStartTranslation: () => void;
onReset: () => void;
onCopy: () => void;
onSaveResult: () => void;
canStart: boolean;
prediction: {
label: string;
score: number;
elapsed_ms: number;
} | null;
hasSavedCurrent: boolean;
error: string | null;
}
export function TranslationOutput({
currentStep,
isProcessing,
onStartTranslation,
onReset,
onCopy,
onSaveResult,
canStart,
prediction,
hasSavedCurrent,
error,
}: TranslationOutputProps) {
const isComplete = Boolean(prediction) && !isProcessing;
const confidencePercent = prediction ? (prediction.score * 100).toFixed(1) : '--';
const confidenceLevel = prediction
? prediction.score >= 0.85
? 'High'
: prediction.score >= 0.6
? 'Medium'
: 'Low'
: '--';
const processingTime = prediction
? `${(prediction.elapsed_ms / 1000).toFixed(2)}s`
: '--s';
return (
<div className="mb-6 rounded-lg border border-gray-200 bg-white p-6">
<div className="mb-4 flex items-center justify-between">
<div>
<h2 className="mb-1 text-xl">Translation Output</h2>
<p className="text-sm text-gray-600">Translated English text with confidence score</p>
</div>
<div className="flex gap-2">
<button
onClick={onCopy}
disabled={!prediction}
className={`flex items-center gap-1.5 rounded border px-3 py-1.5 text-xs ${
prediction
? 'border-gray-300 hover:bg-gray-50'
: 'cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400'
}`}
>
<Copy className="h-3.5 w-3.5" />
Copy
</button>
</div>
</div>
<div className="mb-6 flex min-h-[160px] flex-col items-center justify-center rounded-lg border border-gray-200 bg-gray-50 p-10">
{error ? (
<div className="text-center">
<div className="mb-2 text-2xl text-red-600">Error</div>
<div className="text-sm text-gray-500">{error}</div>
</div>
) : isComplete && prediction ? (
<div className="text-center">
<div className="mb-2 text-3xl">"{prediction.label}"</div>
<div className="text-sm text-gray-500">Translation complete</div>
</div>
) : currentStep >= 3 ? (
<div className="text-center">
<MessageSquareText className="mx-auto mb-2 h-8 w-8 text-gray-300" />
<div className="text-gray-500">Translation in progress...</div>
<div className="text-xs text-gray-400">Processing through Transformer model</div>
</div>
) : (
<div className="text-center">
<MessageSquareText className="mx-auto mb-2 h-8 w-8 text-gray-300" />
<div className="text-gray-400">Translation will appear here</div>
<div className="text-xs text-gray-400">Start processing to see results</div>
</div>
)}
</div>
<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
<div className="rounded-lg border border-gray-200 p-4">
<div className="mb-2 flex items-center justify-between">
<div className="text-sm text-gray-600">Accuracy Score</div>
<Info
className="h-3.5 w-3.5 text-gray-400"
title="Model confidence for the top predicted label"
/>
</div>
<div className="text-2xl font-medium">{prediction ? `${confidencePercent}%` : '--%'}</div>
</div>
<div className="rounded-lg border border-gray-200 p-4">
<div className="mb-2 flex items-center justify-between">
<div className="text-sm text-gray-600">Confidence Level</div>
<Info
className="h-3.5 w-3.5 text-gray-400"
title="High: >=85%, Medium: >=60%, Low: <60%"
/>
</div>
<div className="text-2xl font-medium">{confidenceLevel}</div>
</div>
<div className="rounded-lg border border-gray-200 p-4">
<div className="mb-2 flex items-center justify-between">
<div className="text-sm text-gray-600">Processing Time</div>
<Info
className="h-3.5 w-3.5 text-gray-400"
title="End-to-end backend response time for this prediction"
/>
</div>
<div className="text-2xl font-medium">{processingTime}</div>
</div>
</div>
<div className="mt-6 flex items-center justify-between border-t border-gray-200 pt-6">
<button
onClick={onReset}
className="flex items-center gap-2 rounded-lg border border-gray-300 bg-white px-6 py-2.5 hover:bg-gray-50"
>
<RotateCcw className="h-4 w-4" />
Reset
</button>
<div className="flex gap-3">
<button
onClick={onSaveResult}
disabled={!isComplete}
className={`flex items-center gap-2 rounded-lg border px-6 py-2.5 ${
isComplete
? 'border-gray-300 bg-white hover:bg-gray-50'
: 'cursor-not-allowed border-gray-200 bg-gray-100 text-gray-400'
}`}
>
<Save className="h-4 w-4" />
{hasSavedCurrent ? 'Saved' : 'Save Results'}
</button>
<button
onClick={onStartTranslation}
disabled={!canStart || isProcessing}
className={`flex items-center gap-2 rounded-lg px-6 py-2.5 ${
!canStart || isProcessing
? 'cursor-not-allowed bg-gray-300 text-gray-500'
: 'bg-black text-white hover:bg-gray-800'
}`}
>
<Play className="h-4 w-4" />
{isProcessing ? 'Processing...' : 'Start Translation'}
</button>
</div>
</div>
</div>
);
}
|