Florent Gbelidji commited on
Commit
f435d98
·
verified ·
1 Parent(s): 2488859

Sync DeepSeek OCR HF job code

Browse files
Files changed (1) hide show
  1. ds_batch_ocr/stages.py +38 -0
ds_batch_ocr/stages.py CHANGED
@@ -165,6 +165,44 @@ def _push_dataset_records(
165
  for record in records:
166
  new_record = dict(record)
167
  new_record["figures"] = _normalize_figures(record.get("figures", []))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
  normalized_records.append(new_record)
169
 
170
  dataset = Dataset.from_list(normalized_records, features=_dataset_features())
 
165
  for record in records:
166
  new_record = dict(record)
167
  new_record["figures"] = _normalize_figures(record.get("figures", []))
168
+
169
+ coerced_figures: List[Dict[str, str]] = []
170
+ for fig in new_record["figures"]:
171
+ if isinstance(fig, dict):
172
+ coerced_figures.append(
173
+ {
174
+ "figure_id": str(fig.get("figure_id", "") or ""),
175
+ "image_path": str(fig.get("image_path", "") or ""),
176
+ "description": str(fig.get("description", "") or ""),
177
+ }
178
+ )
179
+ continue
180
+
181
+ if isinstance(fig, (list, tuple)):
182
+ coerced_figures.append(
183
+ {
184
+ "figure_id": str(fig[0]) if len(fig) > 0 and fig[0] is not None else "",
185
+ "image_path": str(fig[1]) if len(fig) > 1 and fig[1] is not None else "",
186
+ "description": str(fig[2]) if len(fig) > 2 and fig[2] is not None else "",
187
+ }
188
+ )
189
+ LOGGER.debug("Coerced list/tuple figure entry to dict: %s", fig)
190
+ continue
191
+
192
+ LOGGER.warning(
193
+ "Unexpected figure entry type after normalization | type=%s | value=%r",
194
+ type(fig),
195
+ fig,
196
+ )
197
+ coerced_figures.append(
198
+ {
199
+ "figure_id": str(fig),
200
+ "image_path": "",
201
+ "description": "",
202
+ }
203
+ )
204
+
205
+ new_record["figures"] = coerced_figures
206
  normalized_records.append(new_record)
207
 
208
  dataset = Dataset.from_list(normalized_records, features=_dataset_features())