Add Preset Library feature

Presets are saved generation recipes that combine all resource types
(character, outfit, action, style, scene, detailer, look, checkpoint)
with per-field on/off/random toggles. At generation time, entities
marked "random" are picked from the DB and fields marked "random" are
randomly included or excluded.

- Preset model + sync_presets() following existing category pattern
- _resolve_preset_entity() / _resolve_preset_fields() helpers
- Full route set: index, detail, generate, edit, upload, clone, save_json, create (LLM), rescan
- 4 templates: index (gallery), detail (summary + generate), edit (3-way toggle UI), create (LLM form)
- example_01.json reference preset + preset_system.txt LLM prompt
- Presets nav link in layout.html

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Aodhan Collins
2026-03-05 23:49:24 +00:00
parent 2c1c3a7ed7
commit ec08eb5d31
10 changed files with 1493 additions and 1 deletions

276
templates/presets/edit.html Normal file
View File

@@ -0,0 +1,276 @@
{% extends "layout.html" %}
{% block content %}
<div class="d-flex justify-content-between align-items-center mb-4">
<h1>Edit Preset: {{ preset.name }}</h1>
<a href="{{ url_for('preset_detail', slug=preset.slug) }}" class="btn btn-outline-secondary">Cancel</a>
</div>
{% macro toggle_group(name, val) %}
{# 3-way toggle: OFF / RNG / ON — renders as Bootstrap btn-group radio #}
{% set v = val | string | lower %}
<div class="btn-group btn-group-sm toggle-group" role="group" data-field="{{ name }}">
<input type="radio" class="btn-check" name="{{ name }}" id="{{ name }}_off" value="false" autocomplete="off" {% if v == 'false' %}checked{% endif %}>
<label class="btn btn-outline-secondary" for="{{ name }}_off">OFF</label>
<input type="radio" class="btn-check" name="{{ name }}" id="{{ name }}_rng" value="random" autocomplete="off" {% if v == 'random' %}checked{% endif %}>
<label class="btn btn-outline-warning" for="{{ name }}_rng">RNG</label>
<input type="radio" class="btn-check" name="{{ name }}" id="{{ name }}_on" value="true" autocomplete="off" {% if v not in ['false', 'random'] %}checked{% endif %}>
<label class="btn btn-outline-success" for="{{ name }}_on">ON</label>
</div>
{% endmacro %}
{% macro entity_select(name, items, id_attr, current_val, include_random=true) %}
<select class="form-select form-select-sm" name="{{ name }}">
<option value="">— None —</option>
{% if include_random %}<option value="random" {% if current_val == 'random' %}selected{% endif %}>🎲 Random</option>{% endif %}
{% for item in items %}
{% set item_id = item | attr(id_attr) %}
<option value="{{ item_id }}" {% if current_val == item_id %}selected{% endif %}>{{ item.name }}</option>
{% endfor %}
</select>
{% endmacro %}
<form action="{{ url_for('edit_preset', slug=preset.slug) }}" method="post">
{% set d = preset.data %}
{% set char_cfg = d.get('character', {}) %}
{% set char_fields = char_cfg.get('fields', {}) %}
{% set id_fields = char_fields.get('identity', {}) %}
{% set def_fields = char_fields.get('defaults', {}) %}
{% set wd_cfg = char_fields.get('wardrobe', {}) %}
{% set wd_fields = wd_cfg.get('fields', {}) %}
<div class="row">
<div class="col-md-8">
<!-- Basic Info -->
<div class="card mb-4">
<div class="card-header bg-dark text-white">Basic Information</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label">Preset Name</label>
<input type="text" class="form-control" name="preset_name" value="{{ preset.name }}" required>
</div>
<div class="mb-3">
<label class="form-label text-muted small">Preset ID</label>
<input type="text" class="form-control form-control-sm" value="{{ preset.preset_id }}" disabled>
</div>
<div class="mb-3">
<label class="form-label">Extra Tags <span class="text-muted small">(comma-separated)</span></label>
<input type="text" class="form-control" name="tags" value="{{ d.get('tags', []) | join(', ') }}">
</div>
</div>
</div>
<!-- Character -->
<div class="card mb-4">
<div class="card-header bg-primary text-white d-flex justify-content-between align-items-center">
<strong>Character</strong>
<div class="form-check form-switch mb-0">
<input class="form-check-input" type="checkbox" name="char_use_lora" id="char_use_lora" {% if char_cfg.get('use_lora', true) %}checked{% endif %}>
<label class="form-check-label text-white small" for="char_use_lora">Use LoRA</label>
</div>
</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label">Character</label>
{{ entity_select('char_character_id', characters, 'character_id', char_cfg.get('character_id')) }}
</div>
<div class="mb-3">
<label class="form-label fw-semibold">Identity Fields</label>
<div class="row g-2">
{% for k in ['base_specs','hair','eyes','hands','arms','torso','pelvis','legs','feet','extra'] %}
<div class="col-6 col-sm-4 col-md-4">
<div class="d-flex justify-content-between align-items-center border rounded p-2">
<small>{{ k | replace('_', ' ') }}</small>
{{ toggle_group('id_' + k, id_fields.get(k, true)) }}
</div>
</div>
{% endfor %}
</div>
</div>
<div class="mb-3">
<label class="form-label fw-semibold">Default Fields</label>
<div class="row g-2">
{% for k in ['expression','pose','scene'] %}
<div class="col-6 col-sm-4">
<div class="d-flex justify-content-between align-items-center border rounded p-2">
<small>{{ k }}</small>
{{ toggle_group('def_' + k, def_fields.get(k, false)) }}
</div>
</div>
{% endfor %}
</div>
</div>
<div>
<label class="form-label fw-semibold">Wardrobe Fields</label>
<div class="mb-2">
<label class="form-label small text-muted">Active outfit name</label>
<input type="text" class="form-control form-control-sm" name="wardrobe_outfit"
value="{{ wd_cfg.get('outfit', 'default') }}" placeholder="default">
</div>
<div class="row g-2">
{% for k in ['full_body','headwear','top','bottom','legwear','footwear','hands','gloves','accessories'] %}
<div class="col-6 col-sm-4">
<div class="d-flex justify-content-between align-items-center border rounded p-2">
<small>{{ k | replace('_', ' ') }}</small>
{{ toggle_group('wd_' + k, wd_fields.get(k, true)) }}
</div>
</div>
{% endfor %}
</div>
</div>
</div>
</div>
<!-- Action -->
{% set act = d.get('action', {}) %}
<div class="card mb-4">
<div class="card-header bg-secondary text-white d-flex justify-content-between align-items-center">
<strong>Action</strong>
<div class="form-check form-switch mb-0">
<input class="form-check-input" type="checkbox" name="action_use_lora" id="action_use_lora" {% if act.get('use_lora', true) %}checked{% endif %}>
<label class="form-check-label text-white small" for="action_use_lora">Use LoRA</label>
</div>
</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label">Action</label>
{{ entity_select('action_id', actions, 'action_id', act.get('action_id')) }}
</div>
<label class="form-label fw-semibold">Fields</label>
<div class="row g-2">
{% for k in ['full_body','additional','head','eyes','arms','hands'] %}
<div class="col-6 col-sm-4">
<div class="d-flex justify-content-between align-items-center border rounded p-2">
<small>{{ k | replace('_', ' ') }}</small>
{{ toggle_group('act_' + k, act.get('fields', {}).get(k, true)) }}
</div>
</div>
{% endfor %}
</div>
</div>
</div>
<!-- Style / Scene / Detailer -->
<div class="row g-3 mb-4">
{% set sty = d.get('style', {}) %}
<div class="col-md-4">
<div class="card h-100">
<div class="card-header bg-info text-white d-flex justify-content-between align-items-center py-2">
<strong>Style</strong>
<div class="form-check form-switch mb-0">
<input class="form-check-input" type="checkbox" name="style_use_lora" id="style_use_lora" {% if sty.get('use_lora', true) %}checked{% endif %}>
<label class="form-check-label text-white" for="style_use_lora" style="font-size:0.75rem">LoRA</label>
</div>
</div>
<div class="card-body">
{{ entity_select('style_id', styles, 'style_id', sty.get('style_id')) }}
</div>
</div>
</div>
{% set det = d.get('detailer', {}) %}
<div class="col-md-4">
<div class="card h-100">
<div class="card-header bg-info text-white d-flex justify-content-between align-items-center py-2">
<strong>Detailer</strong>
<div class="form-check form-switch mb-0">
<input class="form-check-input" type="checkbox" name="detailer_use_lora" id="detailer_use_lora" {% if det.get('use_lora', true) %}checked{% endif %}>
<label class="form-check-label text-white" for="detailer_use_lora" style="font-size:0.75rem">LoRA</label>
</div>
</div>
<div class="card-body">
{{ entity_select('detailer_id', detailers, 'detailer_id', det.get('detailer_id')) }}
</div>
</div>
</div>
{% set lk = d.get('look', {}) %}
<div class="col-md-4">
<div class="card h-100">
<div class="card-header bg-warning text-dark py-2"><strong>Look</strong> <small class="text-muted">(overrides char LoRA)</small></div>
<div class="card-body">
{{ entity_select('look_id', looks, 'look_id', lk.get('look_id')) }}
</div>
</div>
</div>
</div>
<!-- Scene -->
{% set scn = d.get('scene', {}) %}
<div class="card mb-4">
<div class="card-header bg-success text-white d-flex justify-content-between align-items-center">
<strong>Scene</strong>
<div class="form-check form-switch mb-0">
<input class="form-check-input" type="checkbox" name="scene_use_lora" id="scene_use_lora" {% if scn.get('use_lora', true) %}checked{% endif %}>
<label class="form-check-label text-white small" for="scene_use_lora">Use LoRA</label>
</div>
</div>
<div class="card-body">
<div class="mb-3">
<label class="form-label">Scene</label>
{{ entity_select('scene_id', scenes, 'scene_id', scn.get('scene_id')) }}
</div>
<label class="form-label fw-semibold">Fields</label>
<div class="row g-2">
{% for k in ['background','foreground','furniture','colors','lighting','theme'] %}
<div class="col-6 col-sm-4">
<div class="d-flex justify-content-between align-items-center border rounded p-2">
<small>{{ k }}</small>
{{ toggle_group('scn_' + k, scn.get('fields', {}).get(k, true)) }}
</div>
</div>
{% endfor %}
</div>
</div>
</div>
<!-- Outfit + Checkpoint -->
<div class="row g-3 mb-4">
{% set out = d.get('outfit', {}) %}
<div class="col-md-6">
<div class="card h-100">
<div class="card-header bg-secondary text-white d-flex justify-content-between align-items-center py-2">
<strong>Outfit</strong>
<div class="form-check form-switch mb-0">
<input class="form-check-input" type="checkbox" name="outfit_use_lora" id="outfit_use_lora" {% if out.get('use_lora', true) %}checked{% endif %}>
<label class="form-check-label text-white" for="outfit_use_lora" style="font-size:0.75rem">LoRA</label>
</div>
</div>
<div class="card-body">
{{ entity_select('outfit_id', outfits, 'outfit_id', out.get('outfit_id')) }}
<small class="text-muted">Selecting an outfit overrides the character's wardrobe.</small>
</div>
</div>
</div>
{% set ckpt = d.get('checkpoint', {}) %}
<div class="col-md-6">
<div class="card h-100">
<div class="card-header py-2"><strong>Checkpoint</strong></div>
<div class="card-body">
<select class="form-select form-select-sm" name="checkpoint_path">
<option value="">— Use session default —</option>
<option value="random" {% if ckpt.get('checkpoint_path') == 'random' %}selected{% endif %}>🎲 Random</option>
{% for ck in checkpoints %}
<option value="{{ ck.checkpoint_path }}" {% if ckpt.get('checkpoint_path') == ck.checkpoint_path %}selected{% endif %}>{{ ck.name }}</option>
{% endfor %}
</select>
</div>
</div>
</div>
</div>
<div class="d-flex gap-2 pb-4">
<button type="submit" class="btn btn-primary">Save Preset</button>
<a href="{{ url_for('preset_detail', slug=preset.slug) }}" class="btn btn-outline-secondary">Cancel</a>
</div>
</div>
</div>
</form>
{% endblock %}