From 986663cd972e8d4b61f71a3b25782587a1ee607e Mon Sep 17 00:00:00 2001 From: Vito Sansevero Date: Tue, 9 Dec 2025 06:05:14 -0800 Subject: [PATCH] feat(gallery): add model memory management options --- web/gallery.html | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/web/gallery.html b/web/gallery.html index 4bc9b71..3f3db40 100644 --- a/web/gallery.html +++ b/web/gallery.html @@ -600,6 +600,25 @@ + +
+ + +
+
@@ -862,6 +881,7 @@ No sentences, no commentary, no captions. Only tags. Keep length short but descr document.getElementById('applyReviewBtn').addEventListener('click', () => this.applyReviewTags()); document.getElementById('cancelAutoTagBtn').addEventListener('click', () => this.cancelAutoTag()); document.getElementById('cancelDownloadBtn').addEventListener('click', () => this.cancelDownload()); + document.getElementById('unloadModelBtn').addEventListener('click', () => this.unloadModel()); // Close AutoTag modals on outside click ['autoTagModal', 'autoTagReviewModal', 'autoTagProgressModal', 'autoTagDownloadModal'].forEach(modalId => { @@ -3579,6 +3599,9 @@ Seed: ${this.currentMetadata.seed || 'Unknown'}`; async checkAutoTagModels() { const ggufStatus = document.getElementById("ggufModelStatus"); const hfStatus = document.getElementById("hfModelStatus"); + const modelLoadedStatus = document.getElementById("modelLoadedStatus"); + const loadedModelType = document.getElementById("loadedModelType"); + const unloadModelBtn = document.getElementById("unloadModelBtn"); ggufStatus.innerHTML = 'Checking...'; hfStatus.innerHTML = 'Checking...'; @@ -3601,6 +3624,16 @@ Seed: ${this.currentMetadata.seed || 'Unknown'}`; } else { hfStatus.innerHTML = ``; } + + // Update model loaded status + if (data.model_loaded && data.loaded_model_type) { + modelLoadedStatus.classList.remove('hidden'); + loadedModelType.textContent = data.loaded_model_type.toUpperCase(); + unloadModelBtn.classList.remove('hidden'); + } else { + modelLoadedStatus.classList.add('hidden'); + unloadModelBtn.classList.add('hidden'); + } } else { ggufStatus.innerHTML = 'Error'; hfStatus.innerHTML = 'Error'; @@ -3670,9 +3703,36 @@ Seed: ${this.currentMetadata.seed || 'Unknown'}`; this.showModal("autoTagModal"); } + async unloadModel() { + const unloadBtn = document.getElementById("unloadModelBtn"); + unloadBtn.disabled = true; + unloadBtn.textContent = 'Unloading...'; + + try { + const response = await fetch('/prompt_manager/autotag/unload', { + method: 'POST' + }); + const data = await response.json(); + + if (data.success) { + this.showNotification(data.message, 'success'); + await this.checkAutoTagModels(); // Refresh status + } else { + this.showNotification(`Failed to unload model: ${data.error}`, 'error'); + } + } catch (error) { + console.error('Error unloading model:', error); + this.showNotification('Failed to unload model', 'error'); + } finally { + unloadBtn.disabled = false; + unloadBtn.textContent = 'Unload Model'; + } + } + async startAutoTag() { const modelType = document.querySelector('input[name="autoTagModel"]:checked').value; const prompt = document.getElementById('autoTagPrompt').value; + const keepInMemory = document.getElementById('keepModelInMemory').checked; // Check if model is downloaded const response = await fetch('/prompt_manager/autotag/models'); @@ -3700,6 +3760,7 @@ Seed: ${this.currentMetadata.seed || 'Unknown'}`; const formData = new URLSearchParams(); formData.append('model_type', modelType); formData.append('prompt', prompt); + formData.append('keep_in_memory', keepInMemory); this.autoTagState.eventSource = new EventSource(`/prompt_manager/autotag/start?${formData.toString()}`);