- 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
272 lines
13 KiB
HTML
272 lines
13 KiB
HTML
{% extends "layout.html" %}
|
|
|
|
{% block content %}
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2>Character Gallery</h2>
|
|
<div class="d-flex gap-1 align-items-center">
|
|
<button id="batch-generate-btn" class="btn btn-sm btn-outline-success btn-icon" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Generate cover images for characters without one"><img src="{{ url_for('static', filename='icons/new-cover-batch.png') }}"></button>
|
|
<button id="regenerate-all-btn" class="btn btn-sm btn-outline-danger btn-icon" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Regenerate cover images for all characters"><img src="{{ url_for('static', filename='icons/new-cover-batch.png') }}"></button>
|
|
<form action="{{ url_for('rescan') }}" method="post" class="d-contents">
|
|
<button type="submit" class="btn btn-sm btn-outline-primary btn-icon" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Rescan character files from disk"><img src="{{ url_for('static', filename='icons/refresh.png') }}"></button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Batch Progress Bar -->
|
|
<div id="batch-progress-container" class="card mb-4 d-none">
|
|
<div class="card-body">
|
|
<div class="d-flex justify-content-between align-items-center mb-1">
|
|
<h5 id="batch-status-text" class="mb-0">Batch Generating...</h5>
|
|
<span id="batch-node-status" class="badge bg-info">Starting...</span>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<small class="text-muted">Overall Batch Progress</small>
|
|
<div class="progress" role="progressbar" aria-label="Batch Progress" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="height: 10px;">
|
|
<div id="batch-progress-bar" class="progress-bar bg-success" style="width: 0%"></div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="mb-2">
|
|
<div class="d-flex justify-content-between">
|
|
<small id="current-char-name" class="text-muted mb-1"></small>
|
|
<small id="current-step-progress" class="text-muted mb-1"></small>
|
|
</div>
|
|
<div class="progress" role="progressbar" aria-label="Task Progress" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="height: 20px;">
|
|
<div id="task-progress-bar" class="progress-bar progress-bar-striped progress-bar-animated bg-info" style="width: 0%"></div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="row row-cols-1 row-cols-sm-2 row-cols-md-3 row-cols-lg-4 g-4">
|
|
{% for char in characters %}
|
|
<div class="col" id="card-{{ char.slug }}">
|
|
<div class="card h-100 character-card" onclick="window.location.href='/character/{{ char.slug }}'">
|
|
<div class="img-container">
|
|
{% if char.image_path %}
|
|
<img id="img-{{ char.slug }}" src="{{ url_for('static', filename='uploads/' + char.image_path) }}" alt="{{ char.name }}">
|
|
<span id="no-img-{{ char.slug }}" class="text-muted d-none">No Image</span>
|
|
{% else %}
|
|
<img id="img-{{ char.slug }}" src="" alt="{{ char.name }}" class="d-none">
|
|
<span id="no-img-{{ char.slug }}" class="text-muted">No Image</span>
|
|
{% endif %}
|
|
</div>
|
|
<div class="card-body">
|
|
<h5 class="card-title text-center">{{ char.name }}</h5>
|
|
<p class="card-text small text-center text-muted">
|
|
{% set ns = namespace(parts=[]) %}
|
|
{% for section_key in ['identity', 'defaults'] %}
|
|
{% if char.data[section_key] is mapping %}
|
|
{% for v in char.data[section_key].values() %}
|
|
{% if v %}{% set ns.parts = ns.parts + [v] %}{% endif %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endfor %}
|
|
{% set wardrobe = char.data.get('wardrobe', {}) %}
|
|
{% if wardrobe %}
|
|
{% set outfit_data = wardrobe.get('default', wardrobe) %}
|
|
{% if outfit_data is mapping %}
|
|
{% for v in outfit_data.values() %}
|
|
{% if v and v is string %}{% set ns.parts = ns.parts + [v] %}{% endif %}
|
|
{% endfor %}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% if char.data.lora and char.data.lora.lora_triggers %}
|
|
{% set ns.parts = ns.parts + [char.data.lora.lora_triggers] %}
|
|
{% endif %}
|
|
{{ ns.parts | join(', ') }}
|
|
</p>
|
|
</div>
|
|
{% if char.data.lora.lora_name %}
|
|
{% set lora_name = char.data.lora.lora_name.split('/')[-1].replace('.safetensors', '') %}
|
|
<div class="card-footer text-center p-1">
|
|
<small class="text-muted" title="{{ char.data.lora.lora_name }}">{{ lora_name }}</small>
|
|
</div>
|
|
{% endif %}
|
|
</div>
|
|
</div>
|
|
{% endfor %}
|
|
</div>
|
|
{% endblock %}
|
|
|
|
{% block scripts %}
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
const batchBtn = document.getElementById('batch-generate-btn');
|
|
const regenAllBtn = document.getElementById('regenerate-all-btn');
|
|
const progressBar = document.getElementById('batch-progress-bar');
|
|
const taskProgressBar = document.getElementById('task-progress-bar');
|
|
const container = document.getElementById('batch-progress-container');
|
|
const statusText = document.getElementById('batch-status-text');
|
|
const nodeStatus = document.getElementById('batch-node-status');
|
|
const charNameText = document.getElementById('current-char-name');
|
|
const stepProgressText = document.getElementById('current-step-progress');
|
|
|
|
const clientId = 'gallery_batch_' + Math.random().toString(36).substring(2, 15);
|
|
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",
|
|
"9": "Saving"
|
|
};
|
|
|
|
let currentPromptId = null;
|
|
let resolveGeneration = null;
|
|
|
|
socket.addEventListener('message', (event) => {
|
|
const msg = JSON.parse(event.data);
|
|
|
|
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);
|
|
stepProgressText.textContent = `${percent}%`;
|
|
taskProgressBar.style.width = `${percent}%`;
|
|
taskProgressBar.textContent = `${percent}%`;
|
|
taskProgressBar.classList.remove('progress-bar-striped', 'progress-bar-animated');
|
|
}
|
|
else if (msg.type === 'executing') {
|
|
if (msg.data.prompt_id !== currentPromptId) return;
|
|
const nodeId = msg.data.node;
|
|
if (nodeId === null) {
|
|
if (resolveGeneration) resolveGeneration();
|
|
} else {
|
|
nodeStatus.textContent = nodeNames[nodeId] || `Processing...`;
|
|
stepProgressText.textContent = "";
|
|
// Reset task bar for new node if it's not sampling
|
|
if (nodeId !== "3") {
|
|
taskProgressBar.style.width = '100%';
|
|
taskProgressBar.textContent = nodeNames[nodeId] || 'Processing...';
|
|
taskProgressBar.classList.add('progress-bar-striped', 'progress-bar-animated');
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
async function waitForCompletion(promptId) {
|
|
return new Promise((resolve) => {
|
|
const checkResolve = () => {
|
|
clearInterval(pollInterval);
|
|
resolve();
|
|
};
|
|
resolveGeneration = checkResolve;
|
|
const pollInterval = setInterval(async () => {
|
|
try {
|
|
const resp = await fetch(`/check_status/${promptId}`);
|
|
const data = await resp.json();
|
|
if (data.status === 'finished') {
|
|
checkResolve();
|
|
}
|
|
} catch (err) {}
|
|
}, 2000);
|
|
});
|
|
}
|
|
|
|
async function runBatch() {
|
|
const response = await fetch('/get_missing_characters');
|
|
const data = await response.json();
|
|
const missing = data.missing;
|
|
|
|
if (missing.length === 0) {
|
|
alert("No characters missing cover images.");
|
|
return;
|
|
}
|
|
|
|
batchBtn.disabled = true;
|
|
regenAllBtn.disabled = true;
|
|
container.classList.remove('d-none');
|
|
|
|
let completed = 0;
|
|
for (const char of missing) {
|
|
const percent = Math.round((completed / missing.length) * 100);
|
|
progressBar.style.width = `${percent}%`;
|
|
progressBar.textContent = `${percent}%`;
|
|
statusText.textContent = `Batch Generating: ${completed + 1} / ${missing.length}`;
|
|
charNameText.textContent = `Current: ${char.name}`;
|
|
nodeStatus.textContent = "Queuing...";
|
|
|
|
taskProgressBar.style.width = '100%';
|
|
taskProgressBar.textContent = 'Queued';
|
|
taskProgressBar.classList.add('progress-bar-striped', 'progress-bar-animated');
|
|
|
|
try {
|
|
const genResp = await fetch(`/character/${char.slug}/generate`, {
|
|
method: 'POST',
|
|
body: new URLSearchParams({ 'action': 'replace', 'client_id': clientId }),
|
|
headers: { 'X-Requested-With': 'XMLHttpRequest' }
|
|
});
|
|
const genData = await genResp.json();
|
|
currentPromptId = genData.prompt_id;
|
|
|
|
await waitForCompletion(currentPromptId);
|
|
|
|
const finResp = await fetch(`/character/${char.slug}/finalize_generation/${currentPromptId}`, {
|
|
method: 'POST',
|
|
body: new URLSearchParams({ 'action': 'replace' })
|
|
});
|
|
const finData = await finResp.json();
|
|
|
|
if (finData.success) {
|
|
const img = document.getElementById(`img-${char.slug}`);
|
|
const noImgSpan = document.getElementById(`no-img-${char.slug}`);
|
|
if (img) {
|
|
img.src = finData.image_url;
|
|
img.classList.remove('d-none');
|
|
}
|
|
if (noImgSpan) noImgSpan.classList.add('d-none');
|
|
}
|
|
} catch (err) {
|
|
console.error(`Failed for ${char.name}:`, err);
|
|
}
|
|
completed++;
|
|
}
|
|
|
|
progressBar.style.width = '100%';
|
|
progressBar.textContent = '100%';
|
|
statusText.textContent = "Batch Complete!";
|
|
charNameText.textContent = "";
|
|
nodeStatus.textContent = "Done";
|
|
stepProgressText.textContent = "";
|
|
taskProgressBar.style.width = '0%';
|
|
taskProgressBar.textContent = '';
|
|
batchBtn.disabled = false;
|
|
regenAllBtn.disabled = false;
|
|
setTimeout(() => { container.classList.add('d-none'); }, 5000);
|
|
}
|
|
|
|
batchBtn.addEventListener('click', async () => {
|
|
const response = await fetch('/get_missing_characters');
|
|
const data = await response.json();
|
|
if (data.missing.length === 0) {
|
|
alert("No characters missing cover images.");
|
|
return;
|
|
}
|
|
if (!confirm(`Generate cover images for ${data.missing.length} characters?`)) return;
|
|
runBatch();
|
|
});
|
|
|
|
regenAllBtn.addEventListener('click', async () => {
|
|
if (!confirm("This will unassign ALL current cover images and generate new ones for every character. Existing files will be kept on disk. Proceed?")) return;
|
|
|
|
const clearResp = await fetch('/clear_all_covers', { method: 'POST' });
|
|
if (clearResp.ok) {
|
|
// Update UI to show "No Image" for all
|
|
document.querySelectorAll('.img-container img').forEach(img => img.classList.add('d-none'));
|
|
document.querySelectorAll('.img-container .text-muted').forEach(span => span.classList.remove('d-none'));
|
|
runBatch();
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
{% endblock %}
|