Add danbooru-mcp auto-start, git sync, status API endpoints, navbar status indicators, and LLM format retry

- app.py: add subprocess import; add _ensure_mcp_repo() to clone/pull
  danbooru-mcp from https://git.liveaodh.com/aodhan/danbooru-mcp into
  tools/danbooru-mcp/ at startup; add ensure_mcp_server_running() which
  calls _ensure_mcp_repo() then starts the Docker container if not running;
  add GET /api/status/comfyui and GET /api/status/mcp health endpoints;
  fix call_llm() to retry up to 3 times on unexpected response format
  (KeyError/IndexError), logging the raw response and prompting the LLM
  to respond with valid JSON before each retry
- templates/layout.html: add ComfyUI and MCP status dot indicators to
  navbar; add polling JS that checks both endpoints on load and every 30s
- static/style.css: add .service-status, .status-dot, .status-ok,
  .status-error, .status-checking styles and status-pulse keyframe animation
- .gitignore: add tools/ to exclude the cloned danbooru-mcp repo
This commit is contained in:
Aodhan Collins
2026-03-03 00:57:27 +00:00
parent 0b8802deb5
commit ae7ba961c1
1194 changed files with 17475 additions and 3268 deletions

View File

@@ -1,6 +1,34 @@
{% extends "layout.html" %}
{% block content %}
<!-- JSON Editor Modal -->
<div class="modal fade" id="jsonEditorModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Edit JSON — {{ style.name }}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<ul class="nav nav-tabs mb-3" role="tablist">
<li class="nav-item"><button class="nav-link active" id="json-simple-tab" type="button">Simple</button></li>
<li class="nav-item"><button class="nav-link" id="json-advanced-tab" type="button">Advanced JSON</button></li>
</ul>
<div id="json-editor-error" class="alert alert-danger d-none"></div>
<div id="json-simple-panel"></div>
<div id="json-advanced-panel" class="d-none">
<textarea id="json-editor-textarea" class="form-control font-monospace" rows="20" spellcheck="false"></textarea>
</div>
<script type="application/json" id="json-raw-data">{{ style.data | tojson }}</script>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-primary" id="json-save-btn">Save</button>
</div>
</div>
</div>
</div>
<!-- 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">
@@ -104,7 +132,7 @@
</div>
<div class="col-md-8">
<div class="d-flex justify-content-between align-items-center mb-4">
<div class="d-flex justify-content-between align-items-center mb-3">
<div>
<h1 class="mb-0">{{ style.name }}</h1>
<div class="mt-1">
@@ -115,73 +143,125 @@
</form>
</div>
</div>
<a href="{{ url_for('styles_index') }}" class="btn btn-outline-secondary">Back to Gallery</a>
<div class="d-flex gap-2">
<button type="button" class="btn btn-outline-secondary" data-bs-toggle="modal" data-bs-target="#jsonEditorModal">Edit JSON</button>
<a href="{{ url_for('styles_index') }}" class="btn btn-outline-secondary">Back to Gallery</a>
</div>
</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>
<ul class="nav nav-tabs mb-4" id="detailTabs" role="tablist">
<li class="nav-item" role="presentation">
<button class="nav-link active" id="settings-tab" data-bs-toggle="tab" data-bs-target="#settings-pane" type="button" role="tab">Settings</button>
</li>
<li class="nav-item" role="presentation">
<button class="nav-link" id="previews-tab" data-bs-toggle="tab" data-bs-target="#previews-pane" type="button" role="tab">
Previews{% if existing_previews %} <span class="badge bg-secondary">{{ existing_previews|length }}</span>{% endif %}
</button>
</li>
</ul>
<div class="tab-content" id="detailTabContent">
<div class="tab-pane fade show active" id="settings-pane" role="tabpanel">
<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>
{# 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 class="tab-pane fade" id="previews-pane" role="tabpanel">
<div class="d-flex justify-content-between align-items-center mb-3">
<span class="text-muted small">{{ existing_previews|length }} preview(s)</span>
<div class="d-flex gap-2">
<button type="button" id="generate-all-btn" class="btn btn-primary btn-sm">Generate All Characters</button>
<button type="button" id="stop-all-btn" class="btn btn-danger btn-sm d-none">Stop</button>
</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 id="batch-progress" class="mb-3 d-none">
<label id="batch-label" class="form-label small fw-semibold"></label>
<div class="progress" style="height: 8px;">
<div id="batch-bar" class="progress-bar progress-bar-striped progress-bar-animated" style="width: 0%"></div>
</div>
</div>
<div id="preview-gallery" class="row row-cols-2 row-cols-md-3 g-2">
{% for img in existing_previews %}
<div class="col">
<img src="{{ url_for('static', filename='uploads/' + img) }}"
class="img-fluid rounded"
style="cursor: pointer; aspect-ratio: 1; object-fit: cover; width: 100%;"
onclick="showImage(this.src)"
data-bs-toggle="modal" data-bs-target="#imageModal">
</div>
{% else %}
<div class="col-12 text-muted small" id="gallery-empty">No previews yet. Generate some!</div>
{% endfor %}
</div>
</div>
</form>
</div>
</div>
</div>
{% set sg_entity = style %}
{% set sg_category = 'styles' %}
{% set sg_has_lora = style.data.get('lora', {}).get('lora_name', '') != '' %}
{% include 'partials/strengths_gallery.html' %}
{% endblock %}
{% block scripts %}
@@ -362,8 +442,113 @@
progressContainer.classList.add('d-none');
}
}
// Batch: Generate All Characters
const allCharacters = [
{% for char in characters %}{ slug: "{{ char.slug }}", name: {{ char.name | tojson }} },
{% endfor %}
];
const finalizeBaseUrl = '/style/{{ style.slug }}/finalize_generation';
let stopBatch = false;
const generateAllBtn = document.getElementById('generate-all-btn');
const stopAllBtn = document.getElementById('stop-all-btn');
const batchProgress = document.getElementById('batch-progress');
const batchLabel = document.getElementById('batch-label');
const batchBar = document.getElementById('batch-bar');
function addToPreviewGallery(imageUrl, charName) {
const gallery = document.getElementById('preview-gallery');
const placeholder = document.getElementById('gallery-empty');
if (placeholder) placeholder.remove();
const col = document.createElement('div');
col.className = 'col';
col.innerHTML = `<div class="position-relative">
<img src="${imageUrl}" class="img-fluid rounded"
style="cursor: pointer; aspect-ratio: 1; object-fit: cover; width: 100%;"
onclick="showImage(this.src)"
data-bs-toggle="modal" data-bs-target="#imageModal"
title="${charName}">
<div class="position-absolute bottom-0 start-0 w-100 bg-dark bg-opacity-50 text-white p-1 rounded-bottom" style="font-size: 0.7rem; line-height: 1.2;">${charName}</div>
</div>`;
gallery.insertBefore(col, gallery.firstChild);
const badge = document.querySelector('#previews-tab .badge');
if (badge) badge.textContent = parseInt(badge.textContent || '0') + 1;
else document.getElementById('previews-tab').insertAdjacentHTML('beforeend', ' <span class="badge bg-secondary">1</span>');
}
generateAllBtn.addEventListener('click', async () => {
if (allCharacters.length === 0) { alert('No characters available.'); return; }
stopBatch = false;
generateAllBtn.disabled = true;
stopAllBtn.classList.remove('d-none');
batchProgress.classList.remove('d-none');
bootstrap.Tab.getOrCreateInstance(document.getElementById('previews-tab')).show();
for (let i = 0; i < allCharacters.length; i++) {
if (stopBatch) break;
const char = allCharacters[i];
batchBar.style.width = `${Math.round((i / allCharacters.length) * 100)}%`;
batchLabel.textContent = `Generating ${char.name} (${i + 1} / ${allCharacters.length})`;
const genForm = document.getElementById('generate-form');
const fd = new FormData();
genForm.querySelectorAll('input[name="include_field"]:checked').forEach(cb => fd.append('include_field', cb.value));
fd.append('character_slug', char.slug);
fd.append('action', 'preview');
fd.append('client_id', clientId);
try {
progressContainer.classList.remove('d-none');
progressBar.style.width = '0%';
progressBar.textContent = '0%';
progressLabel.textContent = `${char.name}: Starting...`;
const resp = await fetch(genForm.getAttribute('action'), {
method: 'POST', body: fd, headers: { 'X-Requested-With': 'XMLHttpRequest' }
});
const data = await resp.json();
if (data.error) { console.error(`Error for ${char.name}:`, data.error); progressContainer.classList.add('d-none'); continue; }
currentPromptId = data.prompt_id;
await waitForCompletion(currentPromptId);
progressLabel.textContent = 'Saving image...';
const finalFD = new FormData();
finalFD.append('action', 'preview');
const finalResp = await fetch(`${finalizeBaseUrl}/${currentPromptId}`, { method: 'POST', body: finalFD });
const finalData = await finalResp.json();
if (finalData.success) {
addToPreviewGallery(finalData.image_url, char.name);
previewImg.src = finalData.image_url;
if (previewCard) previewCard.classList.remove('d-none');
}
currentPromptId = null;
} catch (err) {
console.error(`Failed for ${char.name}:`, err);
currentPromptId = null;
} finally {
progressContainer.classList.add('d-none');
}
}
batchBar.style.width = '100%';
batchLabel.textContent = stopBatch ? 'Stopped.' : 'Complete!';
generateAllBtn.disabled = false;
stopAllBtn.classList.add('d-none');
setTimeout(() => { batchProgress.classList.add('d-none'); batchBar.style.width = '0%'; }, 3000);
});
stopAllBtn.addEventListener('click', () => {
stopBatch = true;
stopAllBtn.classList.add('d-none');
batchLabel.textContent = 'Stopping after current generation...';
});
// JSON Editor
initJsonEditor('{{ url_for("save_style_json", slug=style.slug) }}');
});
function showImage(src) {
document.getElementById('modalImage').src = src;
}