import os, io, sys, json from pathlib import Path from PIL import Image from dotenv import load_dotenv import fitz, warnings warnings.filterwarnings('ignore') 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) pdf = fitz.open(r'..\raw_pdfs\355 E 86th St Mechanical 100% CD Set_flattened.pdf') page = pdf[int(sys.argv[1]) - 1] # 1-based page number from CLI mat = fitz.Matrix(200/72, 200/72) pix = page.get_pixmap(matrix=mat, alpha=False) img = Image.frombytes('RGB', [pix.width, pix.height], pix.samples) pdf.close() # Scale to 2048px w, h = img.size factor = 2048 / max(w, h) img_scaled = img.resize((int(w*factor), int(h*factor)), Image.LANCZOS) buf = io.BytesIO() img_scaled.save(buf, format='PNG') img_bytes = buf.getvalue() prompt = """This is a mechanical HVAC floor plan blueprint. Please describe: 1. What types of unit symbols do you see on the actual floor plan (not in tables/schedules)? 2. What are the tag labels printed on or beside those unit symbols? 3. List any tag labels you can read exactly as they appear (e.g. "AC-Q", "FCU-1", "ERV-2", etc.) 4. Where on the page are the unit symbols located (describe areas like upper-left, lower-right, etc.)? Be specific about the actual text labels you see next to unit symbols on the drawing itself.""" response = client.models.generate_content( model='gemini-2.5-flash', contents=[prompt, genai_types.Part.from_bytes(data=img_bytes, mime_type='image/png')], config=genai_types.GenerateContentConfig(max_output_tokens=4096, temperature=0.0), ) print(response.text)