Quazim0t0 commited on
Commit
77ea914
·
verified ·
1 Parent(s): 2e2739c

Upload 37 files

Browse files
src/components/MultiSourceCaptioningView.tsx CHANGED
@@ -31,18 +31,33 @@ function normalizeBoxes(raw: any): { label: string, bbox_2d: number[] }[] {
31
  .filter((obj: any) => obj && obj.bbox_2d)
32
  .map((obj: any) => {
33
  let bbox = obj.bbox_2d;
 
 
 
 
 
 
 
 
 
 
34
  if (
35
  Array.isArray(bbox) &&
36
  bbox.length === 2 &&
37
  Array.isArray(bbox[0]) &&
38
  Array.isArray(bbox[1]) &&
39
  bbox[0].length === 2 &&
40
- bbox[1].length === 2
 
 
41
  ) {
42
  bbox = [bbox[0][0], bbox[0][1], bbox[1][0], bbox[1][1]];
 
43
  }
44
- return { ...obj, bbox_2d: bbox };
45
- });
 
 
46
  }
47
 
48
  function isImageFile(file: File) {
 
31
  .filter((obj: any) => obj && obj.bbox_2d)
32
  .map((obj: any) => {
33
  let bbox = obj.bbox_2d;
34
+ // Accept [x1, y1, x2, y2]
35
+ if (
36
+ Array.isArray(bbox) &&
37
+ bbox.length === 4 &&
38
+ bbox.every((v: any) => typeof v === "number")
39
+ ) {
40
+ // Already in [x1, y1, x2, y2] format
41
+ return { ...obj, bbox_2d: bbox };
42
+ }
43
+ // Accept [[x1, y1], [x2, y2]]
44
  if (
45
  Array.isArray(bbox) &&
46
  bbox.length === 2 &&
47
  Array.isArray(bbox[0]) &&
48
  Array.isArray(bbox[1]) &&
49
  bbox[0].length === 2 &&
50
+ bbox[1].length === 2 &&
51
+ bbox[0].every((v: any) => typeof v === "number") &&
52
+ bbox[1].every((v: any) => typeof v === "number")
53
  ) {
54
  bbox = [bbox[0][0], bbox[0][1], bbox[1][0], bbox[1][1]];
55
+ return { ...obj, bbox_2d: bbox };
56
  }
57
+ // Fallback: skip invalid bbox
58
+ return null;
59
+ })
60
+ .filter((obj: any) => obj && Array.isArray(obj.bbox_2d) && obj.bbox_2d.length === 4 && obj.bbox_2d.every((v: any) => typeof v === "number"));
61
  }
62
 
63
  function isImageFile(file: File) {