Florent Gbelidji commited on
Sync DeepSeek OCR HF job code
Browse files- ds_batch_ocr/stages.py +14 -31
ds_batch_ocr/stages.py
CHANGED
|
@@ -138,8 +138,7 @@ def _build_dataset_records(documents: Iterable[Dict[str, Any]]) -> List[Dict[str
|
|
| 138 |
|
| 139 |
def _push_dataset_records(
|
| 140 |
*,
|
| 141 |
-
|
| 142 |
-
records_path: Optional[Path] = None,
|
| 143 |
output_dir: Path,
|
| 144 |
repo_id: Optional[str],
|
| 145 |
commit_message: Optional[str],
|
|
@@ -150,23 +149,7 @@ def _push_dataset_records(
|
|
| 150 |
|
| 151 |
dataset_path = _dataset_path(output_dir)
|
| 152 |
|
| 153 |
-
|
| 154 |
-
if records is not None:
|
| 155 |
-
LOGGER.warning("Both records and records_path provided; ignoring in-memory records.")
|
| 156 |
-
if records_path != dataset_path:
|
| 157 |
-
dataset_path.parent.mkdir(parents=True, exist_ok=True)
|
| 158 |
-
shutil.copyfile(records_path, dataset_path)
|
| 159 |
-
else:
|
| 160 |
-
if records is None:
|
| 161 |
-
records = []
|
| 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 = os.environ.get("HF_TOKEN", None)
|
| 172 |
dataset.push_to_hub(
|
|
@@ -451,19 +434,19 @@ def run_stage_extract(settings: ExtractSettings) -> None:
|
|
| 451 |
extract_commit = settings.upload_commit_message
|
| 452 |
if settings.upload_repo_id and not extract_commit:
|
| 453 |
extract_commit = f"Upload extract stage outputs {__now_iso()}"
|
| 454 |
-
def iter_documents_from_batches(files: Iterable[Path]) -> Iterable[Dict[str, Any]]:
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
documents_iter_for_push = iter_documents_from_batches(document_batch_files)
|
| 464 |
-
dataset_records_iter = _build_dataset_records_iter(documents_iter_for_push)
|
| 465 |
_push_dataset_records(
|
| 466 |
-
|
| 467 |
output_dir=settings.output_dir,
|
| 468 |
repo_id=settings.upload_repo_id,
|
| 469 |
commit_message=extract_commit,
|
|
|
|
| 138 |
|
| 139 |
def _push_dataset_records(
|
| 140 |
*,
|
| 141 |
+
records_files: Optional[List[Path]] = None,
|
|
|
|
| 142 |
output_dir: Path,
|
| 143 |
repo_id: Optional[str],
|
| 144 |
commit_message: Optional[str],
|
|
|
|
| 149 |
|
| 150 |
dataset_path = _dataset_path(output_dir)
|
| 151 |
|
| 152 |
+
dataset = load_dataset("json", data_files=records_files, features=_dataset_features())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
|
| 154 |
token = os.environ.get("HF_TOKEN", None)
|
| 155 |
dataset.push_to_hub(
|
|
|
|
| 434 |
extract_commit = settings.upload_commit_message
|
| 435 |
if settings.upload_repo_id and not extract_commit:
|
| 436 |
extract_commit = f"Upload extract stage outputs {__now_iso()}"
|
| 437 |
+
# def iter_documents_from_batches(files: Iterable[Path]) -> Iterable[Dict[str, Any]]:
|
| 438 |
+
# for file_path in files:
|
| 439 |
+
# try:
|
| 440 |
+
# batch_data = json.loads(file_path.read_text(encoding="utf-8"))
|
| 441 |
+
# except Exception as exc: # pragma: no cover - defensive logging
|
| 442 |
+
# LOGGER.warning("Failed to read documents batch %s: %s", file_path, exc)
|
| 443 |
+
# continue
|
| 444 |
+
# yield from batch_data
|
| 445 |
+
|
| 446 |
+
#documents_iter_for_push = iter_documents_from_batches(document_batch_files)
|
| 447 |
+
#dataset_records_iter = _build_dataset_records_iter(documents_iter_for_push)
|
| 448 |
_push_dataset_records(
|
| 449 |
+
records_file=document_batch_files,
|
| 450 |
output_dir=settings.output_dir,
|
| 451 |
repo_id=settings.upload_repo_id,
|
| 452 |
commit_message=extract_commit,
|