Quazim0t0 commited on
Commit
7599655
·
verified ·
1 Parent(s): 83c414e

Upload 37 files

Browse files
src/components/MultiSourceCaptioningView.tsx CHANGED
@@ -48,6 +48,36 @@ export default function MultiSourceCaptioningView() {
48
  const webcamStreamRef = useRef<MediaStream | null>(null);
49
  const { isLoaded, isLoading, error: modelError, runInference } = useVLMContext();
50
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  // Webcam setup and teardown (unchanged)
52
  useEffect(() => {
53
  if (mode !== "Webcam") {
 
48
  const webcamStreamRef = useRef<MediaStream | null>(null);
49
  const { isLoaded, isLoading, error: modelError, runInference } = useVLMContext();
50
 
51
+ const processVideoFrame = async () => {
52
+ if (!videoRef.current || !canvasRef.current) return;
53
+ const video = videoRef.current;
54
+ const canvas = canvasRef.current;
55
+ if (video.paused || video.ended || video.videoWidth === 0) return;
56
+ canvas.width = video.videoWidth;
57
+ canvas.height = video.videoHeight;
58
+ const ctx = canvas.getContext("2d");
59
+ if (!ctx) return;
60
+ ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
61
+ await runInference(video, prompt, (output: string) => {
62
+ let boxes = extractJsonFromMarkdown(output) || [];
63
+ if (boxes.length === 0 && Array.isArray(output)) {
64
+ boxes = parseFlatBoxArray(output);
65
+ }
66
+ if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
67
+ drawBoundingBoxesOnCanvas(ctx, boxes);
68
+ });
69
+ };
70
+
71
+ const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {
72
+ const file = e.target.files?.[0] || null;
73
+ setUploadedFile(file);
74
+ setUploadedUrl(file ? URL.createObjectURL(file) : "");
75
+ setError(null);
76
+ setImageProcessed(false);
77
+ setVideoProcessing(false);
78
+ setExampleProcessing(false);
79
+ };
80
+
81
  // Webcam setup and teardown (unchanged)
82
  useEffect(() => {
83
  if (mode !== "Webcam") {