sync active training with UI if running

This commit is contained in:
Dobromir Popov
2025-11-12 22:37:20 +02:00
parent fcbc475686
commit 1af3124be7
7 changed files with 384 additions and 10 deletions

View File

@@ -92,6 +92,16 @@
// Load initial data (may call renderAnnotationsList which needs deleteAnnotation)
loadInitialData();
// Load available models for training panel
if (typeof loadAvailableModels === 'function') {
loadAvailableModels();
}
// Check for active training session (resume tracking after page reload)
if (typeof checkActiveTraining === 'function') {
checkActiveTraining();
}
// Setup keyboard shortcuts
setupKeyboardShortcuts();
});

View File

@@ -109,6 +109,30 @@
// Track model states
let modelStates = [];
let selectedModel = null;
let activeTrainingId = null; // Track active training session
function checkActiveTraining() {
/**
* Check if there's an active training session on page load
* This allows resuming progress tracking after page reload
*/
fetch('/api/active-training')
.then(response => response.json())
.then(data => {
if (data.success && data.active && data.session) {
console.log('Active training session found:', data.session);
// Resume tracking
activeTrainingId = data.session.training_id;
showTrainingStatus();
pollTrainingProgress(activeTrainingId);
} else {
console.log('No active training session');
}
})
.catch(error => {
console.error('Error checking active training:', error);
});
}
function loadAvailableModels() {
fetch('/api/available-models')
@@ -290,11 +314,16 @@
startTraining(modelName, annotationIds);
});
function startTraining(modelName, annotationIds) {
// Show training status
function showTrainingStatus() {
// Show training status UI
document.getElementById('training-status').style.display = 'block';
document.getElementById('training-results').style.display = 'none';
document.getElementById('train-model-btn').disabled = true;
}
function startTraining(modelName, annotationIds) {
// Show training status
showTrainingStatus();
// Reset progress
document.getElementById('training-progress-bar').style.width = '0%';
@@ -313,18 +342,22 @@
.then(response => response.json())
.then(data => {
if (data.success) {
// Store active training ID for persistence across reloads
activeTrainingId = data.training_id;
// Start polling for training progress
pollTrainingProgress(data.training_id);
} else {
showError('Failed to start training: ' + data.error.message);
document.getElementById('training-status').style.display = 'none';
document.getElementById('train-model-btn').disabled = false;
activeTrainingId = null;
}
})
.catch(error => {
showError('Network error: ' + error.message);
document.getElementById('training-status').style.display = 'none';
document.getElementById('train-model-btn').disabled = false;
activeTrainingId = null;
});
}
@@ -350,9 +383,11 @@
// Check if complete
if (progress.status === 'completed') {
clearInterval(pollInterval);
activeTrainingId = null; // Clear active training
showTrainingResults(progress);
} else if (progress.status === 'failed') {
clearInterval(pollInterval);
activeTrainingId = null; // Clear active training
showError('Training failed: ' + progress.error);
document.getElementById('training-status').style.display = 'none';
document.getElementById('train-model-btn').disabled = false;
@@ -361,6 +396,7 @@
})
.catch(error => {
clearInterval(pollInterval);
// Don't clear activeTrainingId on network error - training might still be running
showError('Failed to get training progress: ' + error.message);
document.getElementById('training-status').style.display = 'none';
document.getElementById('train-model-btn').disabled = false;