- New Checkpoint model (slug, name, checkpoint_path, data JSON, image_path) - sync_checkpoints() loads metadata from data/checkpoints/*.json and falls back to template defaults for models without a JSON file - _apply_checkpoint_settings() applies per-checkpoint steps, CFG, sampler, base positive/negative prompts, and VAE (with dynamic VAELoader node injection for non-integrated VAEs) to the ComfyUI workflow - Bulk Create from Checkpoints: scans Illustrious/Noob model directories, reads matching HTML files, uses LLM to populate metadata, falls back to template defaults when no HTML is present - Gallery index with batch cover generation and WebSocket progress bar - Detail page showing Generation Settings and Base Prompts cards - Checkpoints nav link added to layout - New data/prompts/checkpoint_system.txt LLM system prompt - Updated README with all current galleries and file structure - Also includes accumulated action/scene JSON updates, new actions, and other template/generator improvements from prior sessions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
372 lines
18 KiB
HTML
372 lines
18 KiB
HTML
{% extends "layout.html" %}
|
|
|
|
{% block content %}
|
|
<!-- Image Modal -->
|
|
<div class="modal fade" id="imageModal" tabindex="-1" aria-labelledby="imageModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-xl modal-dialog-centered">
|
|
<div class="modal-content bg-transparent border-0">
|
|
<div class="modal-body p-0 text-center">
|
|
<img id="modalImage" src="" alt="Enlarged Image" class="img-fluid" style="max-height: 90vh;">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% macro selection_checkbox(section, key, label, value) %}
|
|
<input class="form-check-input me-1" type="checkbox" name="include_field" value="{{ section }}::{{ key }}"
|
|
{% if preferences is not none %}
|
|
{% if section + '::' + key in preferences %}checked{% endif %}
|
|
{% elif style.default_fields is not none %}
|
|
{% if section + '::' + key in style.default_fields %}checked{% endif %}
|
|
{% else %}
|
|
{% if value %}checked{% endif %}
|
|
{% endif %}>
|
|
{% endmacro %}
|
|
|
|
<div class="row">
|
|
<div class="col-md-4">
|
|
<div class="card mb-4">
|
|
<div class="img-container" style="height: auto; min-height: 400px; cursor: pointer;" data-bs-toggle="modal" data-bs-target="#imageModal" onclick="showImage(this.querySelector('img').src)">
|
|
{% if style.image_path %}
|
|
<img src="{{ url_for('static', filename='uploads/' + style.image_path) }}" alt="{{ style.name }}" class="img-fluid">
|
|
{% else %}
|
|
<div class="d-flex align-items-center justify-content-center bg-light" style="height: 400px;">
|
|
<span class="text-muted">No Image Attached</span>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
<div class="card-body">
|
|
<form action="{{ url_for('upload_style_image', slug=style.slug) }}" method="post" enctype="multipart/form-data">
|
|
<div class="mb-3">
|
|
<label for="image" class="form-label text-muted small">Update Cover Image</label>
|
|
<input class="form-control form-control-sm" type="file" id="image" name="image" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-sm btn-outline-primary w-100 mb-2">Upload</button>
|
|
</form>
|
|
|
|
<hr>
|
|
|
|
{# Character Selector #}
|
|
<div class="mb-3">
|
|
<label for="character_select" class="form-label">Preview with Character</label>
|
|
<select class="form-select" id="character_select" name="character_slug" form="generate-form">
|
|
<option value="">-- No Character (Style Only) --</option>
|
|
<option value="__random__" {% if selected_character == '__random__' %}selected{% endif %}>🎲 Random Character</option>
|
|
{% for char in characters %}
|
|
<option value="{{ char.slug }}" {% if selected_character == char.slug %}selected{% endif %}>{{ char.name }}</option>
|
|
{% endfor %}
|
|
</select>
|
|
</div>
|
|
|
|
<div class="d-grid gap-2">
|
|
<button type="submit" name="action" value="preview" class="btn btn-success" form="generate-form">Generate Preview</button>
|
|
<button type="submit" form="generate-form" formaction="{{ url_for('save_style_defaults', slug=style.slug) }}" class="btn btn-sm btn-outline-secondary mt-2">Save Selection as Default</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="progress-container" class="mb-4 d-none">
|
|
<label id="progress-label" class="form-label">Generating...</label>
|
|
<div class="progress" role="progressbar" aria-label="Generation Progress" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
|
|
<div id="progress-bar" class="progress-bar progress-bar-striped progress-bar-animated" style="width: 0%">0%</div>
|
|
</div>
|
|
</div>
|
|
|
|
{% if preview_image %}
|
|
<div class="card mb-4 border-success">
|
|
<div class="card-header bg-success text-white d-flex justify-content-between align-items-center p-2">
|
|
<small>Latest Preview</small>
|
|
<form action="{{ url_for('replace_style_cover_from_preview', slug=style.slug) }}" method="post" class="m-0" id="replace-cover-form">
|
|
<button type="submit" class="btn btn-sm btn-outline-light" id="replace-cover-btn">Replace Cover</button>
|
|
</form>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="img-container" style="height: auto; min-height: 400px; cursor: pointer;" data-bs-toggle="modal" data-bs-target="#imageModal" onclick="showImage(this.querySelector('img').src)">
|
|
<img id="preview-img" src="{{ url_for('static', filename='uploads/' + preview_image) }}" alt="Preview" class="img-fluid">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% else %}
|
|
<div class="card mb-4 border-secondary d-none" id="preview-card">
|
|
<div class="card-header bg-secondary text-white d-flex justify-content-between align-items-center p-2">
|
|
<small>Latest Preview</small>
|
|
<form action="{{ url_for('replace_style_cover_from_preview', slug=style.slug) }}" method="post" class="m-0" id="replace-cover-form">
|
|
<button type="submit" class="btn btn-sm btn-outline-light" id="replace-cover-btn" disabled>Replace Cover</button>
|
|
</form>
|
|
</div>
|
|
<div class="card-body p-0">
|
|
<div class="img-container" style="height: auto; min-height: 400px; cursor: pointer;" data-bs-toggle="modal" data-bs-target="#imageModal" onclick="showImage(this.querySelector('img').src)">
|
|
<img id="preview-img" src="" alt="Preview" class="img-fluid">
|
|
</div>
|
|
</div>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
|
|
<div class="col-md-8">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<div>
|
|
<h1 class="mb-0">{{ style.name }}</h1>
|
|
<div class="mt-1">
|
|
<a href="{{ url_for('edit_style', slug=style.slug) }}" class="btn btn-sm btn-link text-decoration-none ps-0">Edit Style</a>
|
|
<span class="text-muted">|</span>
|
|
<form action="{{ url_for('clone_style', slug=style.slug) }}" method="post" style="display: inline;">
|
|
<button type="submit" class="btn btn-sm btn-link text-decoration-none">Clone Style</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
<a href="{{ url_for('styles_index') }}" class="btn btn-outline-secondary">Back to Gallery</a>
|
|
</div>
|
|
|
|
<form id="generate-form" action="{{ url_for('generate_style_image', slug=style.slug) }}" method="post">
|
|
{# Style definition section #}
|
|
{% set sdata = style.data.get('style', {}) %}
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-light">
|
|
<strong>Style Definition</strong>
|
|
</div>
|
|
<div class="card-body">
|
|
<dl class="row mb-0">
|
|
<dt class="col-sm-4 text-capitalize">
|
|
{{ selection_checkbox('style', 'artist_name', 'Artist Name', sdata.get('artist_name')) }}
|
|
Artist Name
|
|
</dt>
|
|
<dd class="col-sm-8">by {{ sdata.get('artist_name') if sdata.get('artist_name') else '--' }}</dd>
|
|
|
|
<dt class="col-sm-4 text-capitalize">
|
|
{{ selection_checkbox('style', 'artistic_style', 'Artistic Style', sdata.get('artistic_style')) }}
|
|
Artistic Style
|
|
</dt>
|
|
<dd class="col-sm-8">{{ sdata.get('artistic_style') if sdata.get('artistic_style') else '--' }}</dd>
|
|
</dl>
|
|
</div>
|
|
</div>
|
|
|
|
{# Character Identity/Wardrobe context when character is selected #}
|
|
<div id="character-context" class="{% if not selected_character or selected_character == '__random__' %}d-none{% endif %}">
|
|
<div class="alert alert-info">
|
|
<i class="bi bi-info-circle"></i> When a character is selected, their identity and active wardrobe fields will be automatically included.
|
|
</div>
|
|
</div>
|
|
|
|
{# LoRA section #}
|
|
{% set lora = style.data.get('lora', {}) %}
|
|
<div class="card mb-4">
|
|
<div class="card-header bg-light d-flex justify-content-between align-items-center">
|
|
<strong>LoRA Integration</strong>
|
|
<div class="form-check form-switch">
|
|
<input class="form-check-input" type="checkbox" name="include_field" value="lora::lora_triggers" id="includeLora"
|
|
{% if preferences is not none %}
|
|
{% if 'lora::lora_triggers' in preferences %}checked{% endif %}
|
|
{% elif style.default_fields is not none %}
|
|
{% if 'lora::lora_triggers' in style.default_fields %}checked{% endif %}
|
|
{% else %}
|
|
checked
|
|
{% endif %}>
|
|
<label class="form-check-label small" for="includeLora">Include Triggers</label>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<dl class="row mb-0">
|
|
<dt class="col-sm-4">LoRA Name</dt>
|
|
<dd class="col-sm-8 text-muted small">{{ lora.get('lora_name') if lora.get('lora_name') else '--' }}</dd>
|
|
|
|
<dt class="col-sm-4">Weight</dt>
|
|
<dd class="col-sm-8">{{ lora.get('lora_weight', 1.0) }}</dd>
|
|
|
|
<dt class="col-sm-4">Triggers</dt>
|
|
<dd class="col-sm-8 small"><code>{{ lora.get('lora_triggers') if lora.get('lora_triggers') else '--' }}</code></dd>
|
|
</dl>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block scripts %}
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const form = document.getElementById('generate-form');
|
|
const progressBar = document.getElementById('progress-bar');
|
|
const progressContainer = document.getElementById('progress-container');
|
|
const progressLabel = document.getElementById('progress-label');
|
|
const previewCard = document.getElementById('preview-card');
|
|
const previewImg = document.getElementById('preview-img');
|
|
const charSelect = document.getElementById('character_select');
|
|
const charContext = document.getElementById('character-context');
|
|
|
|
// Toggle character context info
|
|
charSelect.addEventListener('change', () => {
|
|
if (charSelect.value && charSelect.value !== '__random__') {
|
|
charContext.classList.remove('d-none');
|
|
} else {
|
|
charContext.classList.add('d-none');
|
|
}
|
|
});
|
|
|
|
// Generate a unique client ID
|
|
const clientId = 'style_detail_' + Math.random().toString(36).substring(2, 15);
|
|
|
|
// ComfyUI WebSocket
|
|
const socket = new WebSocket('{{ COMFYUI_WS_URL }}?clientId=' + clientId);
|
|
|
|
const nodeNames = {
|
|
"3": "Sampling",
|
|
"11": "Face Detailing",
|
|
"13": "Hand Detailing",
|
|
"4": "Loading Models",
|
|
"16": "Character LoRA",
|
|
"17": "Outfit LoRA",
|
|
"18": "Action LoRA",
|
|
"19": "Style/Detailer LoRA",
|
|
"8": "Decoding Image",
|
|
"9": "Saving Image"
|
|
};
|
|
|
|
let currentPromptId = null;
|
|
let currentAction = null;
|
|
|
|
socket.addEventListener('message', (event) => {
|
|
const msg = JSON.parse(event.data);
|
|
|
|
if (msg.type === 'status') {
|
|
if (!currentPromptId) {
|
|
const queueRemaining = msg.data.status.exec_info.queue_remaining;
|
|
if (queueRemaining > 0) {
|
|
progressLabel.textContent = `Queue position: ${queueRemaining}`;
|
|
}
|
|
}
|
|
}
|
|
else if (msg.type === 'progress') {
|
|
if (msg.data.prompt_id !== currentPromptId) return;
|
|
const value = msg.data.value;
|
|
const max = msg.data.max;
|
|
const percent = Math.round((value / max) * 100);
|
|
progressBar.style.width = `${percent}%`;
|
|
progressBar.textContent = `${percent}%`;
|
|
}
|
|
else if (msg.type === 'executing') {
|
|
if (msg.data.prompt_id !== currentPromptId) return;
|
|
|
|
const nodeId = msg.data.node;
|
|
if (nodeId === null) {
|
|
// Execution finished via WebSocket
|
|
console.log('Finished via WebSocket');
|
|
if (resolveCompletion) resolveCompletion();
|
|
} else {
|
|
const nodeName = nodeNames[nodeId] || `Processing...`;
|
|
progressLabel.textContent = nodeName;
|
|
}
|
|
}
|
|
});
|
|
|
|
let resolveCompletion = null;
|
|
async function waitForCompletion(promptId) {
|
|
return new Promise((resolve) => {
|
|
const checkResolve = () => {
|
|
clearInterval(pollInterval);
|
|
resolve();
|
|
};
|
|
resolveCompletion = checkResolve;
|
|
|
|
// Fallback polling in case WebSocket is blocked (403)
|
|
const pollInterval = setInterval(async () => {
|
|
try {
|
|
const resp = await fetch(`/check_status/${promptId}`);
|
|
const data = await resp.json();
|
|
if (data.status === 'finished') {
|
|
checkResolve();
|
|
}
|
|
} catch (err) { console.error('Polling error:', err); }
|
|
}, 2000);
|
|
});
|
|
}
|
|
|
|
form.addEventListener('submit', async (e) => {
|
|
const submitter = e.submitter;
|
|
if (!submitter || submitter.value !== 'preview') return;
|
|
|
|
e.preventDefault();
|
|
|
|
currentAction = submitter.value;
|
|
const formData = new FormData(form);
|
|
formData.append('action', currentAction);
|
|
formData.append('client_id', clientId);
|
|
|
|
progressContainer.classList.remove('d-none');
|
|
progressBar.style.width = '0%';
|
|
progressBar.textContent = '0%';
|
|
progressLabel.textContent = 'Starting...';
|
|
|
|
try {
|
|
const response = await fetch(form.getAttribute('action'), {
|
|
method: 'POST',
|
|
body: formData,
|
|
headers: { 'X-Requested-With': 'XMLHttpRequest' }
|
|
});
|
|
|
|
const data = await response.json();
|
|
if (data.error) {
|
|
alert('Error: ' + data.error);
|
|
progressContainer.classList.add('d-none');
|
|
return;
|
|
}
|
|
|
|
currentPromptId = data.prompt_id;
|
|
progressLabel.textContent = 'Queued...';
|
|
progressBar.style.width = '100%';
|
|
progressBar.textContent = 'Queued';
|
|
progressBar.classList.add('progress-bar-striped', 'progress-bar-animated');
|
|
|
|
await waitForCompletion(currentPromptId);
|
|
finalizeGeneration(currentPromptId, currentAction);
|
|
currentPromptId = null;
|
|
|
|
} catch (err) {
|
|
console.error(err);
|
|
alert('Request failed');
|
|
progressContainer.classList.add('d-none');
|
|
}
|
|
});
|
|
|
|
async function finalizeGeneration(promptId, action) {
|
|
progressLabel.textContent = 'Saving image...';
|
|
const url = `/style/{{ style.slug }}/finalize_generation/${promptId}`;
|
|
const formData = new FormData();
|
|
formData.append('action', 'preview'); // Always save as preview
|
|
|
|
try {
|
|
const response = await fetch(url, { method: 'POST', body: formData });
|
|
const data = await response.json();
|
|
|
|
if (data.success) {
|
|
previewImg.src = data.image_url;
|
|
if (previewCard) previewCard.classList.remove('d-none');
|
|
|
|
const replaceBtn = document.getElementById('replace-cover-btn');
|
|
if (replaceBtn) {
|
|
replaceBtn.disabled = false;
|
|
const form = replaceBtn.closest('form');
|
|
if (form) {
|
|
form.action = `/style/{{ style.slug }}/replace_cover_from_preview`;
|
|
}
|
|
}
|
|
} else {
|
|
alert('Save failed: ' + data.error);
|
|
}
|
|
} catch (err) {
|
|
console.error(err);
|
|
alert('Finalize request failed');
|
|
} finally {
|
|
progressContainer.classList.add('d-none');
|
|
}
|
|
}
|
|
});
|
|
|
|
function showImage(src) {
|
|
document.getElementById('modalImage').src = src;
|
|
}
|
|
</script>
|
|
{% endblock %}
|