Spaces:
Running
Running
Upload 36 files
Browse files
src/components/MultiSourceCaptioningView.tsx
CHANGED
@@ -30,6 +30,9 @@ export default function MultiSourceCaptioningView() {
|
|
30 |
const [imageProcessed, setImageProcessed] = useState(false);
|
31 |
const [exampleProcessing, setExampleProcessing] = useState(false);
|
32 |
const [urlProcessing, setUrlProcessing] = useState(false);
|
|
|
|
|
|
|
33 |
|
34 |
const videoRef = useRef<HTMLVideoElement | null>(null);
|
35 |
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
@@ -94,6 +97,7 @@ export default function MultiSourceCaptioningView() {
|
|
94 |
getContext: () => ctx,
|
95 |
} as unknown as HTMLVideoElement;
|
96 |
const result = await runInference(fakeVideo, prompt);
|
|
|
97 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
98 |
const boxes = extractJsonFromMarkdown(result) || [];
|
99 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
@@ -134,6 +138,7 @@ export default function MultiSourceCaptioningView() {
|
|
134 |
getContext: () => ctx,
|
135 |
} as unknown as HTMLVideoElement;
|
136 |
const result = await runInference(fakeVideo, prompt);
|
|
|
137 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
138 |
const boxes = extractJsonFromMarkdown(result) || [];
|
139 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
@@ -158,6 +163,8 @@ export default function MultiSourceCaptioningView() {
|
|
158 |
const canvas = canvasRef.current;
|
159 |
canvas.width = img.naturalWidth;
|
160 |
canvas.height = img.naturalHeight;
|
|
|
|
|
161 |
const ctx = canvas.getContext("2d");
|
162 |
if (!ctx) return;
|
163 |
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
@@ -170,6 +177,7 @@ export default function MultiSourceCaptioningView() {
|
|
170 |
getContext: () => ctx,
|
171 |
} as unknown as HTMLVideoElement;
|
172 |
const result = await runInference(fakeVideo, prompt);
|
|
|
173 |
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
174 |
const boxes = extractJsonFromMarkdown(result) || [];
|
175 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
@@ -204,6 +212,7 @@ export default function MultiSourceCaptioningView() {
|
|
204 |
getContext: () => ctx,
|
205 |
} as unknown as HTMLVideoElement;
|
206 |
const result = await runInference(fakeVideo, prompt);
|
|
|
207 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
208 |
const boxes = extractJsonFromMarkdown(result) || [];
|
209 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
@@ -244,6 +253,7 @@ export default function MultiSourceCaptioningView() {
|
|
244 |
getContext: () => ctx,
|
245 |
} as unknown as HTMLVideoElement;
|
246 |
const result = await runInference(fakeVideo, prompt);
|
|
|
247 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
248 |
const boxes = extractJsonFromMarkdown(result) || [];
|
249 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
@@ -287,6 +297,21 @@ export default function MultiSourceCaptioningView() {
|
|
287 |
setUrlProcessing((prev) => !prev);
|
288 |
};
|
289 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
return (
|
291 |
<div className="absolute inset-0 text-white">
|
292 |
<div className="flex flex-col items-center justify-center h-full w-full">
|
@@ -390,6 +415,17 @@ export default function MultiSourceCaptioningView() {
|
|
390 |
</div>
|
391 |
{processing && <div className="text-blue-400 mt-2">Processing frame...</div>}
|
392 |
{error && <div className="text-red-400 mt-2">Error: {error}</div>}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
</div>
|
394 |
)}
|
395 |
{mode === "File" && (
|
@@ -487,6 +523,17 @@ export default function MultiSourceCaptioningView() {
|
|
487 |
)}
|
488 |
{processing && <div className="text-blue-400 mt-2">Processing frame...</div>}
|
489 |
{error && <div className="text-red-400 mt-2">Error: {error}</div>}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
490 |
</div>
|
491 |
)}
|
492 |
</div>
|
|
|
30 |
const [imageProcessed, setImageProcessed] = useState(false);
|
31 |
const [exampleProcessing, setExampleProcessing] = useState(false);
|
32 |
const [urlProcessing, setUrlProcessing] = useState(false);
|
33 |
+
const [debugOutput, setDebugOutput] = useState<string>("");
|
34 |
+
const [canvasDims, setCanvasDims] = useState<{w:number,h:number}|null>(null);
|
35 |
+
const [videoDims, setVideoDims] = useState<{w:number,h:number}|null>(null);
|
36 |
|
37 |
const videoRef = useRef<HTMLVideoElement | null>(null);
|
38 |
const canvasRef = useRef<HTMLCanvasElement | null>(null);
|
|
|
97 |
getContext: () => ctx,
|
98 |
} as unknown as HTMLVideoElement;
|
99 |
const result = await runInference(fakeVideo, prompt);
|
100 |
+
setDebugOutput(result);
|
101 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
102 |
const boxes = extractJsonFromMarkdown(result) || [];
|
103 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
|
|
138 |
getContext: () => ctx,
|
139 |
} as unknown as HTMLVideoElement;
|
140 |
const result = await runInference(fakeVideo, prompt);
|
141 |
+
setDebugOutput(result);
|
142 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
143 |
const boxes = extractJsonFromMarkdown(result) || [];
|
144 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
|
|
163 |
const canvas = canvasRef.current;
|
164 |
canvas.width = img.naturalWidth;
|
165 |
canvas.height = img.naturalHeight;
|
166 |
+
setCanvasDims({w:canvas.width,h:canvas.height});
|
167 |
+
setVideoDims({w:img.naturalWidth,h:img.naturalHeight});
|
168 |
const ctx = canvas.getContext("2d");
|
169 |
if (!ctx) return;
|
170 |
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
|
|
177 |
getContext: () => ctx,
|
178 |
} as unknown as HTMLVideoElement;
|
179 |
const result = await runInference(fakeVideo, prompt);
|
180 |
+
setDebugOutput(result);
|
181 |
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
182 |
const boxes = extractJsonFromMarkdown(result) || [];
|
183 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
|
|
212 |
getContext: () => ctx,
|
213 |
} as unknown as HTMLVideoElement;
|
214 |
const result = await runInference(fakeVideo, prompt);
|
215 |
+
setDebugOutput(result);
|
216 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
217 |
const boxes = extractJsonFromMarkdown(result) || [];
|
218 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
|
|
253 |
getContext: () => ctx,
|
254 |
} as unknown as HTMLVideoElement;
|
255 |
const result = await runInference(fakeVideo, prompt);
|
256 |
+
setDebugOutput(result);
|
257 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
258 |
const boxes = extractJsonFromMarkdown(result) || [];
|
259 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
|
|
297 |
setUrlProcessing((prev) => !prev);
|
298 |
};
|
299 |
|
300 |
+
// Test draw box function
|
301 |
+
const handleTestDrawBox = () => {
|
302 |
+
if (!canvasRef.current) return;
|
303 |
+
const canvas = canvasRef.current;
|
304 |
+
const ctx = canvas.getContext("2d");
|
305 |
+
if (!ctx) return;
|
306 |
+
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
307 |
+
ctx.strokeStyle = "#FF00FF";
|
308 |
+
ctx.lineWidth = 4;
|
309 |
+
ctx.strokeRect(40, 40, Math.max(40,canvas.width/4), Math.max(40,canvas.height/4));
|
310 |
+
ctx.font = "20px Arial";
|
311 |
+
ctx.fillStyle = "#FF00FF";
|
312 |
+
ctx.fillText("Test Box", 50, 35);
|
313 |
+
};
|
314 |
+
|
315 |
return (
|
316 |
<div className="absolute inset-0 text-white">
|
317 |
<div className="flex flex-col items-center justify-center h-full w-full">
|
|
|
415 |
</div>
|
416 |
{processing && <div className="text-blue-400 mt-2">Processing frame...</div>}
|
417 |
{error && <div className="text-red-400 mt-2">Error: {error}</div>}
|
418 |
+
<button
|
419 |
+
className="mt-4 px-6 py-2 rounded-lg bg-gray-600 text-white font-semibold"
|
420 |
+
onClick={handleTestDrawBox}
|
421 |
+
>
|
422 |
+
Test Draw Box
|
423 |
+
</button>
|
424 |
+
<div className="mt-2 p-2 bg-gray-800 rounded text-xs">
|
425 |
+
<div>Canvas: {canvasDims ? `${canvasDims.w}x${canvasDims.h}` : "-"} | Video: {videoDims ? `${videoDims.w}x${videoDims.h}` : "-"}</div>
|
426 |
+
<div>Raw Model Output:</div>
|
427 |
+
<pre className="overflow-x-auto max-h-32 whitespace-pre-wrap">{debugOutput}</pre>
|
428 |
+
</div>
|
429 |
</div>
|
430 |
)}
|
431 |
{mode === "File" && (
|
|
|
523 |
)}
|
524 |
{processing && <div className="text-blue-400 mt-2">Processing frame...</div>}
|
525 |
{error && <div className="text-red-400 mt-2">Error: {error}</div>}
|
526 |
+
<button
|
527 |
+
className="mt-4 px-6 py-2 rounded-lg bg-gray-600 text-white font-semibold"
|
528 |
+
onClick={handleTestDrawBox}
|
529 |
+
>
|
530 |
+
Test Draw Box
|
531 |
+
</button>
|
532 |
+
<div className="mt-2 p-2 bg-gray-800 rounded text-xs">
|
533 |
+
<div>Canvas: {canvasDims ? `${canvasDims.w}x${canvasDims.h}` : "-"} | Video: {videoDims ? `${videoDims.w}x${videoDims.h}` : "-"}</div>
|
534 |
+
<div>Raw Model Output:</div>
|
535 |
+
<pre className="overflow-x-auto max-h-32 whitespace-pre-wrap">{debugOutput}</pre>
|
536 |
+
</div>
|
537 |
</div>
|
538 |
)}
|
539 |
</div>
|