Spaces:
Running
Running
File size: 5,097 Bytes
46a8a46 | 1 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 | """
Section title Designer
- Fixed style for current version
"""
import json
from pathlib import Path
from typing import Dict, Any, List
from src.state.poster_state import PosterState
from utils.src.logging_utils import log_agent_info, log_agent_success, log_agent_error
class SectionTitleDesigner:
def __init__(self):
self.name = "section_title_designer"
def __call__(self, state: PosterState) -> PosterState:
log_agent_info(self.name, "generating section title styling (code-based, Style 2 only)")
try:
story_board = state.get("story_board")
color_scheme = state.get("color_scheme")
if not story_board:
log_agent_error(self.name, "missing story_board")
raise ValueError("missing story_board from curator")
if not color_scheme:
log_agent_error(self.name, "missing color_scheme")
raise ValueError("missing color_scheme from color agent")
title_design = self._generate_colorblock_design(story_board, color_scheme)
state["section_title_design"] = title_design
state["current_agent"] = self.name
self._save_title_design(state)
log_agent_success(self.name, "generated section title styling")
log_agent_info(self.name, f"theme color: {color_scheme.get('theme', 'unknown')}")
except Exception as e:
log_agent_error(self.name, f"failed: {e}")
state["errors"].append(f"{self.name}: {e}")
return state
def _generate_colorblock_design(self, story_board: Dict, color_scheme: Dict) -> Dict:
"""Generate colorblock design"""
sections = story_board.get("spatial_content_plan", {}).get("sections", [])
# color mapping from color_scheme for rectangle_left template
colors = self._map_rectangle_colors(color_scheme)
# applications for all sections
applications = self._generate_rectangle_applications(sections, colors)
return {
"section_title_design": {
"selected_template": "rectangle_left",
"design_rationale": "Code-generated rectangle_left template for modern, design-forward appearance with color accent",
"color_palette": colors,
"spacing_specifications": {
"title_left_padding": "4_spaces",
"rectangle_to_content_gap": 0.15
},
"section_applications": applications
}
}
def _map_rectangle_colors(self, color_scheme: Dict) -> Dict:
"""Map color scheme to rectangle_left template colors"""
theme_color = color_scheme.get("theme", "#1E3A8A")
mono_light = color_scheme.get("mono_light", "#335f91")
mono_dark = color_scheme.get("mono_dark", "#002c5e")
return {
"theme_color": theme_color,
"mono_light": mono_light,
"mono_dark": mono_dark,
"title_text_color": "#000000", # black for readability on colored background
"accent_rectangle_color": theme_color,
"background_color": "#FFFFFF"
}
def _generate_rectangle_applications(self, sections: List[Dict], colors: Dict) -> List[Dict]:
applications = []
for section in sections:
application = {
"section_id": section["section_id"],
"section_title": section.get("section_title", ""),
"title_styling": {
"font_family": "Helvetica Neue",
"font_size": 48, # this will be overridden by styling_interfaces font_sizes
"font_weight": "bold",
"color": colors["title_text_color"],
"alignment": "left"
},
"accent_styling": {
"type": "rectangle",
"color": colors["accent_rectangle_color"],
"dimensions": {"width": "golden_ratio_based_on_height", "height": "title_height"},
"position": "same_row"
}
}
applications.append(application)
return applications
def _save_title_design(self, state: PosterState):
"""Save title design to json file"""
output_dir = Path(state["output_dir"]) / "content"
output_dir.mkdir(parents=True, exist_ok=True)
with open(output_dir / "section_title_design.json", "w", encoding='utf-8') as f:
json.dump(state.get("section_title_design", {}), f, indent=2)
def section_title_designer_node(state: PosterState) -> Dict[str, Any]:
result = SectionTitleDesigner()(state)
return {
**state,
"section_title_design": result["section_title_design"],
"current_agent": result["current_agent"],
"errors": result["errors"]
} |