Fix frame display colors and add analyze progress bar
Browse filesFiles changed (2)
- app.py+3-5
- frontend/pages/analyze.jsx+23-13
106 unmodified lines107108109110111112113114193 unmodified lines308309310311312313314315316106 unmodified linesdef b64_encode_image_bgr(img: np.ndarray) -> str:img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)ok, buf = cv2.imencode(".png", img_rgb)if not ok:raise RuntimeError("Failed to encode frame")return base64.b64encode(buf.tobytes()).decode("utf-8")193 unmodified lineslabel = "fake" if p_fake >= p_real else "real"score = p_fake if label == "fake" else p_real# For display, always show the original video frame (not the# preprocessed / cropped face), so colors and aspect ratio match# what the user sees in the video preview.img_for_display = crop if has_face and crop is not None else orig_frameframe_b64 = b64_encode_image_bgr(img_for_display)106 unmodified lines107108109110111112113114115193 unmodified lines309310311312313314106 unmodified linesdef b64_encode_image_bgr(img: np.ndarray) -> str:# Keep original BGR colors as they appear in the video; OpenCV's# encoders expect BGR, so we don't convert to RGB here.ok, buf = cv2.imencode(".png", img)if not ok:raise RuntimeError("Failed to encode frame")return base64.b64encode(buf.tobytes()).decode("utf-8")193 unmodified lineslabel = "fake" if p_fake >= p_real else "real"score = p_fake if label == "fake" else p_realimg_for_display = crop if has_face and crop is not None else orig_frameframe_b64 = b64_encode_image_bgr(img_for_display)
129 unmodified lines130131132133134135136137138139140141142143144145146147148129 unmodified lines)}</div><form onSubmit={onSubmit} className="bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-5 shadow-sm flex items-center gap-3"><buttontype="submit"disabled={loading || !videoFile}className="px-4 py-2 rounded bg-blue-600 text-white disabled:opacity-50 inline-flex items-center gap-2">{loading && (<span className="inline-block h-4 w-4 border-2 border-white/50 border-t-white rounded-full animate-spin"></span>)}{loading ? "Processing..." : "Analyze Video"}</button>{error && <span className="text-red-500 dark:text-red-400 text-sm">{error}</span>}{!videoFile && <span className="text-sm text-gray-600 dark:text-gray-400">Select a video to start.</span>}</form></section>129 unmodified lines130131132133134135136137138139140141142143144145146147148149150151152153154155156157158129 unmodified lines)}</div><form onSubmit={onSubmit} className="bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-xl p-5 shadow-sm flex flex-col gap-3"><div className="flex items-center gap-3"><buttontype="submit"disabled={loading || !videoFile}className="px-4 py-2 rounded bg-blue-600 text-white disabled:opacity-50 inline-flex items-center gap-2">{loading && (<span className="inline-block h-4 w-4 border-2 border-white/50 border-t-white rounded-full animate-spin"></span>)}{loading ? "Processing..." : "Analyze Video"}</button>{error && <span className="text-red-500 dark:text-red-400 text-sm">{error}</span>}{!videoFile && <span className="text-sm text-gray-600 dark:text-gray-400">Select a video to start.</span>}</div>{loading && (<div className="w-full space-y-1"><div className="h-1 w-full bg-gray-200 dark:bg-gray-700 rounded-full overflow-hidden"><div className="h-full w-1/2 bg-blue-500 dark:bg-blue-400 animate-pulse" /></div><p className="text-xs text-gray-500 dark:text-gray-400">Analyzing video, this may take a moment…</p></div>)}</form></section>
app.py+3-5
frontend/pages/analyze.jsx+23-13