diff --git a/scene_search/web/index.html b/scene_search/web/index.html
index afd0ba8..bee37a3 100644
--- a/scene_search/web/index.html
+++ b/scene_search/web/index.html
@@ -89,6 +89,21 @@
Idle
+
+
+ Captioning
+
+
+ Idle
+
+
+
+
+
+
@@ -105,6 +120,7 @@
(() => {
const $ = id => document.getElementById(id);
let statusTimer = null;
+ let captionTimer = null;
let thumbnailUrls = [];
$('apiKey').value = localStorage.getItem('sceneSearchApiKey') || '';
@@ -238,6 +254,90 @@
}
}
+ function renderCaptionStatus(s) {
+ const percent = Number(s.percent || (s.stage === 'complete' ? 100 : 0));
+ $('captionProgress').value = percent;
+ $('captionText').textContent = percent.toFixed(1).replace('.0','') + '%';
+ $('captionFrames').textContent = (s.frames_completed || 0) + ' / ' + (s.frames_total || 0) + ' frames';
+
+ if (s.running) {
+ $('captionNow').disabled = true;
+ $('captionStatus').className = 'status';
+ if (s.stage === 'routing') {
+ $('captionStatus').textContent = 'Routing frames to caption models';
+ $('captionDetail').textContent = (s.frames_selected || s.frames_total || 0) + ' frames selected';
+ } else if (s.stage === 'syncing' || s.stage === 'sync') {
+ $('captionStatus').textContent = 'Rebuilding search index: ' + (s.documents_processed || 0);
+ $('captionDetail').textContent =
+ (s.frames_completed || 0) + ' captions saved, ' + (s.failed || 0) + ' failed';
+ } else {
+ $('captionStatus').textContent = 'Captioning: ' +
+ (s.title || 'current frame') +
+ (s.timestamp_ms != null ? ' at ' + formatTs(s.timestamp_ms) : '');
+ $('captionDetail').textContent =
+ (s.model || '') +
+ (s.route ? ', ' + s.route : '') +
+ ', ' + (s.failed || 0) + ' failed';
+ }
+ } else if (s.stage === 'failed') {
+ $('captionNow').disabled = false;
+ $('captionStatus').className = 'status error';
+ $('captionStatus').textContent = 'Failed: ' + (s.error || 'unknown error');
+ $('captionDetail').textContent = '';
+ } else if (s.stage === 'complete') {
+ $('captionNow').disabled = false;
+ $('captionStatus').className = 'status ok';
+ $('captionStatus').textContent =
+ 'Complete: ' + (s.frames_completed || 0) + ' saved, ' + (s.failed || 0) + ' failed';
+ $('captionDetail').textContent =
+ (s.retained || 0) + ' existing captions retained';
+ } else {
+ $('captionNow').disabled = false;
+ $('captionStatus').className = 'status muted';
+ $('captionStatus').textContent = 'Idle';
+ $('captionDetail').textContent = '';
+ }
+ }
+
+ async function refreshCaptionStatus() {
+ try {
+ const s = await api('/api/caption/status');
+ renderCaptionStatus(s);
+ if (s.running) {
+ if (!captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
+ } else if (captionTimer) {
+ clearInterval(captionTimer);
+ captionTimer = null;
+ refreshHealth();
+ }
+ return s;
+ } catch (e) {
+ $('captionStatus').className = 'status error';
+ $('captionStatus').textContent = e.message;
+ return null;
+ }
+ }
+
+ async function startCaption() {
+ const ids = selectedLibraries();
+ if (!ids.length) {
+ $('captionStatus').className = 'status error';
+ $('captionStatus').textContent = 'Select at least one library.';
+ return;
+ }
+ try {
+ const s = await api('/api/caption', {
+ method:'POST',
+ body:JSON.stringify({library_ids:ids, force:$('forceCaption').checked})
+ });
+ renderCaptionStatus(s);
+ if (s.running && !captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
+ } catch (e) {
+ $('captionStatus').className = 'status error';
+ $('captionStatus').textContent = e.message;
+ }
+ }
+
function formatTs(ms) {
const seconds = Math.floor((ms || 0) / 1000);
const h = Math.floor(seconds / 3600);
@@ -290,15 +390,16 @@
$('saveKey').onclick = () => {
localStorage.setItem('sceneSearchApiKey', $('apiKey').value.trim());
- loadLibraries(); refreshStatus();
+ loadLibraries(); refreshStatus(); refreshCaptionStatus();
};
$('clearKey').onclick = () => {
localStorage.removeItem('sceneSearchApiKey'); $('apiKey').value = '';
- loadLibraries(); refreshStatus();
+ loadLibraries(); refreshStatus(); refreshCaptionStatus();
};
$('refreshLibraries').onclick = loadLibraries;
$('selectAll').onclick = () => document.querySelectorAll('.libraryCheck').forEach(x => x.checked = true);
$('indexNow').onclick = startIndex;
+ $('captionNow').onclick = startCaption;
$('searchButton').onclick = search;
$('searchQuery').addEventListener('keydown', e => { if (e.key === 'Enter') search(); });
@@ -307,6 +408,9 @@
refreshStatus().then(s => {
if (s && s.running && !statusTimer) statusTimer = setInterval(refreshStatus, 2000);
});
+ refreshCaptionStatus().then(s => {
+ if (s && s.running && !captionTimer) captionTimer = setInterval(refreshCaptionStatus, 2000);
+ });
})();