Spaces:
Running
Running
Upload 37 files
Browse files
src/components/MultiSourceCaptioningView.tsx
CHANGED
@@ -16,6 +16,24 @@ function parseFlatBoxArray(arr: any[]): { label: string, bbox_2d: number[] }[] {
|
|
16 |
return [];
|
17 |
}
|
18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
function isImageFile(file: File) {
|
20 |
return file.type.startsWith("image/");
|
21 |
}
|
@@ -64,6 +82,7 @@ export default function MultiSourceCaptioningView() {
|
|
64 |
if (boxes.length === 0 && Array.isArray(output)) {
|
65 |
boxes = parseFlatBoxArray(output);
|
66 |
}
|
|
|
67 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
68 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
69 |
});
|
@@ -184,6 +203,7 @@ export default function MultiSourceCaptioningView() {
|
|
184 |
if (boxes.length === 0 && Array.isArray(output)) {
|
185 |
boxes = parseFlatBoxArray(output);
|
186 |
}
|
|
|
187 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
188 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
189 |
setImageProcessed(true);
|
|
|
16 |
return [];
|
17 |
}
|
18 |
|
19 |
+
function normalizeBoxes(raw: any): { label: string, bbox_2d: number[] }[] {
|
20 |
+
let boxes = [];
|
21 |
+
if (Array.isArray(raw)) {
|
22 |
+
boxes = raw;
|
23 |
+
} else if (typeof raw === "object" && raw !== null) {
|
24 |
+
boxes = [raw];
|
25 |
+
}
|
26 |
+
// Normalize bbox_2d to flat [x1, y1, x2, y2]
|
27 |
+
return boxes.map(obj => {
|
28 |
+
let bbox = obj.bbox_2d;
|
29 |
+
if (Array.isArray(bbox) && Array.isArray(bbox[0])) {
|
30 |
+
// Convert [[x1, y1], [x2, y2]] to [x1, y1, x2, y2]
|
31 |
+
bbox = [bbox[0][0], bbox[0][1], bbox[1][0], bbox[1][1]];
|
32 |
+
}
|
33 |
+
return { ...obj, bbox_2d: bbox };
|
34 |
+
});
|
35 |
+
}
|
36 |
+
|
37 |
function isImageFile(file: File) {
|
38 |
return file.type.startsWith("image/");
|
39 |
}
|
|
|
82 |
if (boxes.length === 0 && Array.isArray(output)) {
|
83 |
boxes = parseFlatBoxArray(output);
|
84 |
}
|
85 |
+
boxes = normalizeBoxes(boxes);
|
86 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
87 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
88 |
});
|
|
|
203 |
if (boxes.length === 0 && Array.isArray(output)) {
|
204 |
boxes = parseFlatBoxArray(output);
|
205 |
}
|
206 |
+
boxes = normalizeBoxes(boxes);
|
207 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
208 |
drawBoundingBoxesOnCanvas(ctx, boxes);
|
209 |
setImageProcessed(true);
|