Spaces:
Sleeping
Sleeping
Download agents/design_variation_generator.py from OneWeekApp/space-ac-design: direct link, hf CLI and curl.
- Browser
- Download file 16.7 kB
-
https://huggingface.co/spaces/OneWeekApp/space-ac-design/resolve/main/agents/design_variation_generator.py
- Command line
-
hf download hf://spaces/OneWeekApp/space-ac-design/agents/design_variation_generator.py
-
curl -L -o design_variation_generator.py https://huggingface.co/spaces/OneWeekApp/space-ac-design/resolve/main/agents/design_variation_generator.py
16.7 kB
| """ | |
| 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"]) | |