Back to PDF tables to sheets
demo.py
"""Regenerate all synthetic sample deliverables without network access."""
import importlib.util,json
from pathlib import Path
from generate_sources import generate
from extract import run
ROOT=Path(__file__).resolve().parent
if __name__=='__main__':
source=generate(); qa=run(); evidence=ROOT/'evidence'; evidence.mkdir(exist_ok=True)
spec=importlib.util.spec_from_file_location('bad_extract',ROOT/'before/extract.py'); bad=importlib.util.module_from_spec(spec); spec.loader.exec_module(bad)
counts={}
for name in ['invoice','statement']: counts[name]=len(bad.extract_bad(source/(name+'.pdf'),evidence/('before-'+name+'.csv')))
comparison={'synthetic':True,'before_rows':counts,'after_rows':{d['kind']:int(d['row_count']['actual']) for d in qa['documents']},'qa_result':qa['overall_quality'],'low_confidence_cells':qa['low_confidence_cell_count']}
(evidence/'demo.json').write_text(json.dumps(comparison,indent=2)+'\n',encoding='utf-8'); print(json.dumps(comparison,indent=2))