Spaces:
Paused
Paused
Download python_files/annotate_all.py from Rachel7/hvac_fable: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/python_files/annotate_all.py
- Command line
-
hf download hf://spaces/Rachel7/hvac_fable/python_files/annotate_all.py
-
curl -L -o annotate_all.py https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/python_files/annotate_all.py
1.1 kB
| import json, glob, re, sys, warnings | |
| warnings.filterwarnings('ignore') | |
| sys.path.insert(0, '.') | |
| from pathlib import Path | |
| import analyze_blueprint as ab | |
| pdf_path = Path(r'..\raw_pdfs\355 E 86th St Mechanical 100% CD Set_flattened.pdf') | |
| out = Path('output') | |
| with open('output/355 E 86th St Mechanical 100% CD Set_flattened_schedule_cache.json') as f: | |
| sched = json.load(f) | |
| known = list(sched.keys()) | |
| tag_colors = ab._build_color_map(sorted(known)) | |
| files = sorted(glob.glob('output/floor_*_detections.json')) | |
| for fp in files: | |
| m = re.match(r'.*floor_(\d+)_(.+)_detections\.json', fp) | |
| if not m: continue | |
| page_num = int(m.group(1)); floor_name = m.group(2) | |
| out_png = out / f'floor_{page_num:03d}_{floor_name}_annotated.png' | |
| if out_png.exists(): | |
| continue | |
| with open(fp) as f: | |
| data = json.load(f) | |
| hits = [ab.TagHit(**h) for h in data['hits']] | |
| color_img = ab._render_page(pdf_path, page_num - 1, 300) | |
| ab.annotate_and_save(floor_name.replace('_', ' '), page_num, color_img, hits, out, tag_colors) | |
| print(f'annotated: {out_png.name}') | |
| print('done') | |