sync active training with UI if running
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user