202 lines
11 KiB
HTML
202 lines
11 KiB
HTML
{% extends "layout.html" %}
|
|
|
|
{% block content %}
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h2>Checkpoint Library</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 checkpoints 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 checkpoints"><img src="{{ url_for('static', filename='icons/new-cover-batch.png') }}"></button>
|
|
<form action="{{ url_for('bulk_create_checkpoints') }}" method="post" class="d-contents">
|
|
<button type="submit" class="btn btn-sm btn-primary btn-icon" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Create new checkpoint entries from all checkpoint files"><img src="{{ url_for('static', filename='icons/new-file.png') }}"></button>
|
|
</form>
|
|
<form action="{{ url_for('bulk_create_checkpoints') }}" method="post" class="d-contents">
|
|
<input type="hidden" name="overwrite" value="true">
|
|
<button type="submit" class="btn btn-sm btn-danger btn-icon" data-bs-toggle="tooltip" data-bs-placement="bottom" title="Overwrite all checkpoint metadata (uses API credits)" onclick="return confirm('WARNING: This will re-run LLM generation for ALL checkpoints, consuming API credits and overwriting ALL existing metadata. Are you sure?')"><img src="{{ url_for('static', filename='icons/new-file.png') }}"></button>
|
|
</form>
|
|
<form action="{{ url_for('rescan_checkpoints') }}" 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 checkpoint 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 Checkpoints...</h5>
|
|
<span id="batch-node-status" class="badge bg-info text-dark">Starting...</span>
|
|
</div>
|
|
<div class="mb-3">
|
|
<small class="text-muted">Overall Batch Progress</small>
|
|
<div class="progress" 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-ckpt-name" class="text-muted mb-1"></small>
|
|
<small id="current-step-progress" class="text-muted mb-1"></small>
|
|
</div>
|
|
<div class="progress" 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-2 row-cols-sm-3 row-cols-md-4 row-cols-lg-5 row-cols-xl-6 g-3">
|
|
{% for ckpt in checkpoints %}
|
|
<div class="col" id="card-{{ ckpt.slug }}">
|
|
<div class="card h-100 character-card" onclick="window.location.href='/checkpoint/{{ ckpt.slug }}'">
|
|
<div class="img-container">
|
|
{% if ckpt.image_path %}
|
|
<img id="img-{{ ckpt.slug }}" src="{{ url_for('static', filename='uploads/' + ckpt.image_path) }}" alt="{{ ckpt.name }}">
|
|
<span id="no-img-{{ ckpt.slug }}" class="text-muted d-none">No Image</span>
|
|
{% else %}
|
|
<img id="img-{{ ckpt.slug }}" src="" alt="{{ ckpt.name }}" class="d-none">
|
|
<span id="no-img-{{ ckpt.slug }}" class="text-muted">No Image</span>
|
|
{% endif %}
|
|
</div>
|
|
<div class="card-body">
|
|
<h5 class="card-title text-center">{{ ckpt.name }}</h5>
|
|
</div>
|
|
<div class="card-footer d-flex justify-content-between align-items-center p-1">
|
|
<small class="text-muted" title="{{ ckpt.checkpoint_path }}">{{ ckpt.checkpoint_path.split('/')[0] }}</small>
|
|
<button class="btn btn-sm btn-outline-danger py-0 px-1 ms-1 resource-delete-btn" title="Delete"
|
|
data-category="checkpoints" data-slug="{{ ckpt.slug }}" data-name="{{ ckpt.name | e }}">🗑</button>
|
|
</div>
|
|
</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 ckptNameText = document.getElementById('current-ckpt-name');
|
|
const stepProgressText = document.getElementById('current-step-progress');
|
|
|
|
let currentJobId = null;
|
|
|
|
async function waitForJob(jobId) {
|
|
return new Promise((resolve, reject) => {
|
|
const poll = setInterval(async () => {
|
|
try {
|
|
const resp = await fetch(`/api/queue/${jobId}/status`);
|
|
const data = await resp.json();
|
|
if (data.status === 'done') { clearInterval(poll); resolve(data); }
|
|
else if (data.status === 'failed' || data.status === 'removed') { clearInterval(poll); reject(new Error(data.error || 'Job failed')); }
|
|
else if (data.status === 'processing') nodeStatus.textContent = 'Generating…';
|
|
else nodeStatus.textContent = 'Queued…';
|
|
} catch (err) {}
|
|
}, 1500);
|
|
});
|
|
}
|
|
|
|
async function runBatch() {
|
|
const response = await fetch('/get_missing_checkpoints');
|
|
const data = await response.json();
|
|
const missing = data.missing;
|
|
|
|
if (missing.length === 0) {
|
|
alert('No checkpoints missing cover images.');
|
|
return;
|
|
}
|
|
|
|
batchBtn.disabled = true;
|
|
regenAllBtn.disabled = true;
|
|
container.classList.remove('d-none');
|
|
|
|
// Phase 1: Queue all jobs upfront
|
|
progressBar.style.width = '100%';
|
|
progressBar.textContent = '';
|
|
progressBar.classList.add('progress-bar-striped', 'progress-bar-animated');
|
|
nodeStatus.textContent = 'Queuing…';
|
|
|
|
const jobs = [];
|
|
for (const ckpt of missing) {
|
|
statusText.textContent = `Queuing ${jobs.length + 1} / ${missing.length}…`;
|
|
try {
|
|
const genResp = await fetch(`/checkpoint/${ckpt.slug}/generate`, {
|
|
method: 'POST',
|
|
body: new URLSearchParams({ character_slug: '__random__' }),
|
|
headers: { 'X-Requested-With': 'XMLHttpRequest' }
|
|
});
|
|
const genData = await genResp.json();
|
|
if (genData.job_id) jobs.push({ item: ckpt, jobId: genData.job_id });
|
|
} catch (err) {
|
|
console.error(`Failed to queue ${ckpt.name}:`, err);
|
|
}
|
|
}
|
|
|
|
// Phase 2: Poll all concurrently
|
|
progressBar.classList.remove('progress-bar-striped', 'progress-bar-animated');
|
|
progressBar.style.width = '0%';
|
|
progressBar.textContent = '0%';
|
|
statusText.textContent = `0 / ${jobs.length} done`;
|
|
|
|
let completed = 0;
|
|
let currentItem = '';
|
|
await Promise.all(jobs.map(async ({ item, jobId }) => {
|
|
currentItem = item.name;
|
|
ckptNameText.textContent = `Processing: ${currentItem}`;
|
|
try {
|
|
const jobResult = await waitForJob(jobId);
|
|
if (jobResult.result && jobResult.result.image_url) {
|
|
const img = document.getElementById(`img-${item.slug}`);
|
|
const noImgSpan = document.getElementById(`no-img-${item.slug}`);
|
|
if (img) { img.src = jobResult.result.image_url; img.classList.remove('d-none'); }
|
|
if (noImgSpan) noImgSpan.classList.add('d-none');
|
|
}
|
|
} catch (err) {
|
|
console.error(`Failed for ${item.name}:`, err);
|
|
}
|
|
completed++;
|
|
const pct = Math.round((completed / jobs.length) * 100);
|
|
progressBar.style.width = `${pct}%`;
|
|
progressBar.textContent = `${pct}%`;
|
|
statusText.textContent = `${completed} / ${jobs.length} done`;
|
|
}));
|
|
|
|
progressBar.style.width = '100%';
|
|
progressBar.textContent = '100%';
|
|
statusText.textContent = 'Batch Checkpoint Generation Complete!';
|
|
ckptNameText.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_checkpoints');
|
|
const data = await response.json();
|
|
if (data.missing.length === 0) { alert('No checkpoints missing cover images.'); return; }
|
|
if (!confirm(`Generate cover images for ${data.missing.length} checkpoints?`)) return;
|
|
runBatch();
|
|
});
|
|
|
|
regenAllBtn.addEventListener('click', async () => {
|
|
if (!confirm('This will unassign ALL current checkpoint cover images and generate new ones. Proceed?')) return;
|
|
const clearResp = await fetch('/clear_all_checkpoint_covers', { method: 'POST' });
|
|
if (clearResp.ok) {
|
|
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 %}
|