Skip to content

Commit

Permalink
Revert "Merge pull request #28 from TNG/feature/restartComfyUIAfterCu…
Browse files Browse the repository at this point in the history
…stomNodeInstallation"

This reverts commit fcae45c, reversing
changes made to d3eb229.
  • Loading branch information
florianesser-tng committed Dec 17, 2024
1 parent 1616b40 commit 57113c5
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 47 deletions.
72 changes: 40 additions & 32 deletions WebUI/src/assets/js/store/comfyUi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,38 +33,27 @@ export const useComfyUi = defineStore("comfyUi", () => {
{ immediate: true }
);

async function installCustomNodesForActiveWorkflow() {
const uniqueCustomNodes = new Set(imageGeneration.workflows.filter(w => w.name === imageGeneration.activeWorkflowName).filter(w => w.backend === 'comfyui').flatMap((item) => item.comfyUIRequirements.customNodes))
const requiredCustomNodes: ComfyUICustomNodesRequestParameters[] =
[...uniqueCustomNodes].map((nodeName) => {
const [username, repoName] = nodeName.replace(" ", "").split("/")
return {username, repoName}
})
const response = await fetch(`${globalSetup.apiHost}/api/comfyUi/loadCustomNodes`, {
method: 'POST',
body: JSON.stringify({data: requiredCustomNodes}),
headers: {
"Content-Type": "application/json"
}
})
if (response.status !== 200) {
throw new Error("Request Failure to install required comfyUINode");
}
const data = await response.json() as { node: string, success: boolean }[];
const notInstalledNodes = data.filter(item => {!item.success})
if (notInstalledNodes.length > 0) {
throw new Error(`Failed to install required comfyUI custom nodes: ${notInstalledNodes}`)
}
if (data.length > 0) {
console.info("restarting comfyUI to finalize installation of required custom nodes")
await backendServices.stopService('comfyui-backend')
const startingResult = await backendServices.startService('comfyui-backend')
if (startingResult !== "running") {
throw new Error("Failed to restart comfyUI. Required Nodes are not active.")
}
console.info("restart complete")
async function triggerInstallCustomNodesForActiveWorkflow() {
const uniqueCustomNodes = new Set(imageGeneration.workflows.filter(w => w.name === imageGeneration.activeWorkflowName).filter(w => w.backend === 'comfyui').flatMap((item) => item.comfyUIRequirements.customNodes))
const toBeInstalledCustomNodes: ComfyUICustomNodesRequestParameters[] =
[...uniqueCustomNodes].map((nodeName) => {
const [username, repoName] = nodeName.replace(" ", "").split("/")
return {username, repoName}
})
console.info("Installing custom nodes", { toBeInstalledCustomNodes })
const response = await fetch(`${globalSetup.apiHost}/api/comfyUi/loadCustomNodes`, {
method: 'POST',
body: JSON.stringify({data: toBeInstalledCustomNodes}),
headers: {
"Content-Type": "application/json"
}
})
if (response.status === 200) {
console.info("custom node installation completed")
return;
}
const data = await response.json();
throw new Error(data.error_message);
}

function connectToComfyUi() {
Expand Down Expand Up @@ -226,9 +215,9 @@ export const useComfyUi = defineStore("comfyUi", () => {
return;
}

try {
await installCustomNodesForActiveWorkflow()
await triggerInstallCustomNodesForActiveWorkflow()

try {
const mutableWorkflow: ComfyUIApiWorkflow = JSON.parse(JSON.stringify(imageGeneration.activeWorkflow.comfyUiApiWorkflow))
const seed = imageGeneration.seed === -1 ? (Math.random() * 1000000) : imageGeneration.seed;

Expand Down Expand Up @@ -288,9 +277,28 @@ export const useComfyUi = defineStore("comfyUi", () => {
})
}

async function free() {
if (!isComfyRunning) {
console.debug('ComfyUI backend not running, nothing to free');
return;
}
await fetch(`${comfyBaseUrl.value}/free`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ free_memory: true,
unload_models: true })
})
await fetch(`${useGlobalSetup().apiHost}/api/triggerxpucacheclear`, {
method: "POST"
})
}

return {
generate,
stop,
free
}
}, {
persist: {
Expand Down
6 changes: 4 additions & 2 deletions WebUI/src/assets/js/store/imageGeneration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,13 +618,15 @@ export const useImageGeneration = defineStore("imageGeneration", () => {
previewIdx.value = 0;
stepText.value = i18nState.COM_GENERATING;
if (activeWorkflow.value.backend === 'default') {
comfyUi.free();
stableDiffusion.generate();
} else {
stableDiffusion.free();
comfyUi.generate();
}
}

function stopGeneration() {
function stop() {
stableDiffusion.stop();
comfyUi.stop();
}
Expand Down Expand Up @@ -675,7 +677,7 @@ export const useImageGeneration = defineStore("imageGeneration", () => {
getMissingModels,
updateDestImage,
generate,
stopGeneration,
stop,
reset
}
}, {
Expand Down
8 changes: 7 additions & 1 deletion WebUI/src/assets/js/store/stableDiffusion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,18 @@ export const useStableDiffusion = defineStore("stableDiffusion", () => {
}
}

async function free() {
await fetch(`${useGlobalSetup().apiHost}/api/free`, {
method: "POST"
})
}

return {
generateParams,
generate,
stop,
free,
}

}, {
persist: {
pick: ['settings', 'hdWarningDismissed']
Expand Down
1 change: 0 additions & 1 deletion WebUI/src/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ type ApiResponse = {
message: string;
};


type KVObject = {
[key: string]: any;
};
Expand Down
2 changes: 1 addition & 1 deletion WebUI/src/views/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<span>{{ languages.COM_GENERATE }}</span>
</button>
<button class="gernate-btn self-stretch flex flex-col w-32 flex-none" v-show="imageGeneration.processing"
@click="imageGeneration.stopGeneration">
@click="imageGeneration.stop">
<span class="svg-icon w-7 h-7" :class="{ 'i-stop': !imageGeneration.stopping, 'i-loading': imageGeneration.stopping }"></span>
<span>{{ languages.COM_STOP }}</span>
</button>
Expand Down
9 changes: 4 additions & 5 deletions service/comfyui_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def is_custom_node_installed(node_repo_ref: ComfyUICustomNodesGithubRepoId) -> b
expected_custom_node_path = os.path.join(service_config.comfy_ui_root_path, "custom_nodes", node_repo_ref.repoName)
return os.path.exists(expected_custom_node_path)

def download_custom_node(node_repo_data: ComfyUICustomNodesGithubRepoId) -> bool:
def download_custom_node(node_repo_data: ComfyUICustomNodesGithubRepoId):
if is_custom_node_installed(node_repo_data):
return True
return
else:
try:
expected_git_url = f"https://github.com/{node_repo_data.username}/{node_repo_data.repoName}"
Expand All @@ -128,8 +128,7 @@ def download_custom_node(node_repo_data: ComfyUICustomNodesGithubRepoId) -> bool

_install_git_repo(expected_git_url, expected_custom_node_path)
_install_pip_requirements(potential_node_requirements)
logging.info("installed on a mock basis")
return True
return
except Exception as e:
logging.error(f"Failed to install custom comfy node {node_repo_data.username}/{node_repo_data.repoName} due to {e}")
return False
raise e
22 changes: 17 additions & 5 deletions service/web_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ def llm_chat():
return Response(stream_with_context(it), content_type="text/event-stream")


@app.post("/api/triggerxpucacheclear")
def trigger_xpu_cache_clear():
paint_biz.clear_xpu_cache()
return Response("{'message':'triggered xpu cache clearance'}", status=201, mimetype='application/json')


@app.post("/api/free")
def free():
paint_biz.dispose()
import llm_biz
llm_biz.dispose()
return jsonify({"code": 0, "message": "success"})

@app.get("/api/llm/stopGenerate")
def stop_llm_generate():
import llm_biz
Expand Down Expand Up @@ -395,12 +408,11 @@ def are_custom_nodes_installed(comfyNodeRequest: ComfyUICustomNodesDownloadReque
@app.input(ComfyUICustomNodesDownloadRequest.Schema, location='json', arg_name='comfyNodeRequest')
def install_custom_nodes(comfyNodeRequest: ComfyUICustomNodesDownloadRequest):
try:
nodes_to_be_installed = [x for x in comfyNodeRequest.data if not comfyui_downloader.is_custom_node_installed(x)]
installation_result = [ {"node": f"{x.username}/{x.repoName}", "success": comfyui_downloader.download_custom_node(x)} for x in nodes_to_be_installed ]
logging.info(f"custom node installation request result: {installation_result}")
return jsonify(installation_result)
for x in comfyNodeRequest.data:
comfyui_downloader.download_custom_node(x)
return jsonify({ f"{x.username}/{x.repoName}" : {"success": True, "errorMessage": ""} for x in comfyNodeRequest.data})
except Exception as e:
return jsonify({'error_message': f'failed to install at least one custom node due to {e}'}), 501
return jsonify({'error_message': f'failed to at least one custom node due to {e}'}), 501



Expand Down

0 comments on commit 57113c5

Please sign in to comment.