Rework Analyze page
Browse filesFiles changed (2)
123421 unmodified lines262728293031321 unmodified line343536373839409 unmodified lines505152535455561 unmodified line5859606162636465export default function FrameGrid({ frames = [], predictions = [] }) {const items = frames.map((frame, idx) => {const pred = predictions[idx] || {};const label = (pred.label || "").toLowerCase();21 unmodified lines});if (!items.length) {return <div className="text-sm text-gray-500 dark:text-gray-400">No frames returned from the backend yet.</div>;}return (1 unmodified line{items.map((item) => (<divkey={item.idx}className="rounded-lg border border-gray-200 bg-white overflow-hidden shadow-sm dark:bg-gray-900 dark:border-gray-800"><div className="relative aspect-video bg-black">{item.src ? (9 unmodified lines{item.label ? item.label.toUpperCase() : "N/A"}</span></div><div className="px-2 py-1.5 flex items-center justify-between text-[11px] text-gray-600 dark:text-gray-300"><span>Frame {item.idx}</span>{item.hasFace ? (<span className="flex items-center gap-1">1 unmodified line<span>{item.score.toFixed(3)}</span></span>) : (<span className="flex items-center gap-1 text-gray-400"><span className="h-1.5 w-1.5 rounded-full bg-gray-400" /><span>No face</span></span>)}123421 unmodified lines262728293031321 unmodified line34353637383940419 unmodified lines515253545556571 unmodified line5960616263646566export default function FrameGrid({ frames = [], predictions = [], onFrameClick }) {const items = frames.map((frame, idx) => {const pred = predictions[idx] || {};const label = (pred.label || "").toLowerCase();21 unmodified lines});if (!items.length) {return <div className="text-sm text-emerald-200/80">No frames returned from the backend yet.</div>;}return (1 unmodified line{items.map((item) => (<divkey={item.idx}onClick={() => onFrameClick && onFrameClick(item.idx)}className="rounded-lg border border-emerald-900 bg-slate-950 overflow-hidden shadow-sm shadow-emerald-900/40 cursor-pointer hover:border-emerald-500 transition"><div className="relative aspect-video bg-black">{item.src ? (9 unmodified lines{item.label ? item.label.toUpperCase() : "N/A"}</span></div><div className="px-2 py-1.5 flex items-center justify-between text-[11px] text-emerald-100/80"><span>Frame {item.idx}</span>{item.hasFace ? (<span className="flex items-center gap-1">1 unmodified line<span>{item.score.toFixed(3)}</span></span>) : (<span className="flex items-center gap-1 text-emerald-300/60"><span className="h-1.5 w-1.5 rounded-full bg-slate-500" /><span>No face</span></span>)}
6 unmodified lines78910111222 unmodified lines35363738394026 unmodified lines6768697071727338 unmodified lines1121131141151161171181194 unmodified lines1241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661673 unmodified lines1711721731741751766 unmodified linesconst [loading, setLoading] = useState(false);const [error, setError] = useState("");const [result, setResult] = useState(null);const fileInputRef = useRef(null);const onFileChange = (e) => {22 unmodified linese.preventDefault();};const onSubmit = async (e) => {e.preventDefault();setError("");26 unmodified lines<div className="min-h-screen"><header className="bg-slate-950 border-b border-emerald-900"><div className="max-w-7xl mx-auto px-4 py-4 flex items-center justify-between"><h1 className="text-xl font-semibold">Analyze a Video</h1><div className="flex items-center gap-3" /></div></header>38 unmodified lines)}</div><form onSubmit={onSubmit} className="bg-slate-950 border border-emerald-900 rounded-xl p-5 shadow-md shadow-emerald-900/40 flex flex-col gap-3"><div className="flex items-center gap-3"><buttontype="submit"disabled={loading || !videoFile}4 unmodified lines)}{loading ? "Processing..." : "Analyze Video"}</button>{error && <span className="text-red-400 text-sm">{error}</span>}{!videoFile && <span className="text-sm text-emerald-200/80">Select a video to start.</span>}</div>{loading && (<div className="w-full space-y-1"><div className="h-1 w-full bg-slate-800 rounded-full overflow-hidden"><div className="h-full w-1/2 bg-gradient-to-r from-emerald-400 to-emerald-600 animate-pulse" /></div><p className="text-xs text-emerald-200/75">Analyzing video, this may take a moment…</p></div>)}</form></section><aside className="space-y-4"><div className="bg-slate-950 border border-emerald-900 rounded-xl p-5 shadow-md shadow-emerald-900/40"><h2 className="text-lg font-semibold mb-2">Final Conclusion</h2><p className="text-sm text-emerald-200/80 mb-3">Aggregated across all extracted frames</p>{result ? (<div className="flex items-center gap-3 mb-3"><span className={`px-3 py-1.5 rounded text-xs tracking-wide font-mono ${result.final_label === 'fake' ? 'bg-red-500 text-white' : 'bg-emerald-500 text-slate-950'}`}>{result.final_label.toUpperCase()}</span>{result.final_label === 'fake' && (<span className="text-sm text-emerald-200/80">avg fake prob: {result.final_score.toFixed(3)}</span>)}</div>) : (<div className="text-sm text-emerald-300/70 mb-3">Run analysis to see results here.</div>)}{result && (<div className="border-t border-gray-200 dark:border-gray-700 mt-3 pt-3 max-h-[480px] overflow-y-auto"><h3 className="text-sm font-semibold mb-2">Frames & predictions</h3><FrameGrid frames={result.frames} predictions={result.predictions} /></div>)}</div></aside>3 unmodified lines</main><footer className="text-center text-xs text-gray-500 dark:text-gray-400 py-8">© {new Date().getFullYear()} Deepfake Detector</footer></div>);}6 unmodified lines7891011121322 unmodified lines3637383940414243444546474849505152535455565758596026 unmodified lines8788899091929394959697989910010138 unmodified lines1401411421431441451461474 unmodified lines1521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232243 unmodified lines2282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183196 unmodified linesconst [loading, setLoading] = useState(false);const [error, setError] = useState("");const [result, setResult] = useState(null);const [selectedFrameIndex, setSelectedFrameIndex] = useState(null);const fileInputRef = useRef(null);const onFileChange = (e) => {22 unmodified linese.preventDefault();};const handleFrameClick = (idx) => {if (!result || !result.frames || !result.frames.length) return;setSelectedFrameIndex(idx);};const closeFrameModal = () => setSelectedFrameIndex(null);const showPrevFrame = () => {if (!result || !result.frames || selectedFrameIndex === null) return;setSelectedFrameIndex((prev) => (prev > 0 ? prev - 1 : prev));};const showNextFrame = () => {if (!result || !result.frames || selectedFrameIndex === null) return;setSelectedFrameIndex((prev) =>prev < result.frames.length - 1 ? prev + 1 : prev);};const onSubmit = async (e) => {e.preventDefault();setError("");26 unmodified lines<div className="min-h-screen"><header className="bg-slate-950 border-b border-emerald-900"><div className="max-w-7xl mx-auto px-4 py-4 flex items-center justify-between"><div className="flex items-center gap-3"><div className="h-8 w-8 rounded-lg bg-emerald-500/20 border border-emerald-500/70 flex items-center justify-center text-emerald-300 font-mono text-xs">FF</div><div className="flex flex-col leading-tight"><span className="text-xs uppercase tracking-[0.2em] text-emerald-400/80">FaceForensics Lab</span><h1 className="text-sm md:text-base font-semibold">Deepfake Detection · Analysis</h1></div></div><div className="flex items-center gap-3" /></div></header>38 unmodified lines)}</div><form onSubmit={onSubmit} className="bg-slate-950 border border-emerald-900 rounded-xl p-5 shadow-md shadow-emerald-900/40 flex flex-col gap-2"><div className="flex items-center gap-3 w-full"><buttontype="submit"disabled={loading || !videoFile}4 unmodified lines)}{loading ? "Processing..." : "Analyze Video"}</button>{loading && (<div className="flex-1 min-w-[120px]"><div className="h-1 w-full bg-slate-800 rounded-full overflow-hidden"><div className="h-full w-1/2 bg-gradient-to-r from-emerald-400 to-emerald-600 animate-pulse" /></div></div>)}</div><div className="flex flex-col gap-1">{error && <span className="text-red-400 text-sm">{error}</span>}{!videoFile && <span className="text-sm text-emerald-200/80">Select a video to start.</span>}{!loading && result && (<span className="text-xs text-emerald-300/80">Tip: click a frame to view it larger.</span>)}</div></form></section><aside className="space-y-4"><div className="bg-slate-950 border border-emerald-900 rounded-xl p-5 shadow-md shadow-emerald-900/40">{result ? (<div className="border-t border-gray-800 pt-3 max-h-[480px] overflow-y-auto"><h3 className="text-sm font-semibold mb-2">Frames & predictions</h3><FrameGridframes={result.frames}predictions={result.predictions}onFrameClick={handleFrameClick}/></div>) : (<div className="text-sm text-emerald-300/70">Run analysis to see frames and predictions here.</div>)}</div><div className="bg-slate-950 border border-emerald-900 rounded-xl p-5 shadow-md shadow-emerald-900/40"><h2 className="text-lg font-semibold mb-2">Final conclusion</h2><p className="text-sm text-emerald-200/80 mb-3">Overall confidence based on all faces found.</p>{result ? ((() => {const fakeProb = typeof result.final_score === "number" ? result.final_score : 0;const realProb = 1 - fakeProb;const isFake = result.final_label === "fake";const percent = Math.round((isFake ? fakeProb : realProb) * 100);const labelText = isFake ? "FAKE" : "REAL";const barColor = isFake ? "bg-red-500" : "bg-emerald-500";return (<div className="space-y-2"><div className="flex items-center justify-between text-xs font-mono text-emerald-200/80"><span>{labelText} confidence</span><span>{percent}%</span></div><div className="h-2 w-full rounded-full bg-slate-800 overflow-hidden"><divclassName={`${barColor} h-full transition-all`}style={{ width: `${percent}%` }}/></div><p className="text-xs text-emerald-300/80">This bar shows how strongly the model leans toward {labelText.toLowerCase()} for thisvideo.</p></div>);})()) : (<div className="text-sm text-emerald-300/70">Run an analysis to see the final confidence bar.</div>)}</div></aside>3 unmodified lines</main><footer className="text-center text-xs text-gray-500 dark:text-gray-400 py-8">© {new Date().getFullYear()} Deepfake Detector</footer>{selectedFrameIndex !== null && result && result.frames && ((() => {const idx = selectedFrameIndex;const frame = result.frames[idx];const pred = (result.predictions || [])[idx] || {};const label = (pred.label || "").toLowerCase();const fakeProb = typeof pred.prob_fake === "number" ? pred.prob_fake : pred.score ?? 0;const realProb = typeof pred.prob_real === "number" ? pred.prob_real : 1 - fakeProb;const src = frame?.startsWith("data:") ? frame : `data:image/png;base64,${frame || ""}`;const labelClass =label === "fake"? "bg-red-500 text-white": label === "real"? "bg-emerald-500 text-slate-950": "bg-slate-500 text-white";return (<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/80 px-4" onClick={closeFrameModal}><divclassName="max-w-4xl w-full bg-slate-950 border border-emerald-800 rounded-xl shadow-2xl shadow-emerald-900/60 p-4 md:p-5"onClick={(e) => e.stopPropagation()}><div className="flex items-center justify-between mb-3"><div className="space-y-1"><div className="flex items-center gap-3 text-xs font-mono text-emerald-200/80"><span className="px-2 py-0.5 rounded-full bg-slate-900 border border-emerald-800">Frame {idx}</span><span className={`px-2 py-0.5 rounded-full text-[10px] ${labelClass}`}>{label ? label.toUpperCase() : "N/A"}</span></div><div className="text-[11px] text-emerald-200/80">REAL: {realProb.toFixed(3)} · FAKE: {fakeProb.toFixed(3)}</div></div><buttontype="button"onClick={closeFrameModal}className="text-xs text-emerald-200/80 hover:text-emerald-100">Close</button></div><div className="w-full rounded-lg border border-emerald-900 overflow-hidden bg-black mb-3">{src ? (<imgsrc={src}alt={`Frame ${idx}`}className="w-full h-auto max-h-[60vh] object-contain"/>) : (<div className="w-full h-64 flex items-center justify-center text-sm text-emerald-300/70">No image for this frame.</div>)}</div><div className="flex items-center justify-between text-xs text-emerald-200/80 mt-2"><div className="flex items-center gap-2"><buttontype="button"onClick={showPrevFrame}disabled={idx === 0}className="px-3 py-1 rounded border border-emerald-800 disabled:opacity-40 hover:bg-emerald-500/10">← Previous</button><buttontype="button"onClick={showNextFrame}disabled={idx >= result.frames.length - 1}className="px-3 py-1 rounded border border-emerald-800 disabled:opacity-40 hover:bg-emerald-500/10">Next →</button></div><span>{idx + 1} / {result.frames.length}</span></div></div></div>);})())}</div>);}
frontend/components/FrameGrid.jsx+7-6
frontend/pages/analyze.jsx+171-28