100+ copy-paste UI components in plain HTML and CSS: no dependencies, no build step.

0 downloads

dbbasic-web-native/test_one.py
Download zip
Clone
Clone with git
git clone https://gitstable.com/git/askrobots/dbbasic-web-native.git
HTTPS
https://gitstable.com/git/askrobots/dbbasic-web-native.git
SSH
ssh://git@gitstable.com:2222/askrobots/dbbasic-web-native.git

Cloning needs no sign-in. Pushing over HTTPS asks for your username and an access token. SSH needs your key under SSH keys.

danq9 Add canonical.html v1.0 - The single source of truth for usability standards fb6e650 1 year ago History
test_one.py · 2.2 KB · 82 lines
1#!/usr/bin/env python3
2"""Quick test of AI vision analysis on one component"""
3
4import os
5import base64
6from pathlib import Path
7from anthropic import Anthropic
8
9# Load .env
10env_path = Path(__file__).parent / '.env'
11if 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
19api_key = os.environ.get('ANTHROPIC_API_KEY')
20if not api_key:
21 print("❌ No API key found")
22 exit(1)
23
24client = Anthropic(api_key=api_key)
25
26# Test on semantic-action screenshot
27screenshot = Path(__file__).parent / 'screenshots' / 'semantic-action.html.png'
28
29if not screenshot.exists():
30 print(f"❌ Screenshot not found: {screenshot}")
31 print("Run: python3 test_visual_ai.py first to capture screenshots")
32 exit(1)
33
34print(f"🤖 Testing AI vision on {screenshot.name}...\n")
35
36# Encode image
37with open(screenshot, 'rb') as f:
38 image_data = base64.standard_b64encode(f.read()).decode('utf-8')
39
40# Prompt
41prompt = """Analyze this component screenshot for WCAG AA contrast compliance:
42
431. Identify all text elements
442. Measure approximate contrast ratios between text and backgrounds
453. Flag any text below 4.5:1 contrast (normal text) or 3:1 (large text 18pt+)
464. List specific failures with colors if detected
47
48Return ONLY valid JSON (no markdown):
49{
50 "passed": true/false,
51 "issues": [
52 {"element": "Save button", "contrast": "3.2:1", "colors": "white on #007aff", "severity": "fail"}
53 ]
54}"""
55
56# Call API
57print("Sending to Claude Sonnet 4.5...")
58message = client.messages.create(
59 model="claude-sonnet-4-5",
60 max_tokens=1024,
61 messages=[{
62 "role": "user",
63 "content": [
64 {
65 "type": "image",
66 "source": {
67 "type": "base64",
68 "media_type": "image/png",
69 "data": image_data
70 }
71 },
72 {
73 "type": "text",
74 "text": prompt
75 }
76 ]
77 }]
78)
79
80print("\n✅ Response received!\n")
81print("Raw response:")
82print(message.content[0].text)