Skip to content

Commit

Permalink
feat: free model/cache feature on new style menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
ltdrdata committed Jul 7, 2024
1 parent 3e45675 commit 87fc538
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 26 deletions.
2 changes: 1 addition & 1 deletion glob/manager_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import cm_global
from manager_util import *

version = [2, 44, 3]
version = [2, 45]
version_str = f"V{version[0]}.{version[1]}" + (f'.{version[2]}' if len(version) > 2 else '')


Expand Down
67 changes: 54 additions & 13 deletions js/comfyui-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,23 @@ import { SnapshotManager } from "./snapshot.js";

var docStyle = document.createElement('style');
docStyle.innerHTML = `
.comfy-toast {
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
background-color: rgba(0, 0, 0, 0.7);
color: white;
padding: 10px 20px;
border-radius: 5px;
z-index: 1000;
transition: opacity 0.5s;
}
.comfy-toast-fadeout {
opacity: 0;
}
#cm-manager-dialog {
width: 1000px;
height: 520px;
Expand Down Expand Up @@ -1288,18 +1305,43 @@ app.registerExtension({
separator.style.width = "100%";
menu.append(separator);

// new style Manager button
app.menu?.saveButton.element.after(new(await import("../../scripts/ui/components/button.js")).ComfyButton({
icon: "puzzle",
action: () => {
if(!manager_instance)
setManagerInstance(new ManagerMenuDialog());
manager_instance.show();
},
tooltip: "ComfyUI Manager",
content: "ComfyUI Manager",
classList: "comfyui-button comfyui-menu-mobile-collapse primary"
}).element);
try {
// new style Manager button
app.menu?.saveButton.element.after(new(await import("../../scripts/ui/components/button.js")).ComfyButton({
icon: "puzzle",
action: () => {
if(!manager_instance)
setManagerInstance(new ManagerMenuDialog());
manager_instance.show();
},
tooltip: "ComfyUI Manager",
content: "ComfyUI Manager",
classList: "comfyui-button comfyui-menu-mobile-collapse primary"
}).element);

// unload models button into new style Manager button
let cmGroup = new (await import("../../scripts/ui/components/buttonGroup.js")).ComfyButtonGroup(
new(await import("../../scripts/ui/components/button.js")).ComfyButton({
icon: "vacuum-outline",
action: () => {
free_models();
},
tooltip: "Unload Models"
}).element,
new(await import("../../scripts/ui/components/button.js")).ComfyButton({
icon: "vacuum",
action: () => {
free_models(true);
},
tooltip: "Unload Whole Cache"
}).element
);

app.menu?.settingsGroup.element.before(cmGroup.element);
}
catch(exception) {
log.console('ComfyUI is outdated. New style menu based features are disabled.');
}

// old style Manager button
const managerButton = document.createElement("button");
Expand All @@ -1311,7 +1353,6 @@ app.registerExtension({
}
menu.append(managerButton);


const shareButton = document.createElement("button");
shareButton.id = "shareButton";
shareButton.textContent = "Share";
Expand Down
48 changes: 37 additions & 11 deletions js/common.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { app } from "../../scripts/app.js";
import { api } from "../../scripts/api.js";
import { $el, ComfyDialog } from "../../scripts/ui.js";

export function show_message(msg) {
app.ui.dialog.show(msg);
Expand Down Expand Up @@ -30,6 +31,15 @@ export function setManagerInstance(obj) {
manager_instance = obj;
}

export function showToast(message, duration = 3000) {
const toast = $el("div.comfy-toast", {textContent: message});
document.body.appendChild(toast);
setTimeout(() => {
toast.classList.add("comfy-toast-fadeout");
setTimeout(() => toast.remove(), 500);
}, duration);
}

function isValidURL(url) {
if(url.includes('&'))
return false;
Expand Down Expand Up @@ -106,18 +116,34 @@ export async function install_via_git_url(url, manager_dialog) {
}
}

export async function free_models() {
let res = await api.fetchApi(`/free`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: '{"unload_models": true}'
});
export async function free_models(free_execution_cache) {
try {
let mode = "";
if(free_execution_cache) {
mode = '{"unload_models": true, "free_memory": true}';
}
else {
mode = '{"unload_models": true}';
}

if(res.status == 200) {
show_message('Models have been unloaded.')
}
else {
show_message('Unloading of models failed.<BR><BR>Installed ComfyUI may be an outdated version.')
let res = await api.fetchApi(`/free`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: mode
});

if (res.status == 200) {
if(free_execution_cache) {
showToast("'Models' and 'Execution Cache' have been unloaded.", 3000);
}
else {
showToast("Models' have been unloaded.", 3000);
}
} else {
showToast('Unloading of models failed. Installed ComfyUI may be an outdated version.', 5000);
}
} catch (error) {
showToast('An error occurred while trying to unload models.', 5000);
}
}

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "comfyui-manager"
description = "ComfyUI-Manager provides features to install and manage custom nodes for ComfyUI, as well as various functionalities to assist with ComfyUI."
version = "2.44.3"
version = "2.45"
license = "LICENSE"
dependencies = ["GitPython", "PyGithub", "matrix-client==0.4.0", "transformers", "huggingface-hub>0.20", "typer", "rich", "typing-extensions"]

Expand Down

0 comments on commit 87fc538

Please sign in to comment.