# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. # SPDX-License-Identifier: OpenMDW-1.1 """Prediction-only merge and Markdown conversion; no labels or scorer imports.""" from __future__ import annotations import argparse,gzip,json,re,time,multiprocessing from concurrent.futures import ProcessPoolExecutor from pathlib import Path from types import SimpleNamespace from engine import merge,markdown as adapter,policies from engine.header_inference_probe import infer_header_rows from engine.text_cleanup import normalize_text,repair_empty_prefix,dedupe_exact_elements from engine.caption_relocation import relocate_above_captions from engine.chart_context import add_native_subtitles from engine.chart_caption import transform def read_rows(path): with (gzip.open(path,'rt') if str(path).endswith('.gz') else open(path)) as f: return [json.loads(s) for s in f if s.strip()] def write_rows(path,rows): path=Path(path);path.parent.mkdir(parents=True,exist_ok=True) with (gzip.open(path,'wt') if str(path).endswith('.gz') else path.open('w')) as f: for row in rows:f.write(json.dumps(row,ensure_ascii=False)+'\n') def key(row):return Path(row.get('key') or row.get('image_name','')).stem.removeprefix('parsebench__') def arguments(crops=None): return SimpleNamespace(crop_element_predictions=[Path(crops)] if crops else [],structural_classes='Table,Chart', include_detector_labels='chart,table',max_crop_output_chars=0,max_crop_output_blocks=0,min_structural_area=0., crop_coordinate_frame='content_normalized',crop_pad_position='top-left',prediction_pad_position='top-left', output_coordinate_frame='content_normalized',canvas_width=1664.,canvas_height=2048.,structural_source='crop', dedupe_overlap_threshold=.85,dedupe_text_threshold=.8,replacement_text_threshold=.8) def corrected(raw): text=adapter.mmd_to_markdown(raw,text_transform=normalize_text) return re.sub(r'