Florent Gbelidji commited on
Commit
0ba35c2
·
verified ·
1 Parent(s): 38b9700

Sync DeepSeek OCR HF job code

Browse files
Files changed (1) hide show
  1. ds_batch_ocr/stages.py +4 -18
ds_batch_ocr/stages.py CHANGED
@@ -7,7 +7,7 @@ from pathlib import Path
7
  from typing import Any, Dict, Iterable, List, Optional
8
 
9
  import shutil
10
- from datasets import Dataset, Features, Sequence, Value, load_dataset, Image as HfImage
11
  from PIL import Image, ImageOps
12
  from torch.utils.data import DataLoader
13
 
@@ -162,19 +162,11 @@ def _push_dataset_records(
162
 
163
  def _record_iterator() -> Iterable[Dict[str, Any]]:
164
  for record in records:
165
- if isinstance(record, dict):
166
- data = dict(record)
167
- else:
168
- data = dict(record)
169
-
170
- if "figures" in data and not isinstance(data["figures"], dict):
171
- data["figures"] = _figures_to_columnar(data.get("figures"))
172
-
173
  yield data
174
 
175
- write_jsonl_iter(dataset_path, _record_iterator())
176
 
177
- dataset = Dataset.from_json(str(dataset_path), features=_dataset_features())
178
 
179
  token = env_or_none("HF_TOKEN")
180
  dataset.push_to_hub(
@@ -454,13 +446,7 @@ def run_stage_extract(settings: ExtractSettings) -> None:
454
  except Exception as exc: # pragma: no cover - defensive logging
455
  LOGGER.warning("Failed to read documents batch %s: %s", file_path, exc)
456
  continue
457
-
458
- if not isinstance(batch_data, list):
459
- LOGGER.warning("Unexpected batch content in %s; expected list", file_path)
460
- continue
461
-
462
- for entry in batch_data:
463
- yield entry
464
 
465
  documents_iter_for_push = iter_documents_from_batches(document_batch_files)
466
  dataset_records_iter = _build_dataset_records_iter(documents_iter_for_push)
 
7
  from typing import Any, Dict, Iterable, List, Optional
8
 
9
  import shutil
10
+ from datasets import Dataset, Features, Sequence, Value, load_dataset, Image as HfImage, load_
11
  from PIL import Image, ImageOps
12
  from torch.utils.data import DataLoader
13
 
 
162
 
163
  def _record_iterator() -> Iterable[Dict[str, Any]]:
164
  for record in records:
165
+ data = json.loads(record)
 
 
 
 
 
 
 
166
  yield data
167
 
 
168
 
169
+ dataset = Dataset.from_generator(_record_iterator, features=_dataset_features())
170
 
171
  token = env_or_none("HF_TOKEN")
172
  dataset.push_to_hub(
 
446
  except Exception as exc: # pragma: no cover - defensive logging
447
  LOGGER.warning("Failed to read documents batch %s: %s", file_path, exc)
448
  continue
449
+ yield from batch_data
 
 
 
 
 
 
450
 
451
  documents_iter_for_push = iter_documents_from_batches(document_batch_files)
452
  dataset_records_iter = _build_dataset_records_iter(documents_iter_for_push)