Spaces:
Running
Running
Upload 37 files
Browse files
src/components/MultiSourceCaptioningView.tsx
CHANGED
@@ -17,28 +17,29 @@ function parseFlatBoxArray(arr: any[]): { label: string, bbox_2d: number[] }[] {
|
|
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 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
}
|
43 |
|
44 |
function isImageFile(file: File) {
|
@@ -91,7 +92,9 @@ export default function MultiSourceCaptioningView() {
|
|
91 |
}
|
92 |
boxes = normalizeBoxes(boxes);
|
93 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
94 |
-
|
|
|
|
|
95 |
});
|
96 |
};
|
97 |
|
@@ -212,7 +215,9 @@ export default function MultiSourceCaptioningView() {
|
|
212 |
}
|
213 |
boxes = normalizeBoxes(boxes);
|
214 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
215 |
-
|
|
|
|
|
216 |
setImageProcessed(true);
|
217 |
});
|
218 |
setProcessing(false);
|
|
|
17 |
}
|
18 |
|
19 |
function normalizeBoxes(raw: any): { label: string, bbox_2d: number[] }[] {
|
20 |
+
if (!raw) return [];
|
21 |
let boxes = [];
|
22 |
if (Array.isArray(raw)) {
|
23 |
boxes = raw;
|
24 |
} else if (typeof raw === "object" && raw !== null) {
|
25 |
boxes = [raw];
|
26 |
}
|
27 |
+
return boxes
|
28 |
+
.filter(obj => obj && obj.bbox_2d)
|
29 |
+
.map(obj => {
|
30 |
+
let bbox = obj.bbox_2d;
|
31 |
+
if (
|
32 |
+
Array.isArray(bbox) &&
|
33 |
+
bbox.length === 2 &&
|
34 |
+
Array.isArray(bbox[0]) &&
|
35 |
+
Array.isArray(bbox[1]) &&
|
36 |
+
bbox[0].length === 2 &&
|
37 |
+
bbox[1].length === 2
|
38 |
+
) {
|
39 |
+
bbox = [bbox[0][0], bbox[0][1], bbox[1][0], bbox[1][1]];
|
40 |
+
}
|
41 |
+
return { ...obj, bbox_2d: bbox };
|
42 |
+
});
|
43 |
}
|
44 |
|
45 |
function isImageFile(file: File) {
|
|
|
92 |
}
|
93 |
boxes = normalizeBoxes(boxes);
|
94 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
95 |
+
if (Array.isArray(boxes) && boxes.length > 0) {
|
96 |
+
drawBoundingBoxesOnCanvas(ctx, boxes);
|
97 |
+
}
|
98 |
});
|
99 |
};
|
100 |
|
|
|
215 |
}
|
216 |
boxes = normalizeBoxes(boxes);
|
217 |
if (boxes.length === 0) setInferenceStatus("No boxes detected or model output invalid.");
|
218 |
+
if (Array.isArray(boxes) && boxes.length > 0) {
|
219 |
+
drawBoundingBoxesOnCanvas(ctx, boxes);
|
220 |
+
}
|
221 |
setImageProcessed(true);
|
222 |
});
|
223 |
setProcessing(false);
|