Technologic101 commited on
Commit
1ef09d2
·
1 Parent(s): 21dc073

task: refactors and refines analyzer prompts

Browse files
data_collection/analyze_designs.py CHANGED
@@ -5,12 +5,13 @@ import asyncio
5
  import base64
6
  from openai import AsyncOpenAI
7
  from dotenv import load_dotenv
 
 
8
 
9
  load_dotenv()
 
10
 
11
- VISION_MODEL = "gpt-4o-2024-08-06"
12
-
13
- client = AsyncOpenAI()
14
 
15
  async def analyze_screenshot(design_id: str, design_path: Path):
16
  """Analyze screenshots and return description, categories, and visual characteristics"""
@@ -46,21 +47,7 @@ async def analyze_screenshot(design_id: str, design_path: Path):
46
  messages=[
47
  {
48
  "role": "system",
49
- "content": """You are an expert graphic designer analyzing print and web designs for aesthetics, functionality, audience appeal, and potential applications.
50
-
51
- The design should be considered from a visual standpoint. Use chain of thought to consider color palette, visual layout, typography, artistic style, mood, and potential applications.
52
- Consider gradients, texture, background effects, and the use of images.
53
-
54
- Treat all text content as placeholder Lorem Ipsum.
55
-
56
- Provide analysis in clean JSON format with these exact keys:
57
- {
58
- "description": "A one-paragraph summary highlighting exceptional features of the design",
59
- "categories": ["category1", "category2"],
60
- "visual_characteristics": ["characteristic1", "characteristic2"]
61
- }
62
- Provide 4-6 categories and 4-6 visual characteristics most relevant to the style and feel of the design. Do not reference css or web design directly because this analysis is primarily about design. These lists should describe the design to another LLM that will use this data to generate a UI.
63
- """
64
  },
65
  {
66
  "role": "user",
@@ -115,7 +102,7 @@ async def analyze_screenshot(design_id: str, design_path: Path):
115
 
116
  print(f"Successfully analyzed design {design_id}")
117
  # Return visual_characteristics as fourth element
118
- return design_id, analysis["description"], analysis["categories"], analysis["visual_characteristics"]
119
 
120
  except json.JSONDecodeError as e:
121
  print(f"Error parsing JSON response for design {design_id}: {str(e)}")
 
5
  import base64
6
  from openai import AsyncOpenAI
7
  from dotenv import load_dotenv
8
+ from anthropic import Anthropic
9
+ from .prompts import get_prompt
10
 
11
  load_dotenv()
12
+ client = Anthropic()
13
 
14
+ VISION_MODEL = "claude-3-7-sonnet-20250219"
 
 
15
 
16
  async def analyze_screenshot(design_id: str, design_path: Path):
17
  """Analyze screenshots and return description, categories, and visual characteristics"""
 
47
  messages=[
48
  {
49
  "role": "system",
50
+ "content": get_prompt(detailed=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51
  },
52
  {
53
  "role": "user",
 
102
 
103
  print(f"Successfully analyzed design {design_id}")
104
  # Return visual_characteristics as fourth element
105
+ return design_id, analysis["description"]["summary"], analysis["categories"], analysis["visual_characteristics"]
106
 
107
  except json.JSONDecodeError as e:
108
  print(f"Error parsing JSON response for design {design_id}: {str(e)}")
data_collection/prompts.py ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Prompt templates for design analysis using different levels of detail.
3
+ Each template is optimized for Claude 3.7 Sonnet's visual processing capabilities.
4
+ """
5
+
6
+ DETAILED_ANALYSIS_PROMPT = """You are an expert design analyst with deep knowledge of visual design, aesthetics, human perception, and design history. Analyze designs holistically, considering their artistic merit, cultural context, and historical influences.
7
+
8
+ For each design, perform a detailed visual analysis considering:
9
+ 1. Visual Composition & Hierarchy
10
+ - Layout structure and flow
11
+ - Balance and white space
12
+ - Focal points and emphasis
13
+
14
+ 2. Color & Atmosphere
15
+ - Color palette and relationships
16
+ - Emotional resonance
17
+ - Light and shadow
18
+
19
+ 3. Typography & Text Treatment
20
+ - Font choices and pairings
21
+ - Text hierarchy
22
+ - Readability and rhythm
23
+
24
+ 4. Texture & Depth
25
+ - Surface treatments
26
+ - Layering effects
27
+ - Material suggestions
28
+
29
+ 5. Artistic Elements
30
+ - Stylistic influences
31
+ - Decorative elements
32
+ - Visual metaphors
33
+
34
+ 6. Historical & Cultural Context
35
+ - Era-specific design trends
36
+ - Cultural references and influences
37
+ - Design movement associations
38
+
39
+ Provide analysis in the following JSON format:
40
+ {
41
+ "description": {
42
+ "summary": "A compelling one-paragraph overview of the design's most distinctive features",
43
+ "visual_style": "Detailed analysis of the design's artistic approach and visual language",
44
+ "emotional_impact": "Description of the mood, atmosphere, and emotional response the design evokes",
45
+ "compositional_elements": "Analysis of how different design elements work together"
46
+ },
47
+ "historical_context": {
48
+ "era_indicators": "Design elements that place this in a specific time period",
49
+ "cultural_references": "Cultural and artistic movements referenced in the design",
50
+ "design_trends": "Contemporary or historical design trends evident in the work"
51
+ },
52
+ "categories": [
53
+ "Primary design categories (4-6 items)",
54
+ "Include both timeless and era-specific categories"
55
+ ],
56
+ "visual_characteristics": [
57
+ "Specific visual techniques and elements (4-6 items)",
58
+ "Include both contemporary and historical design elements"
59
+ ],
60
+ "temporal_markers": {
61
+ "design_period": "Estimated time period or range",
62
+ "characteristic_elements": ["List of elements typical of this period"]
63
+ }
64
+ }"""
65
+
66
+ CORE_ANALYSIS_PROMPT = """You are an expert design analyst. Analyze the visual design, focusing on the most essential elements that define its style and character.
67
+
68
+ Consider:
69
+ 1. Overall composition and layout
70
+ 2. Color palette and mood
71
+ 3. Typography and text treatment
72
+ 4. Key visual elements and textures
73
+ 5. Historical/cultural indicators
74
+
75
+ Provide analysis in the following JSON format:
76
+ {
77
+ "description": "A concise summary highlighting the design's most distinctive features",
78
+ "categories": [
79
+ "4-5 primary design categories that best classify this design"
80
+ ],
81
+ "visual_characteristics": [
82
+ "4-5 specific visual techniques or elements that define this design"
83
+ ],
84
+ "era_indicators": {
85
+ "period": "Estimated time period",
86
+ "key_elements": ["2-3 elements that date this design"]
87
+ }
88
+ }"""
89
+
90
+ def get_prompt(detailed: bool = True) -> str:
91
+ """
92
+ Returns the appropriate prompt template based on the desired detail level.
93
+
94
+ Args:
95
+ detailed (bool): If True, returns the detailed analysis prompt.
96
+ If False, returns the core analysis prompt.
97
+
98
+ Returns:
99
+ str: The selected prompt template
100
+ """
101
+ return DETAILED_ANALYSIS_PROMPT if detailed else CORE_ANALYSIS_PROMPT
data_collection/scraper.py CHANGED
@@ -36,7 +36,7 @@ async def take_screenshot(url, directory):
36
  # Wait for network to be idle (no requests for at least 500ms)
37
  await page.wait_for_load_state("networkidle")
38
  # Add a significant delay to ensure background images are loaded
39
- await page.wait_for_timeout(2000)
40
 
41
  # Get full height
42
  height = await page.evaluate('document.body.scrollHeight')
 
36
  # Wait for network to be idle (no requests for at least 500ms)
37
  await page.wait_for_load_state("networkidle")
38
  # Add a significant delay to ensure background images are loaded
39
+ await page.wait_for_timeout(3000)
40
 
41
  # Get full height
42
  height = await page.evaluate('document.body.scrollHeight')
pyproject.toml CHANGED
@@ -37,6 +37,7 @@ dependencies = [
37
  "matplotlib>=3.10.0",
38
  "accelerate>=0.26.0",
39
  "nest-asyncio>=1.6.0",
 
40
  ]
41
 
42
  [build-system]
 
37
  "matplotlib>=3.10.0",
38
  "accelerate>=0.26.0",
39
  "nest-asyncio>=1.6.0",
40
+ "anthropic>=0.49.0",
41
  ]
42
 
43
  [build-system]
uv.lock CHANGED
@@ -1,4 +1,5 @@
1
  version = 1
 
2
  requires-python = "==3.11.*"
3
 
4
  [[package]]
@@ -91,6 +92,24 @@ wheels = [
91
  { url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643 },
92
  ]
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  [[package]]
95
  name = "anyio"
96
  version = "4.8.0"
@@ -853,6 +872,7 @@ version = "0.1.0"
853
  source = { editable = "." }
854
  dependencies = [
855
  { name = "accelerate" },
 
856
  { name = "beautifulsoup4" },
857
  { name = "chainlit" },
858
  { name = "datasets" },
@@ -886,6 +906,7 @@ dependencies = [
886
  [package.metadata]
887
  requires-dist = [
888
  { name = "accelerate", specifier = ">=0.26.0" },
 
889
  { name = "beautifulsoup4", specifier = ">=4.12.0" },
890
  { name = "chainlit", specifier = ">=0.7.700" },
891
  { name = "datasets", specifier = ">=2.17.0" },
 
1
  version = 1
2
+ revision = 1
3
  requires-python = "==3.11.*"
4
 
5
  [[package]]
 
92
  { url = "https://files.pythonhosted.org/packages/78/b6/6307fbef88d9b5ee7421e68d78a9f162e0da4900bc5f5793f6d3d0e34fb8/annotated_types-0.7.0-py3-none-any.whl", hash = "sha256:1f02e8b43a8fbbc3f3e0d4f0f4bfc8131bcb4eebe8849b8e5c773f3a1c582a53", size = 13643 },
93
  ]
94
 
95
+ [[package]]
96
+ name = "anthropic"
97
+ version = "0.49.0"
98
+ source = { registry = "https://pypi.org/simple" }
99
+ dependencies = [
100
+ { name = "anyio" },
101
+ { name = "distro" },
102
+ { name = "httpx" },
103
+ { name = "jiter" },
104
+ { name = "pydantic" },
105
+ { name = "sniffio" },
106
+ { name = "typing-extensions" },
107
+ ]
108
+ sdist = { url = "https://files.pythonhosted.org/packages/86/e3/a88c8494ce4d1a88252b9e053607e885f9b14d0a32273d47b727cbee4228/anthropic-0.49.0.tar.gz", hash = "sha256:c09e885b0f674b9119b4f296d8508907f6cff0009bc20d5cf6b35936c40b4398", size = 210016 }
109
+ wheels = [
110
+ { url = "https://files.pythonhosted.org/packages/76/74/5d90ad14d55fbe3f9c474fdcb6e34b4bed99e3be8efac98734a5ddce88c1/anthropic-0.49.0-py3-none-any.whl", hash = "sha256:bbc17ad4e7094988d2fa86b87753ded8dce12498f4b85fe5810f208f454a8375", size = 243368 },
111
+ ]
112
+
113
  [[package]]
114
  name = "anyio"
115
  version = "4.8.0"
 
872
  source = { editable = "." }
873
  dependencies = [
874
  { name = "accelerate" },
875
+ { name = "anthropic" },
876
  { name = "beautifulsoup4" },
877
  { name = "chainlit" },
878
  { name = "datasets" },
 
906
  [package.metadata]
907
  requires-dist = [
908
  { name = "accelerate", specifier = ">=0.26.0" },
909
+ { name = "anthropic", specifier = ">=0.49.0" },
910
  { name = "beautifulsoup4", specifier = ">=4.12.0" },
911
  { name = "chainlit", specifier = ">=0.7.700" },
912
  { name = "datasets", specifier = ">=2.17.0" },