File size: 2,258 Bytes
dac3297
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
"""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)