Spaces:
Paused
Paused
Download python_files/visualize_gold_boxes_on_cellar.py from Rachel7/hvac_fable: direct link, hf CLI and curl.
- Browser
- Download file 2.2 kB
-
https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/python_files/visualize_gold_boxes_on_cellar.py
- Command line
-
hf download hf://spaces/Rachel7/hvac_fable/python_files/visualize_gold_boxes_on_cellar.py
-
curl -L -o visualize_gold_boxes_on_cellar.py https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/python_files/visualize_gold_boxes_on_cellar.py
2.2 kB
| """ | |
| Visualize all 13 gold boxes overlaid on the full cellar page. | |
| """ | |
| from pathlib import Path | |
| from PIL import Image, ImageDraw, ImageFont | |
| import fitz | |
| ROOT = Path(__file__).resolve().parent.parent | |
| PDF_PATH = ROOT / "raw_pdfs" / "355 E 86th St Mechanical 100% CD Set_flattened.pdf" | |
| # Verified gold boxes | |
| GOLD = [ | |
| {"tag": "AC-P", "x": 7050, "y": 1300, "w": 500, "h": 550}, | |
| {"tag": "AC-S", "x": 3970, "y": 2200, "w": 500, "h": 500}, | |
| {"tag": "AC-Q", "x": 2530, "y": 2800, "w": 500, "h": 500}, | |
| {"tag": "AC-P", "x": 2530, "y": 3650, "w": 900, "h": 650}, | |
| {"tag": "AC-P", "x": 2530, "y": 4600, "w": 900, "h": 650}, | |
| {"tag": "AC-P", "x": 5750, "y": 4450, "w": 700, "h": 500}, | |
| {"tag": "AC-T", "x": 1800, "y": 6050, "w": 500, "h": 500}, | |
| {"tag": "AC-T", "x": 3300, "y": 7220, "w": 500, "h": 500}, | |
| {"tag": "AC-U", "x": 6600, "y": 6950, "w": 500, "h": 500}, | |
| {"tag": "AC-U", "x": 9050, "y": 7310, "w": 500, "h": 500}, | |
| {"tag": "AC-T", "x": 8300, "y": 5700, "w": 500, "h": 500}, | |
| {"tag": "AC-T", "x": 9600, "y": 6200, "w": 500, "h": 500}, | |
| {"tag": "unit", "x": 8200, "y": 400, "w": 600, "h": 600}, | |
| ] | |
| def render_page(pdf_path: Path, page_num: int, dpi: int) -> Image.Image: | |
| doc = fitz.open(pdf_path) | |
| page = doc.load_page(page_num - 1) | |
| pix = page.get_pixmap(matrix=fitz.Matrix(dpi / 72, dpi / 72), alpha=False) | |
| return Image.frombytes("RGB", [pix.width, pix.height], pix.samples) | |
| # Render full cellar at 300 DPI | |
| print("Rendering full cellar page...") | |
| cellar = render_page(PDF_PATH, 2, 300) | |
| draw = ImageDraw.Draw(cellar) | |
| font = ImageFont.load_default() | |
| # Draw all 13 gold boxes | |
| for idx, box in enumerate(GOLD, 1): | |
| x1 = box["x"] | |
| y1 = box["y"] | |
| x2 = box["x"] + box["w"] | |
| y2 = box["y"] + box["h"] | |
| # Draw box | |
| draw.rectangle([x1, y1, x2, y2], outline=(0, 255, 0), width=3) | |
| # Label | |
| label = f"{idx}. {box['tag']}" | |
| draw.text((x1, y1 - 20), label, fill=(0, 255, 0), font=font) | |
| # Save | |
| out_path = Path(__file__).resolve().parent / "gold_boxes_on_cellar.jpg" | |
| cellar.save(out_path, quality=85) | |
| print(f"Saved: {out_path}") | |
| print(f"Page size: {cellar.width}x{cellar.height}") | |
| print(f"Gold boxes: {len(GOLD)}") | |