Florent Gbelidji commited on
Commit
8e94c5f
·
verified ·
1 Parent(s): 9658ad2

Sync DeepSeek OCR HF job code

Browse files
Files changed (1) hide show
  1. ds_batch_ocr/document.py +24 -0
ds_batch_ocr/document.py CHANGED
@@ -19,6 +19,10 @@ GROUNDING_PATTERN = re.compile(
19
  re.DOTALL,
20
  )
21
 
 
 
 
 
22
  FIGURE_MARKDOWN_PATTERN = re.compile(
23
  r"!\[Figure (?P<figure_id>[^\]]+)\]\((?P<path>[^)]+)\)"
24
  )
@@ -70,6 +74,26 @@ def extract_grounding_blocks(text: str) -> List[Dict[str, Any]]:
70
  "span": match.span(),
71
  }
72
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  return matches
74
 
75
 
 
19
  re.DOTALL,
20
  )
21
 
22
+ ALT_GROUNDING_PATTERN = re.compile(
23
+ r"(?P<label>[A-Za-z0-9_]+)\[\[(?P<coords>[^\[\]]+)\]\]",
24
+ )
25
+
26
  FIGURE_MARKDOWN_PATTERN = re.compile(
27
  r"!\[Figure (?P<figure_id>[^\]]+)\]\((?P<path>[^)]+)\)"
28
  )
 
74
  "span": match.span(),
75
  }
76
  )
77
+
78
+ if not matches:
79
+ for match in ALT_GROUNDING_PATTERN.finditer(text):
80
+ label = match.group("label").strip()
81
+ coords_text = match.group("coords").strip()
82
+ coordinates = None
83
+ if coords_text:
84
+ try:
85
+ coordinates = ast.literal_eval(f"[{coords_text}]")
86
+ except Exception:
87
+ coordinates = None
88
+ matches.append(
89
+ {
90
+ "label": label,
91
+ "coordinates": coordinates,
92
+ "raw": match.group(0),
93
+ "span": match.span(),
94
+ }
95
+ )
96
+
97
  return matches
98
 
99