Spaces:
Running
Running
Upload 37 files
Browse files
src/components/MultiSourceCaptioningView.tsx
CHANGED
@@ -23,10 +23,17 @@ function normalizeBoxes(raw: any): { label: string, bbox_2d: number[] }[] {
|
|
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 (
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
}
|
|
|
23 |
} else if (typeof raw === "object" && raw !== null) {
|
24 |
boxes = [raw];
|
25 |
}
|
26 |
+
// Normalize bbox_2d to flat [x1, y1, x2, y2] only if valid
|
27 |
return boxes.map(obj => {
|
28 |
let bbox = obj.bbox_2d;
|
29 |
+
if (
|
30 |
+
Array.isArray(bbox) &&
|
31 |
+
bbox.length === 2 &&
|
32 |
+
Array.isArray(bbox[0]) &&
|
33 |
+
Array.isArray(bbox[1]) &&
|
34 |
+
bbox[0].length === 2 &&
|
35 |
+
bbox[1].length === 2
|
36 |
+
) {
|
37 |
// Convert [[x1, y1], [x2, y2]] to [x1, y1, x2, y2]
|
38 |
bbox = [bbox[0][0], bbox[0][1], bbox[1][0], bbox[1][1]];
|
39 |
}
|