askrobots / dbbasic-web-native
Public
100+ copy-paste UI components in plain HTML and CSS: no dependencies, no build step.
danq9
Add canonical.html v1.0 - The single source of truth for usability standards
fb6e650
1 year ago
History
analyze-screenshot.py · 2.2 KB · 67 lines
| 1 | #!/usr/bin/env python3 |
| 2 | import os |
| 3 | import base64 |
| 4 | import json |
| 5 | from pathlib import Path |
| 6 | from anthropic import Anthropic |
| 7 | |
| 8 | # Load API key |
| 9 | def load_env(): |
| 10 | env_path = Path.cwd() / '.env' |
| 11 | if env_path.exists(): |
| 12 | with open(env_path) as f: |
| 13 | for line in f: |
| 14 | line = line.strip() |
| 15 | if line and not line.startswith('#') and '=' in line: |
| 16 | key, value = line.split('=', 1) |
| 17 | os.environ[key.strip()] = value.strip() |
| 18 | |
| 19 | load_env() |
| 20 | |
| 21 | screenshot_path = '/Users/danq/dbbasic-web-native/demo-fixed-layout.png' |
| 22 | |
| 23 | # Encode image |
| 24 | with open(screenshot_path, 'rb') as f: |
| 25 | image_data = base64.standard_b64encode(f.read()).decode('utf-8') |
| 26 | |
| 27 | # Analyze |
| 28 | client = Anthropic(api_key=os.environ.get('ANTHROPIC_API_KEY')) |
| 29 | |
| 30 | prompt = """Analyze this SaaS landing page for layout and alignment issues. |
| 31 | |
| 32 | Focus on: |
| 33 | 1. HEADER: Is "ProductName" logo visible? Where is it positioned (left edge, centered, or somewhere else)? Where are the navigation links (Features, Pricing, Testimonials) and "Sign Up Free" button positioned? |
| 34 | |
| 35 | 2. HERO SECTION: Are the heading, buttons, and badges properly centered? Specifically check if the two small badges (green one and outline one) are centered under the buttons or off to one side. |
| 36 | |
| 37 | 3. "EVERYTHING YOU NEED" SECTION: Are the 3 feature cards properly distributed across the full width, or are they bunched on the left/centered with empty space? |
| 38 | |
| 39 | Describe EXACTLY what you see with specific positions. Be very precise about whether elements are at the left edge, centered, or have proper spacing.""" |
| 40 | |
| 41 | response = client.messages.create( |
| 42 | model="claude-sonnet-4-5", |
| 43 | max_tokens=2048, |
| 44 | messages=[{ |
| 45 | "role": "user", |
| 46 | "content": [ |
| 47 | { |
| 48 | "type": "image", |
| 49 | "source": { |
| 50 | "type": "base64", |
| 51 | "media_type": "image/png", |
| 52 | "data": image_data |
| 53 | } |
| 54 | }, |
| 55 | { |
| 56 | "type": "text", |
| 57 | "text": prompt |
| 58 | } |
| 59 | ] |
| 60 | }] |
| 61 | ) |
| 62 | |
| 63 | print("\n" + "="*80) |
| 64 | print("AI VISION ANALYSIS OF SCREENSHOT") |
| 65 | print("="*80 + "\n") |
| 66 | print(response.content[0].text) |
| 67 | print("\n" + "="*80 + "\n") |