init
This commit is contained in:
215
.opencode/skills/design/scripts/cip/core.py
Normal file
215
.opencode/skills/design/scripts/cip/core.py
Normal file
@@ -0,0 +1,215 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
CIP Design Core - BM25 search engine for Corporate Identity Program design guidelines
|
||||
"""
|
||||
|
||||
import csv
|
||||
import re
|
||||
from pathlib import Path
|
||||
from math import log
|
||||
from collections import defaultdict
|
||||
|
||||
# ============ CONFIGURATION ============
|
||||
DATA_DIR = Path(__file__).parent.parent.parent / "data" / "cip"
|
||||
MAX_RESULTS = 3
|
||||
|
||||
CSV_CONFIG = {
|
||||
"deliverable": {
|
||||
"file": "deliverables.csv",
|
||||
"search_cols": ["Deliverable", "Category", "Keywords", "Description", "Mockup Context"],
|
||||
"output_cols": ["Deliverable", "Category", "Keywords", "Description", "Dimensions", "File Format", "Logo Placement", "Color Usage", "Typography Notes", "Mockup Context", "Best Practices", "Avoid"]
|
||||
},
|
||||
"style": {
|
||||
"file": "styles.csv",
|
||||
"search_cols": ["Style Name", "Category", "Keywords", "Description", "Mood"],
|
||||
"output_cols": ["Style Name", "Category", "Keywords", "Description", "Primary Colors", "Secondary Colors", "Typography", "Materials", "Finishes", "Mood", "Best For", "Avoid For"]
|
||||
},
|
||||
"industry": {
|
||||
"file": "industries.csv",
|
||||
"search_cols": ["Industry", "Keywords", "CIP Style", "Mood"],
|
||||
"output_cols": ["Industry", "Keywords", "CIP Style", "Primary Colors", "Secondary Colors", "Typography", "Key Deliverables", "Mood", "Best Practices", "Avoid"]
|
||||
},
|
||||
"mockup": {
|
||||
"file": "mockup-contexts.csv",
|
||||
"search_cols": ["Context Name", "Category", "Keywords", "Scene Description"],
|
||||
"output_cols": ["Context Name", "Category", "Keywords", "Scene Description", "Lighting", "Environment", "Props", "Camera Angle", "Background", "Style Notes", "Best For", "Prompt Modifiers"]
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# ============ BM25 IMPLEMENTATION ============
|
||||
class BM25:
|
||||
"""BM25 ranking algorithm for text search"""
|
||||
|
||||
def __init__(self, k1=1.5, b=0.75):
|
||||
self.k1 = k1
|
||||
self.b = b
|
||||
self.corpus = []
|
||||
self.doc_lengths = []
|
||||
self.avgdl = 0
|
||||
self.idf = {}
|
||||
self.doc_freqs = defaultdict(int)
|
||||
self.N = 0
|
||||
|
||||
def tokenize(self, text):
|
||||
"""Lowercase, split, remove punctuation, filter short words"""
|
||||
text = re.sub(r'[^\w\s]', ' ', str(text).lower())
|
||||
return [w for w in text.split() if len(w) > 2]
|
||||
|
||||
def fit(self, documents):
|
||||
"""Build BM25 index from documents"""
|
||||
self.corpus = [self.tokenize(doc) for doc in documents]
|
||||
self.N = len(self.corpus)
|
||||
if self.N == 0:
|
||||
return
|
||||
self.doc_lengths = [len(doc) for doc in self.corpus]
|
||||
self.avgdl = sum(self.doc_lengths) / self.N
|
||||
|
||||
for doc in self.corpus:
|
||||
seen = set()
|
||||
for word in doc:
|
||||
if word not in seen:
|
||||
self.doc_freqs[word] += 1
|
||||
seen.add(word)
|
||||
|
||||
for word, freq in self.doc_freqs.items():
|
||||
self.idf[word] = log((self.N - freq + 0.5) / (freq + 0.5) + 1)
|
||||
|
||||
def score(self, query):
|
||||
"""Score all documents against query"""
|
||||
query_tokens = self.tokenize(query)
|
||||
scores = []
|
||||
|
||||
for idx, doc in enumerate(self.corpus):
|
||||
score = 0
|
||||
doc_len = self.doc_lengths[idx]
|
||||
term_freqs = defaultdict(int)
|
||||
for word in doc:
|
||||
term_freqs[word] += 1
|
||||
|
||||
for token in query_tokens:
|
||||
if token in self.idf:
|
||||
tf = term_freqs[token]
|
||||
idf = self.idf[token]
|
||||
numerator = tf * (self.k1 + 1)
|
||||
denominator = tf + self.k1 * (1 - self.b + self.b * doc_len / self.avgdl)
|
||||
score += idf * numerator / denominator
|
||||
|
||||
scores.append((idx, score))
|
||||
|
||||
return sorted(scores, key=lambda x: x[1], reverse=True)
|
||||
|
||||
|
||||
# ============ SEARCH FUNCTIONS ============
|
||||
def _load_csv(filepath):
|
||||
"""Load CSV and return list of dicts"""
|
||||
with open(filepath, 'r', encoding='utf-8') as f:
|
||||
return list(csv.DictReader(f))
|
||||
|
||||
|
||||
def _search_csv(filepath, search_cols, output_cols, query, max_results):
|
||||
"""Core search function using BM25"""
|
||||
if not filepath.exists():
|
||||
return []
|
||||
|
||||
data = _load_csv(filepath)
|
||||
|
||||
# Build documents from search columns
|
||||
documents = [" ".join(str(row.get(col, "")) for col in search_cols) for row in data]
|
||||
|
||||
# BM25 search
|
||||
bm25 = BM25()
|
||||
bm25.fit(documents)
|
||||
ranked = bm25.score(query)
|
||||
|
||||
# Get top results with score > 0
|
||||
results = []
|
||||
for idx, score in ranked[:max_results]:
|
||||
if score > 0:
|
||||
row = data[idx]
|
||||
results.append({col: row.get(col, "") for col in output_cols if col in row})
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def detect_domain(query):
|
||||
"""Auto-detect the most relevant domain from query"""
|
||||
query_lower = query.lower()
|
||||
|
||||
domain_keywords = {
|
||||
"deliverable": ["card", "letterhead", "envelope", "folder", "shirt", "cap", "badge", "signage", "vehicle", "car", "van", "stationery", "uniform", "merchandise", "packaging", "banner", "booth"],
|
||||
"style": ["style", "minimal", "modern", "luxury", "vintage", "industrial", "elegant", "bold", "corporate", "organic", "playful"],
|
||||
"industry": ["tech", "finance", "legal", "healthcare", "hospitality", "food", "fashion", "retail", "construction", "logistics"],
|
||||
"mockup": ["mockup", "scene", "context", "photo", "shot", "lighting", "background", "studio", "lifestyle"]
|
||||
}
|
||||
|
||||
scores = {domain: sum(1 for kw in keywords if kw in query_lower) for domain, keywords in domain_keywords.items()}
|
||||
best = max(scores, key=scores.get)
|
||||
return best if scores[best] > 0 else "deliverable"
|
||||
|
||||
|
||||
def search(query, domain=None, max_results=MAX_RESULTS):
|
||||
"""Main search function with auto-domain detection"""
|
||||
if domain is None:
|
||||
domain = detect_domain(query)
|
||||
|
||||
config = CSV_CONFIG.get(domain, CSV_CONFIG["deliverable"])
|
||||
filepath = DATA_DIR / config["file"]
|
||||
|
||||
if not filepath.exists():
|
||||
return {"error": f"File not found: {filepath}", "domain": domain}
|
||||
|
||||
results = _search_csv(filepath, config["search_cols"], config["output_cols"], query, max_results)
|
||||
|
||||
return {
|
||||
"domain": domain,
|
||||
"query": query,
|
||||
"file": config["file"],
|
||||
"count": len(results),
|
||||
"results": results
|
||||
}
|
||||
|
||||
|
||||
def search_all(query, max_results=2):
|
||||
"""Search across all domains and combine results"""
|
||||
all_results = {}
|
||||
for domain in CSV_CONFIG.keys():
|
||||
result = search(query, domain, max_results)
|
||||
if result.get("results"):
|
||||
all_results[domain] = result["results"]
|
||||
return all_results
|
||||
|
||||
|
||||
def get_cip_brief(brand_name, industry_query, style_query=None):
|
||||
"""Generate a comprehensive CIP brief for a brand"""
|
||||
# Search industry
|
||||
industry_results = search(industry_query, "industry", 1)
|
||||
industry = industry_results.get("results", [{}])[0] if industry_results.get("results") else {}
|
||||
|
||||
# Search style (use industry style if not specified)
|
||||
style_query = style_query or industry.get("CIP Style", "corporate minimal")
|
||||
style_results = search(style_query, "style", 1)
|
||||
style = style_results.get("results", [{}])[0] if style_results.get("results") else {}
|
||||
|
||||
# Get recommended deliverables for the industry
|
||||
key_deliverables = industry.get("Key Deliverables", "").split()
|
||||
deliverable_results = []
|
||||
for d in key_deliverables[:5]:
|
||||
result = search(d, "deliverable", 1)
|
||||
if result.get("results"):
|
||||
deliverable_results.append(result["results"][0])
|
||||
|
||||
return {
|
||||
"brand_name": brand_name,
|
||||
"industry": industry,
|
||||
"style": style,
|
||||
"recommended_deliverables": deliverable_results,
|
||||
"color_system": {
|
||||
"primary": style.get("Primary Colors", industry.get("Primary Colors", "")),
|
||||
"secondary": style.get("Secondary Colors", industry.get("Secondary Colors", ""))
|
||||
},
|
||||
"typography": style.get("Typography", industry.get("Typography", "")),
|
||||
"materials": style.get("Materials", ""),
|
||||
"finishes": style.get("Finishes", "")
|
||||
}
|
||||
484
.opencode/skills/design/scripts/cip/generate.py
Normal file
484
.opencode/skills/design/scripts/cip/generate.py
Normal file
@@ -0,0 +1,484 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
CIP Design Generator - Generate corporate identity mockups using Gemini Nano Banana
|
||||
|
||||
Uses Gemini's native image generation (Nano Banana 2/Pro) for high-quality mockups.
|
||||
Supports text-and-image-to-image generation for using actual brand logos.
|
||||
|
||||
- gemini-3.1-flash-image-preview: Nano Banana 2, fastest, 95% Pro quality (default)
|
||||
- gemini-3-pro-image-preview: Pro quality, 4K text rendering
|
||||
|
||||
Image Editing (text-and-image-to-image):
|
||||
When --logo is provided, the script uses Gemini's image editing capability
|
||||
to incorporate the actual logo into CIP mockups instead of generating one.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
# Add parent directory for imports
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
from core import search, get_cip_brief
|
||||
|
||||
# Model options
|
||||
MODELS = {
|
||||
"flash": "gemini-3.1-flash-image-preview", # Nano Banana 2 - fastest, 95% Pro quality (default)
|
||||
"pro": "gemini-3-pro-image-preview" # Nano Banana Pro - quality, 4K text
|
||||
}
|
||||
DEFAULT_MODEL = "flash"
|
||||
|
||||
|
||||
def load_logo_image(logo_path):
|
||||
"""Load logo image using PIL for Gemini image editing"""
|
||||
try:
|
||||
from PIL import Image
|
||||
except ImportError:
|
||||
print("Error: pillow package not installed.")
|
||||
print("Install with: pip install pillow")
|
||||
return None
|
||||
|
||||
logo_path = Path(logo_path)
|
||||
if not logo_path.exists():
|
||||
print(f"Error: Logo file not found: {logo_path}")
|
||||
return None
|
||||
|
||||
try:
|
||||
img = Image.open(logo_path)
|
||||
# Convert to RGB if necessary (Gemini works best with RGB)
|
||||
if img.mode in ('RGBA', 'P'):
|
||||
# Create white background for transparent images
|
||||
background = Image.new('RGB', img.size, (255, 255, 255))
|
||||
if img.mode == 'RGBA':
|
||||
background.paste(img, mask=img.split()[3]) # Use alpha channel as mask
|
||||
else:
|
||||
background.paste(img)
|
||||
img = background
|
||||
elif img.mode != 'RGB':
|
||||
img = img.convert('RGB')
|
||||
return img
|
||||
except Exception as e:
|
||||
print(f"Error loading logo: {e}")
|
||||
return None
|
||||
|
||||
# Load environment variables
|
||||
def load_env():
|
||||
"""Load environment variables from .env files"""
|
||||
env_paths = [
|
||||
Path(__file__).parent.parent.parent / ".env",
|
||||
Path.home() / ".claude" / "skills" / ".env",
|
||||
Path.home() / ".claude" / ".env"
|
||||
]
|
||||
for env_path in env_paths:
|
||||
if env_path.exists():
|
||||
with open(env_path) as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if line and not line.startswith("#") and "=" in line:
|
||||
key, value = line.split("=", 1)
|
||||
if key not in os.environ:
|
||||
os.environ[key] = value.strip('"\'')
|
||||
|
||||
load_env()
|
||||
|
||||
|
||||
def build_cip_prompt(deliverable, brand_name, style=None, industry=None, mockup=None, use_logo_image=False):
|
||||
"""Build an optimized prompt for CIP mockup generation
|
||||
|
||||
Args:
|
||||
deliverable: Type of deliverable (business card, letterhead, etc.)
|
||||
brand_name: Name of the brand
|
||||
style: Design style preference
|
||||
industry: Industry for style recommendations
|
||||
mockup: Mockup context override
|
||||
use_logo_image: If True, prompt is optimized for image editing with logo
|
||||
"""
|
||||
|
||||
# Get deliverable details
|
||||
deliverable_info = search(deliverable, "deliverable", 1)
|
||||
deliverable_data = deliverable_info.get("results", [{}])[0] if deliverable_info.get("results") else {}
|
||||
|
||||
# Get style details
|
||||
style_info = search(style or "corporate minimal", "style", 1) if style else {}
|
||||
style_data = style_info.get("results", [{}])[0] if style_info.get("results") else {}
|
||||
|
||||
# Get industry details
|
||||
industry_info = search(industry or "technology", "industry", 1) if industry else {}
|
||||
industry_data = industry_info.get("results", [{}])[0] if industry_info.get("results") else {}
|
||||
|
||||
# Get mockup context
|
||||
mockup_context = deliverable_data.get("Mockup Context", "clean professional")
|
||||
if mockup:
|
||||
mockup_info = search(mockup, "mockup", 1)
|
||||
if mockup_info.get("results"):
|
||||
mockup_data = mockup_info["results"][0]
|
||||
mockup_context = mockup_data.get("Scene Description", mockup_context)
|
||||
|
||||
# Build prompt components
|
||||
deliverable_name = deliverable_data.get("Deliverable", deliverable)
|
||||
description = deliverable_data.get("Description", "")
|
||||
dimensions = deliverable_data.get("Dimensions", "")
|
||||
logo_placement = deliverable_data.get("Logo Placement", "center")
|
||||
|
||||
style_name = style_data.get("Style Name", style or "corporate")
|
||||
primary_colors = style_data.get("Primary Colors", industry_data.get("Primary Colors", "#0F172A #FFFFFF"))
|
||||
typography = style_data.get("Typography", industry_data.get("Typography", "clean sans-serif"))
|
||||
materials = style_data.get("Materials", "premium quality")
|
||||
finishes = style_data.get("Finishes", "professional")
|
||||
|
||||
mood = style_data.get("Mood", industry_data.get("Mood", "professional"))
|
||||
|
||||
# Construct the prompt - different for image editing vs pure generation
|
||||
if use_logo_image:
|
||||
# Image editing prompt: instructs to USE the provided logo image
|
||||
prompt_parts = [
|
||||
f"Create a professional corporate identity mockup photograph of a {deliverable_name}",
|
||||
f"Use the EXACT logo from the provided image - do NOT modify or recreate the logo",
|
||||
f"The logo MUST appear exactly as shown in the input image",
|
||||
f"Place the logo on the {deliverable_name} at: {logo_placement}",
|
||||
f"Brand name: '{brand_name}'",
|
||||
f"{description}" if description else "",
|
||||
f"Design style: {style_name}",
|
||||
f"Color scheme matching the logo colors",
|
||||
f"Materials: {materials} with {finishes} finish",
|
||||
f"Setting: {mockup_context}",
|
||||
f"Mood: {mood}",
|
||||
"Photorealistic product photography",
|
||||
"Soft natural lighting, professional studio quality",
|
||||
"8K resolution, sharp details"
|
||||
]
|
||||
else:
|
||||
# Pure text-to-image prompt
|
||||
prompt_parts = [
|
||||
f"Professional corporate identity mockup photograph",
|
||||
f"showing {deliverable_name} for brand '{brand_name}'",
|
||||
f"{description}" if description else "",
|
||||
f"{style_name} design style",
|
||||
f"using colors {primary_colors}",
|
||||
f"{typography} typography",
|
||||
f"logo placement: {logo_placement}",
|
||||
f"{materials} materials with {finishes} finish",
|
||||
f"{mockup_context} setting",
|
||||
f"{mood} mood",
|
||||
"photorealistic product photography",
|
||||
"soft natural lighting",
|
||||
"high quality professional shot",
|
||||
"8k resolution detailed"
|
||||
]
|
||||
|
||||
prompt = ", ".join([p for p in prompt_parts if p])
|
||||
|
||||
return {
|
||||
"prompt": prompt,
|
||||
"deliverable": deliverable_name,
|
||||
"style": style_name,
|
||||
"brand": brand_name,
|
||||
"colors": primary_colors,
|
||||
"mockup_context": mockup_context,
|
||||
"logo_placement": logo_placement
|
||||
}
|
||||
|
||||
|
||||
def generate_with_nano_banana(prompt_data, output_dir=None, model_key="flash", aspect_ratio="1:1", logo_image=None):
|
||||
"""Generate image using Gemini Nano Banana (native image generation)
|
||||
|
||||
Supports two modes:
|
||||
1. Text-to-image: Pure prompt-based generation (logo_image=None)
|
||||
2. Image editing: Text-and-image-to-image using provided logo (logo_image=PIL.Image)
|
||||
|
||||
Models:
|
||||
- flash: gemini-3.1-flash-image-preview (fast, cost-effective) - DEFAULT
|
||||
- pro: gemini-3-pro-image-preview (quality, 4K text rendering)
|
||||
|
||||
Args:
|
||||
prompt_data: Dict with prompt, deliverable, brand, etc.
|
||||
output_dir: Output directory for generated images
|
||||
model_key: 'flash' or 'pro'
|
||||
aspect_ratio: Output aspect ratio (1:1, 16:9, etc.)
|
||||
logo_image: PIL.Image object of the brand logo for image editing mode
|
||||
"""
|
||||
try:
|
||||
from google import genai
|
||||
from google.genai import types
|
||||
except ImportError:
|
||||
print("Error: google-genai package not installed.")
|
||||
print("Install with: pip install google-genai")
|
||||
return None
|
||||
|
||||
api_key = os.environ.get("GEMINI_API_KEY") or os.environ.get("GOOGLE_API_KEY")
|
||||
if not api_key:
|
||||
print("Error: GEMINI_API_KEY or GOOGLE_API_KEY not set")
|
||||
return None
|
||||
|
||||
client = genai.Client(api_key=api_key)
|
||||
|
||||
prompt = prompt_data["prompt"]
|
||||
model_name = MODELS.get(model_key, MODELS[DEFAULT_MODEL])
|
||||
|
||||
# Determine mode
|
||||
mode = "image-editing" if logo_image else "text-to-image"
|
||||
|
||||
print(f"\n🎨 Generating CIP mockup...")
|
||||
print(f" Mode: {mode}")
|
||||
print(f" Deliverable: {prompt_data['deliverable']}")
|
||||
print(f" Brand: {prompt_data['brand']}")
|
||||
print(f" Style: {prompt_data['style']}")
|
||||
print(f" Model: {model_name}")
|
||||
print(f" Context: {prompt_data['mockup_context']}")
|
||||
if logo_image:
|
||||
print(f" Logo: Using provided image ({logo_image.size[0]}x{logo_image.size[1]})")
|
||||
|
||||
try:
|
||||
# Build contents: either just prompt or [prompt, image] for image editing
|
||||
if logo_image:
|
||||
# Image editing mode: pass both prompt and logo image
|
||||
contents = [prompt, logo_image]
|
||||
else:
|
||||
# Text-to-image mode: just the prompt
|
||||
contents = prompt
|
||||
|
||||
# Use generate_content with response_modalities=['IMAGE'] for Nano Banana
|
||||
response = client.models.generate_content(
|
||||
model=model_name,
|
||||
contents=contents,
|
||||
config=types.GenerateContentConfig(
|
||||
response_modalities=['IMAGE'], # Uppercase required
|
||||
image_config=types.ImageConfig(
|
||||
aspect_ratio=aspect_ratio
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
# Extract image from response
|
||||
if response.candidates and response.candidates[0].content.parts:
|
||||
for part in response.candidates[0].content.parts:
|
||||
if hasattr(part, 'inline_data') and part.inline_data:
|
||||
# Save image
|
||||
output_dir = output_dir or Path.cwd()
|
||||
output_dir = Path(output_dir)
|
||||
output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
||||
brand_slug = prompt_data["brand"].lower().replace(" ", "-")
|
||||
deliverable_slug = prompt_data["deliverable"].lower().replace(" ", "-")
|
||||
filename = f"{brand_slug}-{deliverable_slug}-{timestamp}.png"
|
||||
filepath = output_dir / filename
|
||||
|
||||
image_data = part.inline_data.data
|
||||
with open(filepath, "wb") as f:
|
||||
f.write(image_data)
|
||||
|
||||
print(f"\n✅ Generated: {filepath}")
|
||||
return str(filepath)
|
||||
|
||||
print("No image generated in response")
|
||||
return None
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error generating image: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def generate_cip_set(brand_name, industry, style=None, deliverables=None, output_dir=None, model_key="flash", logo_path=None, aspect_ratio="1:1"):
|
||||
"""Generate a complete CIP set for a brand
|
||||
|
||||
Args:
|
||||
brand_name: Brand name to generate for
|
||||
industry: Industry type for style recommendations
|
||||
style: Optional specific style override
|
||||
deliverables: List of deliverables to generate (default: core set)
|
||||
output_dir: Output directory for images
|
||||
model_key: 'flash' (fast) or 'pro' (quality)
|
||||
logo_path: Path to brand logo image for image editing mode
|
||||
aspect_ratio: Output aspect ratio
|
||||
"""
|
||||
|
||||
# Load logo image if provided
|
||||
logo_image = None
|
||||
if logo_path:
|
||||
logo_image = load_logo_image(logo_path)
|
||||
if not logo_image:
|
||||
print("Warning: Could not load logo, falling back to text-to-image mode")
|
||||
|
||||
# Get CIP brief for the brand
|
||||
brief = get_cip_brief(brand_name, industry, style)
|
||||
|
||||
# Default deliverables if not specified
|
||||
if not deliverables:
|
||||
deliverables = ["business card", "letterhead", "office signage", "vehicle", "polo shirt"]
|
||||
|
||||
results = []
|
||||
for deliverable in deliverables:
|
||||
prompt_data = build_cip_prompt(
|
||||
deliverable=deliverable,
|
||||
brand_name=brand_name,
|
||||
style=brief.get("style", {}).get("Style Name"),
|
||||
industry=industry,
|
||||
use_logo_image=(logo_image is not None)
|
||||
)
|
||||
|
||||
filepath = generate_with_nano_banana(
|
||||
prompt_data,
|
||||
output_dir,
|
||||
model_key=model_key,
|
||||
aspect_ratio=aspect_ratio,
|
||||
logo_image=logo_image
|
||||
)
|
||||
if filepath:
|
||||
results.append({
|
||||
"deliverable": deliverable,
|
||||
"filepath": filepath,
|
||||
"prompt": prompt_data["prompt"]
|
||||
})
|
||||
|
||||
return results
|
||||
|
||||
|
||||
def check_logo_required(brand_name, skip_prompt=False):
|
||||
"""Check if logo is required and suggest logo-design skill if not provided
|
||||
|
||||
Returns:
|
||||
str: 'continue' to proceed without logo, 'generate' to use logo-design skill, 'exit' to abort
|
||||
"""
|
||||
if skip_prompt:
|
||||
return 'continue'
|
||||
|
||||
print(f"\n⚠️ No logo image provided for '{brand_name}'")
|
||||
print(" Without a logo, AI will generate its own interpretation of the brand logo.")
|
||||
print("")
|
||||
print(" Options:")
|
||||
print(" 1. Continue without logo (AI-generated logo interpretation)")
|
||||
print(" 2. Generate a logo first using 'logo-design' skill")
|
||||
print(" 3. Exit and provide a logo path with --logo")
|
||||
print("")
|
||||
|
||||
try:
|
||||
choice = input(" Enter choice [1/2/3] (default: 1): ").strip()
|
||||
if choice == '2':
|
||||
return 'generate'
|
||||
elif choice == '3':
|
||||
return 'exit'
|
||||
return 'continue'
|
||||
except (EOFError, KeyboardInterrupt):
|
||||
return 'continue'
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generate CIP mockups using Gemini Nano Banana",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
# Generate with brand logo (RECOMMENDED)
|
||||
python generate.py --brand "TopGroup" --logo /path/to/logo.png --deliverable "business card"
|
||||
|
||||
# Generate CIP set with logo
|
||||
python generate.py --brand "TopGroup" --logo /path/to/logo.png --industry "consulting" --set
|
||||
|
||||
# Generate without logo (AI interprets brand)
|
||||
python generate.py --brand "TechFlow" --deliverable "business card" --no-logo-prompt
|
||||
|
||||
# Generate with Pro model (higher quality, 4K text)
|
||||
python generate.py --brand "TechFlow" --logo logo.png --deliverable "business card" --model pro
|
||||
|
||||
# Specify output directory and aspect ratio
|
||||
python generate.py --brand "MyBrand" --logo logo.png --deliverable "vehicle" --output ./mockups --ratio 16:9
|
||||
|
||||
Models:
|
||||
flash (default): gemini-3.1-flash-image-preview - Fast, cost-effective
|
||||
pro: gemini-3-pro-image-preview - Quality, 4K text rendering
|
||||
|
||||
Image Editing Mode:
|
||||
When --logo is provided, uses Gemini's text-and-image-to-image capability
|
||||
to incorporate your ACTUAL logo into the CIP mockups.
|
||||
"""
|
||||
)
|
||||
|
||||
parser.add_argument("--brand", "-b", required=True, help="Brand name")
|
||||
parser.add_argument("--logo", "-l", help="Path to brand logo image (enables image editing mode)")
|
||||
parser.add_argument("--deliverable", "-d", help="Single deliverable to generate")
|
||||
parser.add_argument("--deliverables", help="Comma-separated list of deliverables")
|
||||
parser.add_argument("--industry", "-i", default="technology", help="Industry type")
|
||||
parser.add_argument("--style", "-s", help="Design style")
|
||||
parser.add_argument("--mockup", "-m", help="Mockup context")
|
||||
parser.add_argument("--set", action="store_true", help="Generate full CIP set")
|
||||
parser.add_argument("--output", "-o", help="Output directory")
|
||||
parser.add_argument("--model", default="flash", choices=["flash", "pro"], help="Model: flash (fast) or pro (quality)")
|
||||
parser.add_argument("--ratio", default="1:1", help="Aspect ratio (1:1, 16:9, 4:3, etc.)")
|
||||
parser.add_argument("--prompt-only", action="store_true", help="Only show prompt, don't generate")
|
||||
parser.add_argument("--json", "-j", action="store_true", help="Output as JSON")
|
||||
parser.add_argument("--no-logo-prompt", action="store_true", help="Skip logo prompt, proceed without logo")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# Check if logo is provided, prompt user if not
|
||||
logo_image = None
|
||||
if args.logo:
|
||||
logo_image = load_logo_image(args.logo)
|
||||
if not logo_image:
|
||||
print("Error: Could not load logo image")
|
||||
sys.exit(1)
|
||||
elif not args.prompt_only:
|
||||
# No logo provided - ask user what to do
|
||||
action = check_logo_required(args.brand, skip_prompt=args.no_logo_prompt)
|
||||
if action == 'generate':
|
||||
print("\n💡 To generate a logo, use the logo-design skill:")
|
||||
print(f" python ~/.opencode/skills/design/scripts/logo/generate.py --brand \"{args.brand}\" --industry \"{args.industry}\"")
|
||||
print("\n Then re-run this command with --logo <generated_logo.png>")
|
||||
sys.exit(0)
|
||||
elif action == 'exit':
|
||||
print("\n Provide logo with: --logo /path/to/your/logo.png")
|
||||
sys.exit(0)
|
||||
# else: continue without logo
|
||||
|
||||
use_logo = logo_image is not None
|
||||
|
||||
if args.set or args.deliverables:
|
||||
# Generate multiple deliverables
|
||||
deliverables = args.deliverables.split(",") if args.deliverables else None
|
||||
|
||||
if args.prompt_only:
|
||||
results = []
|
||||
deliverables = deliverables or ["business card", "letterhead", "office signage", "vehicle", "polo shirt"]
|
||||
for d in deliverables:
|
||||
prompt_data = build_cip_prompt(d, args.brand, args.style, args.industry, args.mockup, use_logo_image=use_logo)
|
||||
results.append(prompt_data)
|
||||
if args.json:
|
||||
print(json.dumps(results, indent=2))
|
||||
else:
|
||||
for r in results:
|
||||
print(f"\n{r['deliverable']}:\n{r['prompt']}\n")
|
||||
else:
|
||||
results = generate_cip_set(
|
||||
args.brand, args.industry, args.style, deliverables, args.output,
|
||||
model_key=args.model, logo_path=args.logo, aspect_ratio=args.ratio
|
||||
)
|
||||
if args.json:
|
||||
print(json.dumps(results, indent=2))
|
||||
else:
|
||||
print(f"\n✅ Generated {len(results)} CIP mockups")
|
||||
else:
|
||||
# Generate single deliverable
|
||||
deliverable = args.deliverable or "business card"
|
||||
prompt_data = build_cip_prompt(deliverable, args.brand, args.style, args.industry, args.mockup, use_logo_image=use_logo)
|
||||
|
||||
if args.prompt_only:
|
||||
if args.json:
|
||||
print(json.dumps(prompt_data, indent=2))
|
||||
else:
|
||||
print(f"\nPrompt:\n{prompt_data['prompt']}")
|
||||
else:
|
||||
filepath = generate_with_nano_banana(
|
||||
prompt_data, args.output, model_key=args.model,
|
||||
aspect_ratio=args.ratio, logo_image=logo_image
|
||||
)
|
||||
if args.json:
|
||||
print(json.dumps({"filepath": filepath, **prompt_data}, indent=2))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
424
.opencode/skills/design/scripts/cip/render-html.py
Normal file
424
.opencode/skills/design/scripts/cip/render-html.py
Normal file
@@ -0,0 +1,424 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
CIP HTML Presentation Renderer
|
||||
|
||||
Generates a professional HTML presentation from CIP mockup images
|
||||
with detailed descriptions, concepts, and brand guidelines.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import base64
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
# Add parent directory for imports
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
from core import search, get_cip_brief
|
||||
|
||||
# Deliverable descriptions for presentation
|
||||
DELIVERABLE_INFO = {
|
||||
"business card": {
|
||||
"title": "Business Card",
|
||||
"concept": "First impression touchpoint for professional networking",
|
||||
"purpose": "Creates memorable brand recall during business exchanges",
|
||||
"specs": "Standard 3.5 x 2 inches, premium paper stock"
|
||||
},
|
||||
"letterhead": {
|
||||
"title": "Letterhead",
|
||||
"concept": "Official correspondence identity",
|
||||
"purpose": "Establishes credibility and professionalism in written communications",
|
||||
"specs": "A4/Letter size, digital and print versions"
|
||||
},
|
||||
"document template": {
|
||||
"title": "Document Template",
|
||||
"concept": "Branded document system for internal and external use",
|
||||
"purpose": "Ensures consistent brand representation across all documents",
|
||||
"specs": "Multiple formats: Word, PDF, Google Docs compatible"
|
||||
},
|
||||
"reception signage": {
|
||||
"title": "Reception Signage",
|
||||
"concept": "Brand presence in physical office environment",
|
||||
"purpose": "Creates strong first impression for visitors and reinforces brand identity",
|
||||
"specs": "3D dimensional letters, backlit LED options, premium materials"
|
||||
},
|
||||
"office signage": {
|
||||
"title": "Office Signage",
|
||||
"concept": "Wayfinding and brand presence system",
|
||||
"purpose": "Guides visitors while maintaining consistent brand experience",
|
||||
"specs": "Modular system with directional and informational signs"
|
||||
},
|
||||
"polo shirt": {
|
||||
"title": "Polo Shirt",
|
||||
"concept": "Professional team apparel",
|
||||
"purpose": "Creates unified team identity and brand ambassadorship",
|
||||
"specs": "Premium pique cotton, embroidered logo on left chest"
|
||||
},
|
||||
"t-shirt": {
|
||||
"title": "T-Shirt",
|
||||
"concept": "Casual brand apparel",
|
||||
"purpose": "Extends brand reach through everyday wear and promotional events",
|
||||
"specs": "High-quality cotton, screen print or embroidery options"
|
||||
},
|
||||
"vehicle": {
|
||||
"title": "Vehicle Branding",
|
||||
"concept": "Mobile brand advertising",
|
||||
"purpose": "Transforms fleet into moving billboards for maximum visibility",
|
||||
"specs": "Partial or full wrap, vinyl graphics, weather-resistant"
|
||||
},
|
||||
"van": {
|
||||
"title": "Van Branding",
|
||||
"concept": "Commercial vehicle identity",
|
||||
"purpose": "Professional fleet presence for service and delivery operations",
|
||||
"specs": "Full wrap design, high-visibility contact information"
|
||||
},
|
||||
"car": {
|
||||
"title": "Car Branding",
|
||||
"concept": "Executive vehicle identity",
|
||||
"purpose": "Professional presence for corporate and sales teams",
|
||||
"specs": "Subtle branding, door panels and rear window"
|
||||
},
|
||||
"envelope": {
|
||||
"title": "Envelope",
|
||||
"concept": "Branded mail correspondence",
|
||||
"purpose": "Extends brand identity to all outgoing mail",
|
||||
"specs": "DL, C4, C5 sizes with logo placement"
|
||||
},
|
||||
"folder": {
|
||||
"title": "Presentation Folder",
|
||||
"concept": "Document organization with brand identity",
|
||||
"purpose": "Professional presentation of proposals and materials",
|
||||
"specs": "A4/Letter pocket folder with die-cut design"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def get_image_base64(image_path):
|
||||
"""Convert image to base64 for embedding in HTML"""
|
||||
try:
|
||||
with open(image_path, "rb") as f:
|
||||
return base64.b64encode(f.read()).decode('utf-8')
|
||||
except Exception as e:
|
||||
print(f"Warning: Could not load image {image_path}: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def get_deliverable_info(filename):
|
||||
"""Extract deliverable type from filename and get info"""
|
||||
filename_lower = filename.lower()
|
||||
for key, info in DELIVERABLE_INFO.items():
|
||||
if key.replace(" ", "-") in filename_lower or key.replace(" ", "_") in filename_lower:
|
||||
return info
|
||||
# Default info
|
||||
return {
|
||||
"title": filename.replace("-", " ").replace("_", " ").title(),
|
||||
"concept": "Brand identity application",
|
||||
"purpose": "Extends brand presence across touchpoints",
|
||||
"specs": "Custom specifications"
|
||||
}
|
||||
|
||||
|
||||
def generate_html(brand_name, industry, images_dir, output_path=None, style=None):
|
||||
"""Generate HTML presentation from CIP images"""
|
||||
|
||||
images_dir = Path(images_dir)
|
||||
if not images_dir.exists():
|
||||
print(f"Error: Directory not found: {images_dir}")
|
||||
return None
|
||||
|
||||
# Get all PNG images
|
||||
images = sorted(images_dir.glob("*.png"))
|
||||
if not images:
|
||||
print(f"Error: No PNG images found in {images_dir}")
|
||||
return None
|
||||
|
||||
# Get CIP brief for brand info
|
||||
brief = get_cip_brief(brand_name, industry, style)
|
||||
style_info = brief.get("style", {})
|
||||
industry_info = brief.get("industry", {})
|
||||
|
||||
# Build HTML
|
||||
html_parts = [f'''<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{brand_name} - Corporate Identity Program</title>
|
||||
<style>
|
||||
* {{
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}}
|
||||
body {{
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
|
||||
background: #0a0a0a;
|
||||
color: #ffffff;
|
||||
line-height: 1.6;
|
||||
}}
|
||||
.hero {{
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
text-align: center;
|
||||
padding: 4rem 2rem;
|
||||
background: linear-gradient(135deg, #1a1a2e 0%, #0a0a0a 100%);
|
||||
}}
|
||||
.hero h1 {{
|
||||
font-size: 4rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.02em;
|
||||
margin-bottom: 1rem;
|
||||
background: linear-gradient(135deg, #ffffff 0%, #888888 100%);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
}}
|
||||
.hero .subtitle {{
|
||||
font-size: 1.5rem;
|
||||
color: #888;
|
||||
margin-bottom: 3rem;
|
||||
}}
|
||||
.hero .meta {{
|
||||
display: flex;
|
||||
gap: 3rem;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
}}
|
||||
.hero .meta-item {{
|
||||
text-align: center;
|
||||
}}
|
||||
.hero .meta-label {{
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.1em;
|
||||
color: #666;
|
||||
margin-bottom: 0.5rem;
|
||||
}}
|
||||
.hero .meta-value {{
|
||||
font-size: 1rem;
|
||||
color: #ccc;
|
||||
}}
|
||||
.section {{
|
||||
padding: 6rem 2rem;
|
||||
max-width: 1400px;
|
||||
margin: 0 auto;
|
||||
}}
|
||||
.section-title {{
|
||||
font-size: 2.5rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 1rem;
|
||||
color: #fff;
|
||||
}}
|
||||
.section-subtitle {{
|
||||
font-size: 1.1rem;
|
||||
color: #888;
|
||||
margin-bottom: 4rem;
|
||||
max-width: 600px;
|
||||
}}
|
||||
.deliverable {{
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 4rem;
|
||||
margin-bottom: 8rem;
|
||||
align-items: center;
|
||||
}}
|
||||
.deliverable:nth-child(even) {{
|
||||
direction: rtl;
|
||||
}}
|
||||
.deliverable:nth-child(even) > * {{
|
||||
direction: ltr;
|
||||
}}
|
||||
.deliverable-image {{
|
||||
position: relative;
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
|
||||
}}
|
||||
.deliverable-image img {{
|
||||
width: 100%;
|
||||
height: auto;
|
||||
display: block;
|
||||
}}
|
||||
.deliverable-content {{
|
||||
padding: 2rem 0;
|
||||
}}
|
||||
.deliverable-title {{
|
||||
font-size: 2rem;
|
||||
font-weight: 600;
|
||||
margin-bottom: 1rem;
|
||||
color: #fff;
|
||||
}}
|
||||
.deliverable-concept {{
|
||||
font-size: 1.1rem;
|
||||
color: #aaa;
|
||||
margin-bottom: 1.5rem;
|
||||
font-style: italic;
|
||||
}}
|
||||
.deliverable-purpose {{
|
||||
font-size: 1rem;
|
||||
color: #888;
|
||||
margin-bottom: 1.5rem;
|
||||
line-height: 1.8;
|
||||
}}
|
||||
.deliverable-specs {{
|
||||
display: inline-block;
|
||||
padding: 0.5rem 1rem;
|
||||
background: rgba(255, 255, 255, 0.05);
|
||||
border-radius: 8px;
|
||||
font-size: 0.85rem;
|
||||
color: #666;
|
||||
}}
|
||||
.color-palette {{
|
||||
display: flex;
|
||||
gap: 1rem;
|
||||
margin-top: 2rem;
|
||||
}}
|
||||
.color-swatch {{
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
|
||||
}}
|
||||
.footer {{
|
||||
text-align: center;
|
||||
padding: 4rem 2rem;
|
||||
border-top: 1px solid #222;
|
||||
color: #666;
|
||||
}}
|
||||
.footer p {{
|
||||
margin-bottom: 0.5rem;
|
||||
}}
|
||||
@media (max-width: 900px) {{
|
||||
.hero h1 {{
|
||||
font-size: 2.5rem;
|
||||
}}
|
||||
.deliverable {{
|
||||
grid-template-columns: 1fr;
|
||||
gap: 2rem;
|
||||
}}
|
||||
.deliverable:nth-child(even) {{
|
||||
direction: ltr;
|
||||
}}
|
||||
}}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<section class="hero">
|
||||
<h1>{brand_name}</h1>
|
||||
<p class="subtitle">Corporate Identity Program</p>
|
||||
<div class="meta">
|
||||
<div class="meta-item">
|
||||
<div class="meta-label">Industry</div>
|
||||
<div class="meta-value">{industry_info.get("Industry", industry.title())}</div>
|
||||
</div>
|
||||
<div class="meta-item">
|
||||
<div class="meta-label">Style</div>
|
||||
<div class="meta-value">{style_info.get("Style Name", "Corporate")}</div>
|
||||
</div>
|
||||
<div class="meta-item">
|
||||
<div class="meta-label">Mood</div>
|
||||
<div class="meta-value">{style_info.get("Mood", "Professional")}</div>
|
||||
</div>
|
||||
<div class="meta-item">
|
||||
<div class="meta-label">Deliverables</div>
|
||||
<div class="meta-value">{len(images)} Items</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="section">
|
||||
<h2 class="section-title">Brand Applications</h2>
|
||||
<p class="section-subtitle">
|
||||
Comprehensive identity system designed to maintain consistency
|
||||
across all brand touchpoints and communications.
|
||||
</p>
|
||||
''']
|
||||
|
||||
# Add each deliverable
|
||||
for i, image_path in enumerate(images):
|
||||
info = get_deliverable_info(image_path.stem)
|
||||
img_base64 = get_image_base64(image_path)
|
||||
|
||||
if img_base64:
|
||||
img_src = f"data:image/png;base64,{img_base64}"
|
||||
else:
|
||||
img_src = str(image_path)
|
||||
|
||||
html_parts.append(f'''
|
||||
<div class="deliverable">
|
||||
<div class="deliverable-image">
|
||||
<img src="{img_src}" alt="{info['title']}" loading="lazy">
|
||||
</div>
|
||||
<div class="deliverable-content">
|
||||
<h3 class="deliverable-title">{info['title']}</h3>
|
||||
<p class="deliverable-concept">{info['concept']}</p>
|
||||
<p class="deliverable-purpose">{info['purpose']}</p>
|
||||
<span class="deliverable-specs">{info['specs']}</span>
|
||||
</div>
|
||||
</div>
|
||||
''')
|
||||
|
||||
# Close HTML
|
||||
html_parts.append(f'''
|
||||
</section>
|
||||
|
||||
<footer class="footer">
|
||||
<p><strong>{brand_name}</strong> Corporate Identity Program</p>
|
||||
<p>Generated on {datetime.now().strftime("%B %d, %Y")}</p>
|
||||
<p style="margin-top: 1rem; font-size: 0.8rem;">Powered by CIP Design Skill</p>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
||||
''')
|
||||
|
||||
html_content = "".join(html_parts)
|
||||
|
||||
# Save HTML
|
||||
output_path = output_path or images_dir / f"{brand_name.lower().replace(' ', '-')}-cip-presentation.html"
|
||||
output_path = Path(output_path)
|
||||
|
||||
with open(output_path, "w", encoding="utf-8") as f:
|
||||
f.write(html_content)
|
||||
|
||||
print(f"✅ HTML presentation generated: {output_path}")
|
||||
return str(output_path)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Generate HTML presentation from CIP mockups",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
# Generate HTML from CIP images directory
|
||||
python render-html.py --brand "TopGroup" --industry "consulting" --images ./topgroup-cip
|
||||
|
||||
# Specify output path
|
||||
python render-html.py --brand "TopGroup" --industry "consulting" --images ./cip --output presentation.html
|
||||
"""
|
||||
)
|
||||
|
||||
parser.add_argument("--brand", "-b", required=True, help="Brand name")
|
||||
parser.add_argument("--industry", "-i", default="technology", help="Industry type")
|
||||
parser.add_argument("--style", "-s", help="Design style")
|
||||
parser.add_argument("--images", required=True, help="Directory containing CIP mockup images")
|
||||
parser.add_argument("--output", "-o", help="Output HTML file path")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
generate_html(
|
||||
brand_name=args.brand,
|
||||
industry=args.industry,
|
||||
images_dir=args.images,
|
||||
output_path=args.output,
|
||||
style=args.style
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
127
.opencode/skills/design/scripts/cip/search.py
Normal file
127
.opencode/skills/design/scripts/cip/search.py
Normal file
@@ -0,0 +1,127 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
CIP Design Search CLI - Search corporate identity design guidelines
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
# Add parent directory for imports
|
||||
sys.path.insert(0, str(Path(__file__).parent))
|
||||
from core import search, search_all, get_cip_brief, CSV_CONFIG
|
||||
|
||||
|
||||
def format_results(results, domain):
|
||||
"""Format search results for display"""
|
||||
if not results:
|
||||
return "No results found."
|
||||
|
||||
output = []
|
||||
for i, item in enumerate(results, 1):
|
||||
output.append(f"\n{'='*60}")
|
||||
output.append(f"Result {i}:")
|
||||
for key, value in item.items():
|
||||
if value:
|
||||
output.append(f" {key}: {value}")
|
||||
return "\n".join(output)
|
||||
|
||||
|
||||
def format_brief(brief):
|
||||
"""Format CIP brief for display"""
|
||||
output = []
|
||||
output.append(f"\n{'='*60}")
|
||||
output.append(f"CIP DESIGN BRIEF: {brief['brand_name']}")
|
||||
output.append(f"{'='*60}")
|
||||
|
||||
if brief.get("industry"):
|
||||
output.append(f"\n📊 INDUSTRY: {brief['industry'].get('Industry', 'N/A')}")
|
||||
output.append(f" Style: {brief['industry'].get('CIP Style', 'N/A')}")
|
||||
output.append(f" Mood: {brief['industry'].get('Mood', 'N/A')}")
|
||||
|
||||
if brief.get("style"):
|
||||
output.append(f"\n🎨 DESIGN STYLE: {brief['style'].get('Style Name', 'N/A')}")
|
||||
output.append(f" Description: {brief['style'].get('Description', 'N/A')}")
|
||||
output.append(f" Materials: {brief['style'].get('Materials', 'N/A')}")
|
||||
output.append(f" Finishes: {brief['style'].get('Finishes', 'N/A')}")
|
||||
|
||||
if brief.get("color_system"):
|
||||
output.append(f"\n🎯 COLOR SYSTEM:")
|
||||
output.append(f" Primary: {brief['color_system'].get('primary', 'N/A')}")
|
||||
output.append(f" Secondary: {brief['color_system'].get('secondary', 'N/A')}")
|
||||
|
||||
output.append(f"\n✏️ TYPOGRAPHY: {brief.get('typography', 'N/A')}")
|
||||
|
||||
if brief.get("recommended_deliverables"):
|
||||
output.append(f"\n📦 RECOMMENDED DELIVERABLES:")
|
||||
for d in brief["recommended_deliverables"]:
|
||||
output.append(f" • {d.get('Deliverable', 'N/A')}: {d.get('Description', '')[:60]}...")
|
||||
|
||||
return "\n".join(output)
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Search CIP design guidelines",
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog="""
|
||||
Examples:
|
||||
# Search deliverables
|
||||
python search.py "business card"
|
||||
|
||||
# Search specific domain
|
||||
python search.py "luxury elegant" --domain style
|
||||
|
||||
# Generate CIP brief
|
||||
python search.py "tech startup" --cip-brief -b "TechFlow"
|
||||
|
||||
# Search all domains
|
||||
python search.py "corporate professional" --all
|
||||
|
||||
# JSON output
|
||||
python search.py "vehicle branding" --json
|
||||
"""
|
||||
)
|
||||
|
||||
parser.add_argument("query", help="Search query")
|
||||
parser.add_argument("--domain", "-d", choices=list(CSV_CONFIG.keys()),
|
||||
help="Search domain (auto-detected if not specified)")
|
||||
parser.add_argument("--max", "-m", type=int, default=3, help="Max results (default: 3)")
|
||||
parser.add_argument("--all", "-a", action="store_true", help="Search all domains")
|
||||
parser.add_argument("--cip-brief", "-c", action="store_true", help="Generate CIP brief")
|
||||
parser.add_argument("--brand", "-b", default="BrandName", help="Brand name for CIP brief")
|
||||
parser.add_argument("--style", "-s", help="Style override for CIP brief")
|
||||
parser.add_argument("--json", "-j", action="store_true", help="Output as JSON")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.cip_brief:
|
||||
brief = get_cip_brief(args.brand, args.query, args.style)
|
||||
if args.json:
|
||||
print(json.dumps(brief, indent=2))
|
||||
else:
|
||||
print(format_brief(brief))
|
||||
elif args.all:
|
||||
results = search_all(args.query, args.max)
|
||||
if args.json:
|
||||
print(json.dumps(results, indent=2))
|
||||
else:
|
||||
for domain, items in results.items():
|
||||
print(f"\n{'#'*60}")
|
||||
print(f"# {domain.upper()}")
|
||||
print(format_results(items, domain))
|
||||
else:
|
||||
result = search(args.query, args.domain, args.max)
|
||||
if args.json:
|
||||
print(json.dumps(result, indent=2))
|
||||
else:
|
||||
print(f"\nDomain: {result['domain']}")
|
||||
print(f"Query: {result['query']}")
|
||||
print(f"Results: {result['count']}")
|
||||
print(format_results(result.get("results", []), result["domain"]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user