CoolFace
Apppublic

moebiusT7/book-ocr-studio

sourceHugging Faceagpl-3.0updated 2d agoView on Hugging Face
0likes
capture_options.py28 linesDownload Raw Back to root
1"""Resolve the model selected before capture, including long-lived capture workers."""2from pathlib import Path3 4def apply_options(job,cfg,root,read,save):5    if cfg.get('capture_options_applied'):return cfg6    source=cfg.get('autopilot',{}).get('source_capture')7    if not source:return cfg8    boundary=(Path(root)/'captures').resolve();folder=Path(source).resolve()9    if not folder.is_relative_to(boundary):raise ValueError('Capture source is outside the storage directory')10    while folder!=boundary:11        path=folder/'conversion-options.json'12        if path.exists():13            options=read(path)14            model=options['model']15            engine=options.get('ocr_engine',cfg.get('ocr_engine','marker'))16            if engine not in {'marker','yomitoku'}:raise ValueError('Invalid capture OCR engine')17            connector=options.get('review_connector')18            if connector:19                from review_connector import model_for20                if model!=model_for(connector):raise ValueError('Connector model mismatch')21            elif model not in {'gemma4:12b-it-qat','gemma4:26b-a4b-it-qat'}:raise ValueError('Invalid capture review model')22            cfg.update(model=model,ocr_engine=engine,review_connector=connector,capture_options_applied=True,capture_options_source=str(path));save(Path(job)/'job.json',cfg)23            break24        folder=folder.parent25    if not cfg.get('capture_options_applied'):26        cfg['capture_options_applied']=True;save(Path(job)/'job.json',cfg)27    return cfg28