Spaces:
Paused
Paused
Download python_files/find_ac_labels.py from Rachel7/hvac_fable: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/python_files/find_ac_labels.py
- Command line
-
hf download hf://spaces/Rachel7/hvac_fable/python_files/find_ac_labels.py
-
curl -L -o find_ac_labels.py https://huggingface.co/spaces/Rachel7/hvac_fable/resolve/main/python_files/find_ac_labels.py
2.26 kB
| """Render a page section at very high DPI and look for AC- pattern text.""" | |
| import os, io, sys, json | |
| from pathlib import Path | |
| from PIL import Image | |
| from dotenv import load_dotenv | |
| import fitz, warnings | |
| warnings.filterwarnings('ignore') | |
| from PIL import Image as _PIL_Image | |
| _PIL_Image.MAX_IMAGE_PIXELS = None | |
| load_dotenv(Path(__file__).parent.parent / '.env') | |
| api_key = os.environ.get('GEMINI_API_KEY', '').strip().strip('"') | |
| from google import genai as google_genai | |
| from google.genai import types as genai_types | |
| client = google_genai.Client(api_key=api_key) | |
| page_num = int(sys.argv[1]) # 1-based | |
| pdf = fitz.open(r'..\raw_pdfs\355 E 86th St Mechanical 100% CD Set_flattened.pdf') | |
| page = pdf[page_num - 1] | |
| # Very high DPI to read small text | |
| mat = fitz.Matrix(250/72, 250/72) | |
| pix = page.get_pixmap(matrix=mat, alpha=False) | |
| img = Image.frombytes('RGB', [pix.width, pix.height], pix.samples) | |
| pdf.close() | |
| print(f'Page {page_num} at 400 DPI: {img.size}') | |
| # Crop center portion (avoid title block on right) | |
| w, h = img.size | |
| # Focus on the main drawing area - left 80%, all height | |
| crop = img.crop((0, 0, int(w * 0.8), h)) | |
| # Scale to 2048px | |
| cw, ch = crop.size | |
| factor = 2048 / max(cw, ch) | |
| scaled = crop.resize((int(cw*factor), int(ch*factor)), Image.LANCZOS) | |
| scaled.save(f'output/page{page_num}_hires_crop.png') | |
| buf = io.BytesIO() | |
| scaled.save(buf, format='PNG') | |
| prompt = """This is a section of a mechanical HVAC floor plan at high resolution. | |
| Look carefully for any labels matching the pattern "AC-" followed by a letter (A through U), such as: | |
| AC-D, AC-F, AC-Q, AC-S, etc. | |
| These may appear: | |
| - As small text labels next to unit rectangles | |
| - Inside or below equipment symbols | |
| - In parentheses like (AC-D) below a unit tag | |
| - As part of a two-line label like "FCU-15 / AC-D" | |
| Please: | |
| 1. List every "AC-X" label you can find and its approximate location on this cropped image | |
| 2. Describe the unit symbol it's associated with | |
| 3. If you see NO AC-X labels at all, say so explicitly""" | |
| response = client.models.generate_content( | |
| model='gemini-2.5-flash', | |
| contents=[prompt, genai_types.Part.from_bytes(data=buf.getvalue(), mime_type='image/png')], | |
| config=genai_types.GenerateContentConfig(max_output_tokens=4096, temperature=0.0), | |
| ) | |
| print(response.text) | |