From c83fd0ed94b3e9b0c555a4bdf598d5138a6ffa72 Mon Sep 17 00:00:00 2001 From: "dr.lt.data" Date: Fri, 5 Jan 2024 10:51:16 +0900 Subject: [PATCH] feat: unload models --- __init__.py | 2 +- js/comfyui-manager.js | 13 ++-- js/common.js | 158 +++++++++++++++++++++++------------------- 3 files changed, 97 insertions(+), 76 deletions(-) diff --git a/__init__.py b/__init__.py index 31d39d1..b4ff868 100644 --- a/__init__.py +++ b/__init__.py @@ -27,7 +27,7 @@ except: print(f"[WARN] ComfyUI-Manager: Your ComfyUI version is outdated. Please update to the latest version.") -version = [1, 24] +version = [1, 25] version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '') print(f"### Loading: ComfyUI-Manager ({version_str})") diff --git a/js/comfyui-manager.js b/js/comfyui-manager.js index 20ee133..aa4c4e4 100644 --- a/js/comfyui-manager.js +++ b/js/comfyui-manager.js @@ -7,13 +7,13 @@ import { CustomNodesInstaller } from "./custom-nodes-downloader.js"; import { AlternativesInstaller } from "./a1111-alter-downloader.js"; import { SnapshotManager } from "./snapshot.js"; import { ModelInstaller } from "./model-downloader.js"; -import { manager_instance, setManagerInstance, install_via_git_url, install_pip, rebootAPI } from "./common.js"; +import { manager_instance, setManagerInstance, install_via_git_url, install_pip, rebootAPI, free_models } from "./common.js"; var docStyle = document.createElement('style'); docStyle.innerHTML = ` #cm-manager-dialog { width: 1000px; - height: 450px; + height: 460px; box-sizing: content-box; z-index: 10000; } @@ -66,7 +66,7 @@ docStyle.innerHTML = ` .cm-notice-board { width: 310px; padding: 0px !important; - height: 190px; + height: 250px; overflow: auto; color: var(--input-text); border: 1px solid var(--descrip-text); @@ -812,10 +812,15 @@ class ManagerMenuDialog extends ComfyDialog { install_pip(url, self); } } + }), + $el("button.cm-experimental-button", { + type: "button", + textContent: "Unload models", + onclick: () => { free_models(); } }) ]), ]; - } +} createControlsRight() { const elts = [ diff --git a/js/common.js b/js/common.js index 4719517..f118e14 100644 --- a/js/common.js +++ b/js/common.js @@ -2,7 +2,7 @@ import { app } from "../../scripts/app.js"; import { api } from "../../scripts/api.js" export async function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); + return new Promise(resolve => setTimeout(resolve, ms)); } export function rebootAPI() { @@ -21,92 +21,92 @@ export function rebootAPI() { export async function install_checked_custom_node(grid_rows, target_i, caller, mode) { if(caller) { - let failed = ''; - - caller.disableButtons(); - - for(let i in grid_rows) { - if(!grid_rows[i].checkbox.checked && i != target_i) - continue; - - var target; - - if(grid_rows[i].data.custom_node) { - target = grid_rows[i].data.custom_node; - } - else { - target = grid_rows[i].data; - } - - caller.startInstall(target); - - try { - const response = await api.fetchApi(`/customnode/${mode}`, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify(target) - }); - - if(response.status == 400) { - app.ui.dialog.show(`${mode} failed: ${target.title}`); - app.ui.dialog.element.style.zIndex = 10010; - continue; - } - - const status = await response.json(); - app.ui.dialog.close(); - target.installed = 'True'; - continue; - } - catch(exception) { - failed += `
${target.title}`; - } + let failed = ''; + + caller.disableButtons(); + + for(let i in grid_rows) { + if(!grid_rows[i].checkbox.checked && i != target_i) + continue; + + var target; + + if(grid_rows[i].data.custom_node) { + target = grid_rows[i].data.custom_node; + } + else { + target = grid_rows[i].data; + } + + caller.startInstall(target); + + try { + const response = await api.fetchApi(`/customnode/${mode}`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(target) + }); + + if(response.status == 400) { + app.ui.dialog.show(`${mode} failed: ${target.title}`); + app.ui.dialog.element.style.zIndex = 10010; + continue; + } + + const status = await response.json(); + app.ui.dialog.close(); + target.installed = 'True'; + continue; + } + catch(exception) { + failed += `
${target.title}`; + } } if(failed != '') { - app.ui.dialog.show(`${mode} failed: ${failed}`); - app.ui.dialog.element.style.zIndex = 10010; + app.ui.dialog.show(`${mode} failed: ${failed}`); + app.ui.dialog.element.style.zIndex = 10010; } - await caller.invalidateControl(); - caller.updateMessage("
To apply the installed/updated/disabled/enabled custom node, please ComfyUI. And refresh browser.", 'cm-reboot-button'); + await caller.invalidateControl(); + caller.updateMessage("
To apply the installed/updated/disabled/enabled custom node, please ComfyUI. And refresh browser.", 'cm-reboot-button'); } }; export var manager_instance = null; export function setManagerInstance(obj) { - manager_instance = obj; + manager_instance = obj; } function isValidURL(url) { if(url.includes('&')) return false; - const pattern = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/; - return pattern.test(url); + const pattern = /^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/; + return pattern.test(url); } export async function install_pip(packages) { if(packages.includes('&')) - app.ui.dialog.show(`Invalid PIP package enumeration: '${packages}'`); + app.ui.dialog.show(`Invalid PIP package enumeration: '${packages}'`); - const res = await api.fetchApi(`/customnode/install/pip?packages=${packages}`); + const res = await api.fetchApi(`/customnode/install/pip?packages=${packages}`); - if(res.status == 200) { - app.ui.dialog.show(`PIP package installation is processed.
To apply the pip packages, please click the button in ComfyUI.`); + if(res.status == 200) { + app.ui.dialog.show(`PIP package installation is processed.
To apply the pip packages, please click the button in ComfyUI.`); const rebootButton = document.getElementById('cm-reboot-button'); const self = this; rebootButton.addEventListener("click", rebootAPI); - app.ui.dialog.element.style.zIndex = 10010; - } - else { - app.ui.dialog.show(`Failed to install '${packages}'
See terminal log.`); - app.ui.dialog.element.style.zIndex = 10010; - } + app.ui.dialog.element.style.zIndex = 10010; + } + else { + app.ui.dialog.show(`Failed to install '${packages}'
See terminal log.`); + app.ui.dialog.element.style.zIndex = 10010; + } } export async function install_via_git_url(url, manager_dialog) { @@ -115,18 +115,18 @@ export async function install_via_git_url(url, manager_dialog) { } if(!isValidURL(url)) { - app.ui.dialog.show(`Invalid Git url '${url}'`); - app.ui.dialog.element.style.zIndex = 10010; + app.ui.dialog.show(`Invalid Git url '${url}'`); + app.ui.dialog.element.style.zIndex = 10010; return; } - app.ui.dialog.show(`Wait...

Installing '${url}'`); - app.ui.dialog.element.style.zIndex = 10010; + app.ui.dialog.show(`Wait...

Installing '${url}'`); + app.ui.dialog.element.style.zIndex = 10010; - const res = await api.fetchApi(`/customnode/install/git_url?url=${url}`); + const res = await api.fetchApi(`/customnode/install/git_url?url=${url}`); - if(res.status == 200) { - app.ui.dialog.show(`'${url}' is installed
To apply the installed custom node, please ComfyUI.`); + if(res.status == 200) { + app.ui.dialog.show(`'${url}' is installed
To apply the installed custom node, please ComfyUI.`); const rebootButton = document.getElementById('cm-reboot-button'); const self = this; @@ -138,10 +138,26 @@ export async function install_via_git_url(url, manager_dialog) { } }); - app.ui.dialog.element.style.zIndex = 10010; - } - else { - app.ui.dialog.show(`Failed to install '${url}'
See terminal log.`); - app.ui.dialog.element.style.zIndex = 10010; - } + app.ui.dialog.element.style.zIndex = 10010; + } + else { + app.ui.dialog.show(`Failed to install '${url}'
See terminal log.`); + app.ui.dialog.element.style.zIndex = 10010; + } +} + +export async function free_models() { + let res = await api.fetchApi(`/free`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: '{}' + }); + + if(res.status == 200) { + app.ui.dialog.show('Models have been unloaded.') + } + else { + app.ui.dialog.show('Unloading of models failed.

Installed ComfyUI may be an outdated version.') + } + app.ui.dialog.element.style.zIndex = 10010; } \ No newline at end of file