3.4 KiB
Feature Development Guide: Gallery Pages & Character Integration
This guide outlines the architectural patterns and best practices developed during the implementation of the Actions, Outfits, and Styles galleries. Use this as a blueprint for adding similar features (e.g., "Scenes", "Props", "Effects").
1. Data Model & Persistence
- Database Model: Add a new class in
models.py. Includedefault_fields(JSON) to support persistent prompt selections. - JSON Sync: Implement a
sync_[feature]()function inapp.pyto keep the SQLite database in sync with thedata/[feature]/*.jsonfiles. - Slugs: Use URL-safe slugs generated from the ID for clean routing.
2. Quadruple LoRA Chaining
Our workflow supports chaining up to four distinct LoRAs from specific directories:
- Character:
Illustrious/Looks/(Node 16) - Outfit:
Illustrious/Clothing/(Node 17) - Action:
Illustrious/Poses/(Node 18) - Style:
Illustrious/Styles/(Node 19)
Implementation Detail:
In _prepare_workflow, LoRAs must be chained sequentially. If a previous LoRA is missing, the next one must "reach back" to the Checkpoint (Node 4) or the last valid node in the chain to maintain the model/CLIP connection. Node 19 is the terminal LoRA loader before terminal consumers (KSampler, Detailers).
3. Style Prompt Construction
Artistic styles follow specific formatting rules in the build_prompt engine:
- Artist Attribution: Artist names are prefixed with "by " (e.g., "by Sabu").
- Artistic Styles: Raw descriptive style tags (e.g., "watercolor painting") are appended to the prompt.
- Priority: Style tags are applied after identity and wardrobe tags but before trigger words.
4. Adetailer Routing
To improve generation quality, route specific JSON sub-fields to targeted Adetailers:
- Face Detailer (Node 14): Receives
character_name,expression, and action-specifichead/eyestags. - Hand Detailer (Node 15): Receives priority hand tags (Wardrobe Gloves > Wardrobe Hands > Identity Hands) and action-specific
arms/handstags.
5. Character-Integrated Previews
The "Killer Feature" is previewing a standalone item (like an Action, Outfit, or Style) on a specific character.
Logic Flow:
- Merge Data: Copy
character.data. - Override/Merge: Replace character
defaultswith feature-specific tags (e.g., Action pose overrides Character pose). - Context Injection: Append character-specific styles (e.g.,
[primary_color] simple background) to the main prompt. - Auto-Selection: When a character is selected, ensure their essential identity and active wardrobe fields are automatically included in the prompt.
6. UI/UX Patterns
- Selection Boxes: Use checkboxes next to field labels to allow users to toggle specific tags.
- Default Selection: Implement a "Save as Default Selection" button that persists the current checkbox state to the database.
- Session State: Store the last selected character and field preferences in the Flask
sessionto provide a seamless experience. - AJAX Generation: Use the WebSocket + Polling hybrid pattern in the frontend to show real-time progress bars without page reloads.
7. Directory Isolation
Always isolate LoRAs by purpose to prevent dropdown clutter:
get_available_loras()-> Charactersget_available_clothing_loras()-> Outfitsget_available_action_loras()-> Actions/Posesget_available_style_loras()-> Styles