Spaces:
Running
Running
Upload 36 files
Browse files
src/components/MultiSourceCaptioningView.tsx
CHANGED
@@ -79,7 +79,7 @@ export default function MultiSourceCaptioningView() {
|
|
79 |
useEffect(() => {
|
80 |
if (mode !== "Webcam" || !isLoaded || !webcamActive) return;
|
81 |
let interval: ReturnType<typeof setInterval> | null = null;
|
82 |
-
const
|
83 |
if (!videoRef.current || !canvasRef.current) return;
|
84 |
const video = videoRef.current;
|
85 |
const canvas = canvasRef.current;
|
@@ -89,31 +89,17 @@ export default function MultiSourceCaptioningView() {
|
|
89 |
const ctx = canvas.getContext("2d");
|
90 |
if (!ctx) return;
|
91 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
92 |
-
|
93 |
-
|
94 |
-
setError(null);
|
95 |
-
setInferenceStatus("Running inference...");
|
96 |
-
const fakeVideo = {
|
97 |
-
videoWidth: canvas.width,
|
98 |
-
videoHeight: canvas.height,
|
99 |
-
getContext: () => ctx,
|
100 |
-
} as unknown as HTMLVideoElement;
|
101 |
-
const result = await runInference(fakeVideo, prompt);
|
102 |
-
setDebugOutput(result);
|
103 |
setInferenceStatus("Inference complete.");
|
104 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
105 |
-
const boxes = extractJsonFromMarkdown(
|
106 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
107 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
108 |
-
}
|
109 |
-
setError(e instanceof Error ? e.message : String(e));
|
110 |
-
setInferenceStatus("Inference error: " + (e instanceof Error ? e.message : String(e)));
|
111 |
-
} finally {
|
112 |
-
setProcessing(false);
|
113 |
-
}
|
114 |
};
|
115 |
interval = setInterval(() => {
|
116 |
-
|
117 |
}, 1000);
|
118 |
return () => {
|
119 |
if (interval) clearInterval(interval);
|
@@ -124,7 +110,7 @@ export default function MultiSourceCaptioningView() {
|
|
124 |
useEffect(() => {
|
125 |
if (mode !== "URL" || !isLoaded || !urlProcessing) return;
|
126 |
let interval: ReturnType<typeof setInterval> | null = null;
|
127 |
-
const
|
128 |
if (!videoRef.current || !canvasRef.current) return;
|
129 |
const video = videoRef.current;
|
130 |
const canvas = canvasRef.current;
|
@@ -134,31 +120,17 @@ export default function MultiSourceCaptioningView() {
|
|
134 |
const ctx = canvas.getContext("2d");
|
135 |
if (!ctx) return;
|
136 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
137 |
-
|
138 |
-
|
139 |
-
setError(null);
|
140 |
-
setInferenceStatus("Running inference...");
|
141 |
-
const fakeVideo = {
|
142 |
-
videoWidth: canvas.width,
|
143 |
-
videoHeight: canvas.height,
|
144 |
-
getContext: () => ctx,
|
145 |
-
} as unknown as HTMLVideoElement;
|
146 |
-
const result = await runInference(fakeVideo, prompt);
|
147 |
-
setDebugOutput(result);
|
148 |
setInferenceStatus("Inference complete.");
|
149 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
150 |
-
const boxes = extractJsonFromMarkdown(
|
151 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
152 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
153 |
-
}
|
154 |
-
setError(e instanceof Error ? e.message : String(e));
|
155 |
-
setInferenceStatus("Inference error: " + (e instanceof Error ? e.message : String(e)));
|
156 |
-
} finally {
|
157 |
-
setProcessing(false);
|
158 |
-
}
|
159 |
};
|
160 |
interval = setInterval(() => {
|
161 |
-
|
162 |
}, 1000);
|
163 |
return () => {
|
164 |
if (interval) clearInterval(interval);
|
@@ -177,36 +149,26 @@ export default function MultiSourceCaptioningView() {
|
|
177 |
const ctx = canvas.getContext("2d");
|
178 |
if (!ctx) return;
|
179 |
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
videoWidth: canvas.width,
|
186 |
-
videoHeight: canvas.height,
|
187 |
-
getContext: () => ctx,
|
188 |
-
} as unknown as HTMLVideoElement;
|
189 |
-
const result = await runInference(fakeVideo, prompt);
|
190 |
-
setDebugOutput(result);
|
191 |
setInferenceStatus("Inference complete.");
|
192 |
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
193 |
-
const boxes = extractJsonFromMarkdown(
|
194 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
195 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
196 |
setImageProcessed(true);
|
197 |
-
}
|
198 |
-
|
199 |
-
setInferenceStatus("Inference error: " + (e instanceof Error ? e.message : String(e)));
|
200 |
-
} finally {
|
201 |
-
setProcessing(false);
|
202 |
-
}
|
203 |
};
|
204 |
|
205 |
// File mode: process uploaded video frames (start/stop)
|
206 |
useEffect(() => {
|
207 |
if (mode !== "File" || !isLoaded || !uploadedFile || !isVideoFile(uploadedFile) || !videoProcessing) return;
|
208 |
let interval: ReturnType<typeof setInterval> | null = null;
|
209 |
-
const
|
210 |
if (!videoRef.current || !canvasRef.current) return;
|
211 |
const video = videoRef.current;
|
212 |
const canvas = canvasRef.current;
|
@@ -216,31 +178,17 @@ export default function MultiSourceCaptioningView() {
|
|
216 |
const ctx = canvas.getContext("2d");
|
217 |
if (!ctx) return;
|
218 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
219 |
-
|
220 |
-
|
221 |
-
setError(null);
|
222 |
-
setInferenceStatus("Running inference...");
|
223 |
-
const fakeVideo = {
|
224 |
-
videoWidth: canvas.width,
|
225 |
-
videoHeight: canvas.height,
|
226 |
-
getContext: () => ctx,
|
227 |
-
} as unknown as HTMLVideoElement;
|
228 |
-
const result = await runInference(fakeVideo, prompt);
|
229 |
-
setDebugOutput(result);
|
230 |
setInferenceStatus("Inference complete.");
|
231 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
232 |
-
const boxes = extractJsonFromMarkdown(
|
233 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
234 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
235 |
-
}
|
236 |
-
setError(e instanceof Error ? e.message : String(e));
|
237 |
-
setInferenceStatus("Inference error: " + (e instanceof Error ? e.message : String(e)));
|
238 |
-
} finally {
|
239 |
-
setProcessing(false);
|
240 |
-
}
|
241 |
};
|
242 |
interval = setInterval(() => {
|
243 |
-
|
244 |
}, 1000);
|
245 |
return () => {
|
246 |
if (interval) clearInterval(interval);
|
@@ -251,7 +199,7 @@ export default function MultiSourceCaptioningView() {
|
|
251 |
useEffect(() => {
|
252 |
if (mode !== "File" || uploadedFile || !isLoaded || !exampleProcessing) return;
|
253 |
let interval: ReturnType<typeof setInterval> | null = null;
|
254 |
-
const
|
255 |
if (!videoRef.current || !canvasRef.current) return;
|
256 |
const video = videoRef.current;
|
257 |
const canvas = canvasRef.current;
|
@@ -261,31 +209,17 @@ export default function MultiSourceCaptioningView() {
|
|
261 |
const ctx = canvas.getContext("2d");
|
262 |
if (!ctx) return;
|
263 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
264 |
-
|
265 |
-
|
266 |
-
setError(null);
|
267 |
-
setInferenceStatus("Running inference...");
|
268 |
-
const fakeVideo = {
|
269 |
-
videoWidth: canvas.width,
|
270 |
-
videoHeight: canvas.height,
|
271 |
-
getContext: () => ctx,
|
272 |
-
} as unknown as HTMLVideoElement;
|
273 |
-
const result = await runInference(fakeVideo, prompt);
|
274 |
-
setDebugOutput(result);
|
275 |
setInferenceStatus("Inference complete.");
|
276 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
277 |
-
const boxes = extractJsonFromMarkdown(
|
278 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
279 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
280 |
-
}
|
281 |
-
setError(e instanceof Error ? e.message : String(e));
|
282 |
-
setInferenceStatus("Inference error: " + (e instanceof Error ? e.message : String(e)));
|
283 |
-
} finally {
|
284 |
-
setProcessing(false);
|
285 |
-
}
|
286 |
};
|
287 |
interval = setInterval(() => {
|
288 |
-
|
289 |
}, 1000);
|
290 |
return () => {
|
291 |
if (interval) clearInterval(interval);
|
|
|
79 |
useEffect(() => {
|
80 |
if (mode !== "Webcam" || !isLoaded || !webcamActive) return;
|
81 |
let interval: ReturnType<typeof setInterval> | null = null;
|
82 |
+
const processVideoFrame = async () => {
|
83 |
if (!videoRef.current || !canvasRef.current) return;
|
84 |
const video = videoRef.current;
|
85 |
const canvas = canvasRef.current;
|
|
|
89 |
const ctx = canvas.getContext("2d");
|
90 |
if (!ctx) return;
|
91 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
92 |
+
await runInference(video, prompt, (output: string) => {
|
93 |
+
setDebugOutput(output);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
94 |
setInferenceStatus("Inference complete.");
|
95 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
96 |
+
const boxes = extractJsonFromMarkdown(output) || [];
|
97 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
98 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
99 |
+
});
|
|
|
|
|
|
|
|
|
|
|
100 |
};
|
101 |
interval = setInterval(() => {
|
102 |
+
processVideoFrame();
|
103 |
}, 1000);
|
104 |
return () => {
|
105 |
if (interval) clearInterval(interval);
|
|
|
110 |
useEffect(() => {
|
111 |
if (mode !== "URL" || !isLoaded || !urlProcessing) return;
|
112 |
let interval: ReturnType<typeof setInterval> | null = null;
|
113 |
+
const processVideoFrame = async () => {
|
114 |
if (!videoRef.current || !canvasRef.current) return;
|
115 |
const video = videoRef.current;
|
116 |
const canvas = canvasRef.current;
|
|
|
120 |
const ctx = canvas.getContext("2d");
|
121 |
if (!ctx) return;
|
122 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
123 |
+
await runInference(video, prompt, (output: string) => {
|
124 |
+
setDebugOutput(output);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
setInferenceStatus("Inference complete.");
|
126 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
127 |
+
const boxes = extractJsonFromMarkdown(output) || [];
|
128 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
129 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
130 |
+
});
|
|
|
|
|
|
|
|
|
|
|
131 |
};
|
132 |
interval = setInterval(() => {
|
133 |
+
processVideoFrame();
|
134 |
}, 1000);
|
135 |
return () => {
|
136 |
if (interval) clearInterval(interval);
|
|
|
149 |
const ctx = canvas.getContext("2d");
|
150 |
if (!ctx) return;
|
151 |
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
152 |
+
setProcessing(true);
|
153 |
+
setError(null);
|
154 |
+
setInferenceStatus("Running inference...");
|
155 |
+
await runInference(img, prompt, (output: string) => {
|
156 |
+
setDebugOutput(output);
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
setInferenceStatus("Inference complete.");
|
158 |
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
|
159 |
+
const boxes = extractJsonFromMarkdown(output) || [];
|
160 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
161 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
162 |
setImageProcessed(true);
|
163 |
+
});
|
164 |
+
setProcessing(false);
|
|
|
|
|
|
|
|
|
165 |
};
|
166 |
|
167 |
// File mode: process uploaded video frames (start/stop)
|
168 |
useEffect(() => {
|
169 |
if (mode !== "File" || !isLoaded || !uploadedFile || !isVideoFile(uploadedFile) || !videoProcessing) return;
|
170 |
let interval: ReturnType<typeof setInterval> | null = null;
|
171 |
+
const processVideoFrame = async () => {
|
172 |
if (!videoRef.current || !canvasRef.current) return;
|
173 |
const video = videoRef.current;
|
174 |
const canvas = canvasRef.current;
|
|
|
178 |
const ctx = canvas.getContext("2d");
|
179 |
if (!ctx) return;
|
180 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
181 |
+
await runInference(video, prompt, (output: string) => {
|
182 |
+
setDebugOutput(output);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
183 |
setInferenceStatus("Inference complete.");
|
184 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
185 |
+
const boxes = extractJsonFromMarkdown(output) || [];
|
186 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
187 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
188 |
+
});
|
|
|
|
|
|
|
|
|
|
|
189 |
};
|
190 |
interval = setInterval(() => {
|
191 |
+
processVideoFrame();
|
192 |
}, 1000);
|
193 |
return () => {
|
194 |
if (interval) clearInterval(interval);
|
|
|
199 |
useEffect(() => {
|
200 |
if (mode !== "File" || uploadedFile || !isLoaded || !exampleProcessing) return;
|
201 |
let interval: ReturnType<typeof setInterval> | null = null;
|
202 |
+
const processVideoFrame = async () => {
|
203 |
if (!videoRef.current || !canvasRef.current) return;
|
204 |
const video = videoRef.current;
|
205 |
const canvas = canvasRef.current;
|
|
|
209 |
const ctx = canvas.getContext("2d");
|
210 |
if (!ctx) return;
|
211 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
212 |
+
await runInference(video, prompt, (output: string) => {
|
213 |
+
setDebugOutput(output);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
214 |
setInferenceStatus("Inference complete.");
|
215 |
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
|
216 |
+
const boxes = extractJsonFromMarkdown(output) || [];
|
217 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
218 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
219 |
+
});
|
|
|
|
|
|
|
|
|
|
|
220 |
};
|
221 |
interval = setInterval(() => {
|
222 |
+
processVideoFrame();
|
223 |
}, 1000);
|
224 |
return () => {
|
225 |
if (interval) clearInterval(interval);
|