Spaces:
Running
Running
Upload 51 files
Browse files
src/components/MultiSourceCaptioningView.tsx
CHANGED
|
@@ -86,6 +86,7 @@ export default function MultiSourceCaptioningView() {
|
|
| 86 |
const processingVideoRef = useRef<HTMLVideoElement | null>(null);
|
| 87 |
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
| 88 |
const imageRef = useRef<HTMLImageElement | null>(null);
|
|
|
|
| 89 |
const webcamStreamRef = useRef<MediaStream | null>(null);
|
| 90 |
const { isLoaded, isLoading, error: modelError, runInference } = useVLMContext();
|
| 91 |
|
|
@@ -136,12 +137,11 @@ export default function MultiSourceCaptioningView() {
|
|
| 136 |
// Box persistence logic (2 seconds)
|
| 137 |
const now = Date.now();
|
| 138 |
if (Array.isArray(boxes) && boxes.length > 0) {
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
window._boxHistory.push(...boxes.map(box => ({ ...box, timestamp: now })));
|
| 142 |
}
|
| 143 |
// Draw all boxes from last 2 seconds
|
| 144 |
-
const boxHistory =
|
| 145 |
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 146 |
if (boxHistory.length > 0) {
|
| 147 |
const scaleX = canvas.width / video.videoWidth;
|
|
|
|
| 86 |
const processingVideoRef = useRef<HTMLVideoElement | null>(null);
|
| 87 |
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
| 88 |
const imageRef = useRef<HTMLImageElement | null>(null);
|
| 89 |
+
const boxHistoryRef = useRef<any[]>([]);
|
| 90 |
const webcamStreamRef = useRef<MediaStream | null>(null);
|
| 91 |
const { isLoaded, isLoading, error: modelError, runInference } = useVLMContext();
|
| 92 |
|
|
|
|
| 137 |
// Box persistence logic (2 seconds)
|
| 138 |
const now = Date.now();
|
| 139 |
if (Array.isArray(boxes) && boxes.length > 0) {
|
| 140 |
+
boxHistoryRef.current = boxHistoryRef.current.filter((b: any) => now - b.timestamp < 2000);
|
| 141 |
+
boxHistoryRef.current.push(...boxes.map(box => ({ ...box, timestamp: now })));
|
|
|
|
| 142 |
}
|
| 143 |
// Draw all boxes from last 2 seconds
|
| 144 |
+
const boxHistory = boxHistoryRef.current.filter((b: any) => now - b.timestamp < 2000);
|
| 145 |
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
| 146 |
if (boxHistory.length > 0) {
|
| 147 |
const scaleX = canvas.width / video.videoWidth;
|