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
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
"""
AC2: Design Variation Generator Agent

Takes moodboard analysis and generates 4 complete design theme variations,
each with complete design system specifications.
"""

import json
import os
from typing import Dict, Any, List
from huggingface_hub import InferenceClient


class DesignVariationGenerator:
    """
    Generates 4 complete design theme variations from moodboard analysis
    """

    def __init__(self):
        self.hf_token = os.getenv("HF_TOKEN")
        # Explicitly use HF provider (not third-party like Hyperbolic)
        self.client = InferenceClient(token=self.hf_token, provider="hf-inference")
        self.text_model = "meta-llama/Llama-3.1-70B-Instruct"

    def process(self, input_data: Dict[str, Any]) -> Dict[str, Any]:
        """
        Main processing function

        Input:
            moodboard_analysis: Output from AC1
            wireframe: Wireframe description
            app_context: App context information

        Output:
            themes: List of 4 complete design themes
        """

        moodboard_analysis = input_data.get("moodboard_analysis", {})
        wireframe = input_data.get("wireframe", "")
        app_context = input_data.get("app_context", {})

        # Extract key info from moodboard
        color_palettes = moodboard_analysis.get("color_palettes", [])
        typography_trends = moodboard_analysis.get("typography_trends", [])
        ui_patterns = moodboard_analysis.get("ui_patterns", [])

        # Generate 4 distinct themes
        themes = self._generate_four_themes(
            color_palettes,
            typography_trends,
            ui_patterns,
            app_context
        )

        return {
            "themes": themes,
            "total_themes": len(themes),
            "based_on_moodboard": True
        }

    def _generate_four_themes(
        self,
        color_palettes: List[Dict],
        typography_trends: List[Dict],
        ui_patterns: List[Dict],
        app_context: Dict
    ) -> List[Dict]:
        """
        Generate 4 distinct design themes
        """

        themes = []

        # Theme templates based on common design styles
        theme_templates = [
            {
                "name": "Bold Energy",
                "mood": "Energetic, vibrant, attention-grabbing",
                "style": "bold",
                "base_palette_index": 0
            },
            {
                "name": "Clean Professional",
                "mood": "Professional, trustworthy, minimal",
                "style": "minimal",
                "base_palette_index": 1 if len(color_palettes) > 1 else 0
            },
            {
                "name": "Dark Modern",
                "mood": "Modern, sleek, tech-forward",
                "style": "dark",
                "base_palette_index": 0
            },
            {
                "name": "Playful Fun",
                "mood": "Friendly, approachable, youthful",
                "style": "playful",
                "base_palette_index": 2 if len(color_palettes) > 2 else 0
            }
        ]

        for idx, template in enumerate(theme_templates):
            theme = self._create_theme_from_template(
                template,
                color_palettes,
                typography_trends,
                app_context,
                idx + 1
            )
            themes.append(theme)

        return themes

    def _create_theme_from_template(
        self,
        template: Dict,
        color_palettes: List[Dict],
        typography_trends: List[Dict],
        app_context: Dict,
        theme_number: int
    ) -> Dict:
        """
        Create a complete theme from template
        """

        theme_name = template["name"]
        theme_style = template["style"]

        # Select base palette
        palette_idx = template.get("base_palette_index", 0)
        base_palette = color_palettes[palette_idx] if color_palettes else {}

        # Generate complete color system
        color_system = self._generate_color_system(theme_style, base_palette)

        # Generate typography system
        typography_system = self._generate_typography_system(
            theme_style,
            typography_trends
        )

        # Generate spacing system
        spacing_system = self._generate_spacing_system(theme_style)

        # Generate component styles
        component_styles = self._generate_component_styles(theme_style)

        # Generate animation specs
        animation_specs = self._generate_animation_specs(theme_style)

        return {
            "id": f"theme_{theme_number}",
            "name": theme_name,
            "mood": template["mood"],
            "style": theme_style,
            "palette": color_system,
            "typography": typography_system,
            "spacing": spacing_system,
            "borders": self._generate_border_specs(theme_style),
            "shadows": self._generate_shadow_specs(theme_style),
            "component_style": component_styles,
            "animations": animation_specs,
            "inspiration": self._get_inspiration_apps(theme_style)
        }

    def _generate_color_system(
        self,
        style: str,
        base_palette: Dict
    ) -> Dict:
        """
        Generate complete color system for a theme
        """

        color_systems = {
            "bold": {
                "primary": "#FF3B30",
                "secondary": "#FFD60A",
                "background": "#FFFFFF",
                "surface": "#F5F5F5",
                "success": "#34C759",
                "error": "#FF3B30",
                "warning": "#FF9500",
                "text_primary": "#000000",
                "text_secondary": "#8E8E93",
                "border": "#E0E0E0"
            },
            "minimal": {
                "primary": "#007AFF",
                "secondary": "#5856D6",
                "background": "#FFFFFF",
                "surface": "#F9F9F9",
                "success": "#34C759",
                "error": "#FF3B30",
                "warning": "#FF9500",
                "text_primary": "#1C1C1E",
                "text_secondary": "#8E8E93",
                "border": "#E5E5EA"
            },
            "dark": {
                "primary": "#BB86FC",
                "secondary": "#03DAC6",
                "background": "#121212",
                "surface": "#1E1E1E",
                "success": "#00C853",
                "error": "#CF6679",
                "warning": "#FFC107",
                "text_primary": "#FFFFFF",
                "text_secondary": "#B0B0B0",
                "border": "#2C2C2C"
            },
            "playful": {
                "primary": "#FF2D55",
                "secondary": "#5856D6",
                "background": "#FFFFFF",
                "surface": "#FFF5F7",
                "success": "#34C759",
                "error": "#FF3B30",
                "warning": "#FF9500",
                "text_primary": "#1C1C1E",
                "text_secondary": "#8E8E93",
                "border": "#FFD0DD"
            }
        }

        return color_systems.get(style, color_systems["minimal"])

    def _generate_typography_system(
        self,
        style: str,
        typography_trends: List[Dict]
    ) -> Dict:
        """
        Generate typography system
        """

        typography_systems = {
            "bold": {
                "display": {
                    "font_family": "Bebas Neue",
                    "weight": 700,
                    "sizes": {
                        "h1": "40px",
                        "h2": "32px",
                        "h3": "24px"
                    }
                },
                "body": {
                    "font_family": "Inter",
                    "weight": 400,
                    "sizes": {
                        "large": "18px",
                        "regular": "16px",
                        "small": "14px"
                    }
                },
                "numbers": {
                    "font_family": "Rajdhani",
                    "weight": 700
                }
            },
            "minimal": {
                "display": {
                    "font_family": "SF Pro Display",
                    "weight": 600,
                    "sizes": {
                        "h1": "34px",
                        "h2": "28px",
                        "h3": "22px"
                    }
                },
                "body": {
                    "font_family": "SF Pro Text",
                    "weight": 400,
                    "sizes": {
                        "large": "17px",
                        "regular": "15px",
                        "small": "13px"
                    }
                }
            },
            "dark": {
                "display": {
                    "font_family": "JetBrains Mono",
                    "weight": 700,
                    "sizes": {
                        "h1": "36px",
                        "h2": "30px",
                        "h3": "24px"
                    }
                },
                "body": {
                    "font_family": "Inter",
                    "weight": 400,
                    "sizes": {
                        "large": "18px",
                        "regular": "16px",
                        "small": "14px"
                    }
                }
            },
            "playful": {
                "display": {
                    "font_family": "Quicksand",
                    "weight": 700,
                    "sizes": {
                        "h1": "38px",
                        "h2": "30px",
                        "h3": "24px"
                    }
                },
                "body": {
                    "font_family": "Nunito",
                    "weight": 400,
                    "sizes": {
                        "large": "18px",
                        "regular": "16px",
                        "small": "14px"
                    }
                }
            }
        }

        return typography_systems.get(style, typography_systems["minimal"])

    def _generate_spacing_system(self, style: str) -> Dict:
        """Generate spacing system"""

        base_unit = 8 if style != "playful" else 12

        return {
            "unit": base_unit,
            "scale": [
                base_unit * 0.5,  # 4 or 6
                base_unit,        # 8 or 12
                base_unit * 2,    # 16 or 24
                base_unit * 3,    # 24 or 36
                base_unit * 4,    # 32 or 48
                base_unit * 6,    # 48 or 72
                base_unit * 8     # 64 or 96
            ]
        }

    def _generate_border_specs(self, style: str) -> Dict:
        """Generate border specifications"""

        border_specs = {
            "bold": {
                "radius": {
                    "small": "4px",
                    "medium": "8px",
                    "large": "12px"
                },
                "width": {
                    "thin": "1px",
                    "regular": "2px",
                    "thick": "3px"
                }
            },
            "minimal": {
                "radius": {
                    "small": "4px",
                    "medium": "8px",
                    "large": "16px"
                },
                "width": {
                    "thin": "1px",
                    "regular": "1px",
                    "thick": "2px"
                }
            },
            "dark": {
                "radius": {
                    "small": "2px",
                    "medium": "4px",
                    "large": "8px"
                },
                "width": {
                    "thin": "1px",
                    "regular": "1px",
                    "thick": "2px"
                }
            },
            "playful": {
                "radius": {
                    "small": "12px",
                    "medium": "20px",
                    "large": "28px"
                },
                "width": {
                    "thin": "2px",
                    "regular": "3px",
                    "thick": "4px"
                }
            }
        }

        return border_specs.get(style, border_specs["minimal"])

    def _generate_shadow_specs(self, style: str) -> Dict:
        """Generate shadow specifications"""

        shadow_specs = {
            "bold": {
                "small": "0 2px 4px rgba(0,0,0,0.2)",
                "medium": "0 4px 8px rgba(0,0,0,0.25)",
                "large": "0 8px 16px rgba(0,0,0,0.3)"
            },
            "minimal": {
                "small": "0 1px 2px rgba(0,0,0,0.05)",
                "medium": "0 2px 4px rgba(0,0,0,0.08)",
                "large": "0 4px 8px rgba(0,0,0,0.12)"
            },
            "dark": {
                "small": "0 2px 8px rgba(0,0,0,0.5)",
                "medium": "0 4px 12px rgba(0,0,0,0.6)",
                "large": "0 8px 24px rgba(0,0,0,0.7)",
                "glow": "0 0 20px rgba(187,134,252,0.5)"
            },
            "playful": {
                "small": "0 2px 8px rgba(255,45,85,0.15)",
                "medium": "0 4px 12px rgba(255,45,85,0.2)",
                "large": "0 8px 24px rgba(255,45,85,0.25)"
            }
        }

        return shadow_specs.get(style, shadow_specs["minimal"])

    def _generate_component_styles(self, style: str) -> Dict:
        """Generate component style descriptions"""

        component_styles = {
            "bold": {
                "buttons": "3D effect with hard shadows, bold text, high contrast",
                "cards": "Elevated with glowing borders, strong shadows",
                "icons": "Filled style, bold weight, vibrant colors",
                "inputs": "Thick borders, high contrast, bold labels"
            },
            "minimal": {
                "buttons": "Flat design, subtle borders, clean text",
                "cards": "Subtle shadows, white background, minimal borders",
                "icons": "Outlined style, regular weight, monochrome",
                "inputs": "Thin borders, subtle focus states, light labels"
            },
            "dark": {
                "buttons": "Neon glow effect, transparent background, tech-inspired",
                "cards": "Dark surface with neon accent lines, subtle glow",
                "icons": "Filled with glow effect, tech aesthetic",
                "inputs": "Glow borders, dark background, bright text"
            },
            "playful": {
                "buttons": "Rounded corners, gradient backgrounds, bounce animations",
                "cards": "Very rounded corners, colorful gradient backgrounds",
                "icons": "Filled, colorful, friendly style",
                "inputs": "Rounded borders, soft colors, friendly labels"
            }
        }

        return component_styles.get(style, component_styles["minimal"])

    def _generate_animation_specs(self, style: str) -> Dict:
        """Generate animation specifications"""

        animation_specs = {
            "bold": {
                "speed": "Fast (200-300ms)",
                "easing": "ease-in-out",
                "style": "Bounce, elastic, scale",
                "transitions": ["scale", "opacity", "transform"]
            },
            "minimal": {
                "speed": "Medium (300-400ms)",
                "easing": "ease-out",
                "style": "Fade, subtle slide",
                "transitions": ["opacity", "transform"]
            },
            "dark": {
                "speed": "Medium-Fast (250-350ms)",
                "easing": "cubic-bezier(0.4, 0, 0.2, 1)",
                "style": "Fade, glow pulse, glitch",
                "transitions": ["opacity", "box-shadow", "transform"]
            },
            "playful": {
                "speed": "Slow (400-500ms)",
                "easing": "cubic-bezier(0.68, -0.55, 0.265, 1.55)",
                "style": "Bounce, wiggle, pop, spring",
                "transitions": ["transform", "scale", "rotate"]
            }
        }

        return animation_specs.get(style, animation_specs["minimal"])

    def _get_inspiration_apps(self, style: str) -> List[str]:
        """Get inspiration app examples for each style"""

        inspiration = {
            "bold": ["PUBG Mobile", "Fortnite", "Uber Driver", "Deliveroo Rider"],
            "minimal": ["Apple Health", "Notion", "Linear", "Things 3"],
            "dark": ["Spotify", "Discord", "GitHub Dark", "VS Code"],
            "playful": ["Duolingo", "Headspace", "Calm", "TikTok"]
        }

        return inspiration.get(style, ["Modern Apps"])