From 224337bc8bd15edb6462cfffb7ee61eda49094fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20=20Sk=C3=B6ld?= Date: Wed, 26 Jun 2024 03:11:23 +0200 Subject: [PATCH] try to fix simple sampler api problems --- sn0w.py | 11 +++++++--- src/character_select.py | 1 + src/check_folder_paths.py | 1 - src/simple_sampler_custom.py | 2 ++ web/js/simpleSamplerCustom.js | 39 +++++++++++++++++++++-------------- web/js/sn0w.js | 2 +- 6 files changed, 36 insertions(+), 20 deletions(-) diff --git a/sn0w.py b/sn0w.py index d36e984..34b4152 100644 --- a/sn0w.py +++ b/sn0w.py @@ -219,15 +219,18 @@ class AnyType(str): class MessageHolder: messages = {} routes = PromptServer.instance.routes - API_PREFIX = '/sn0w' + API_PREFIX = '/api/sn0w' + logger = Logger() @classmethod def addMessage(self, id, message): + self.logger.log(f"Added message: {message}", "DEBUG") self.messages[str(id)] = message @classmethod def waitForMessage(self, id, period = 0.1): sid = str(id) + self.logger.log(f"Id: {sid} waiting for message", "DEBUG") while not (sid in self.messages): time.sleep(period) @@ -252,8 +255,9 @@ async def handle_update_sorting(request): @routes.post(f'{API_PREFIX}/widget_values') async def handle_widget_values(request): data = await request.json() + print(data) MessageHolder.addMessage(data.get("node_id"), data.get("outputs")) - return web.json_response({"status": "ok"}) + return web.json_response({"status": "ok"}, {"data": data}) @routes.post(f'{API_PREFIX}/should_decode_image') async def handle_should_decode_image(request): @@ -265,4 +269,5 @@ async def handle_should_decode_image(request): async def handle_get_sigmas(request): data = await request.json() MessageHolder.addMessage(data.get("node_id"), data.get("outputs")) - return web.json_response({"status": "ok"}) \ No newline at end of file + return web.json_response({"status": "ok"}) + \ No newline at end of file diff --git a/src/character_select.py b/src/character_select.py index c1eab1e..6f95555 100644 --- a/src/character_select.py +++ b/src/character_select.py @@ -12,6 +12,7 @@ API_PREFIX = MessageHolder.API_PREFIX @routes.post(f'{API_PREFIX}/update_characters') async def handle_update_characters(request): + print("RECIEVED API REQUEST") CharacterSelectNode.initialize() return web.json_response({"status": "ok"}) diff --git a/src/check_folder_paths.py b/src/check_folder_paths.py index 576cde1..17621e0 100644 --- a/src/check_folder_paths.py +++ b/src/check_folder_paths.py @@ -24,7 +24,6 @@ def check_lora_folders(): except Exception as e: logger.log(f"{path} doesn't exist: {e}", "WARNING") - print(existing_paths) # Write the result to a JSON file in /web/settings data = {"loaders_enabled": existing_paths} with open(json_path, "w") as json_file: diff --git a/src/simple_sampler_custom.py b/src/simple_sampler_custom.py index 69587fb..c851a92 100644 --- a/src/simple_sampler_custom.py +++ b/src/simple_sampler_custom.py @@ -118,7 +118,9 @@ class SimpleSamplerCustom: "id": unique_id, "widgets_needed": widgets_needed, }) + self.logger.log(f"WAITING FOR SIGMAS", "DEBUG") outputs = MessageHolder.waitForMessage(unique_id) + self.logger.log(f"GOT SIGMAS: {outputs}", "DEBUG") return outputs def get_denoised_sigmas(self, sigmas, denoise): diff --git a/web/js/simpleSamplerCustom.js b/web/js/simpleSamplerCustom.js index 7964d64..2b24442 100644 --- a/web/js/simpleSamplerCustom.js +++ b/web/js/simpleSamplerCustom.js @@ -7,36 +7,36 @@ import { ComfyWidgets } from "../../../scripts/widgets.js"; app.registerExtension({ name: "sn0w.SimpleSamplerCustom", async beforeRegisterNodeDef(nodeType, nodeData, app) { - const allSettings = new Set(); - if (nodeData.name === "Simple Sampler Custom") { + const allSettings = new Set(); + console.log(nodeType.prototype) // Set positive and negative connection colors const onConnectInput = nodeType.prototype.onConnectInput; nodeType.prototype.onConnectInput = function (targetSlot, type, output, originNode, originSlot) { const slot = type[0] const inputType = type[1] - const initialCount = countWidgetsOfType(targetSlot.widgets, "converted-widget"); - const originalSize = [targetSlot.size[0], targetSlot.size[1]]; + const initialCount = countWidgetsOfType(this.widgets, "converted-widget"); + const originalSize = [this.size[0], this.size[1]]; if (slot === 3 || slot === 4) { if (inputType == "STRING" || inputType == "CONDITIONING") { - targetSlot.inputs[slot].color_on = app.canvas.default_connection_color_byType[inputType]; + this.inputs[slot].color_on = app.canvas.default_connection_color_byType[inputType]; } else { console.error(`The input type has to be STRING or CONDITIONING, it cannot be ${inputType}.`) - targetSlot.inputs[slot].color_on = app.canvas.default_connection_color_byType["VAE"]; + this.inputs[slot].color_on = app.canvas.default_connection_color_byType["VAE"]; } } else if (slot === 5) { - hideAllSchedulerWidgets(targetSlot); - SettingUtils.hideWidget(targetSlot, findWidget(targetSlot, "scheduler_name")); + hideAllSchedulerWidgets(this); + SettingUtils.hideWidget(this, findWidget(this, "scheduler_name")); - resizeNode(targetSlot, initialCount, originalSize); + resizeNode(this, initialCount, originalSize); } else if (slot === 6) { - hideAllLatentWidgets(targetSlot); - resizeNode(targetSlot, initialCount, originalSize); + hideAllLatentWidgets(this); + resizeNode(this, initialCount, originalSize); } - onConnectInput?.apply(targetSlot, type, output, originNode, originSlot); + onConnectInput?.apply(this, type, output, originNode, originSlot); } // Handle when connection is disconnected @@ -88,7 +88,12 @@ app.registerExtension({ const data = event.detail const output = getWidgetOutputs(this, data.widgets_needed); if (this.id == data.id) { - api.fetchApi(`${SettingUtils.API_PREFIX}/widget_values`, { + console.log(JSON.stringify( + { + node_id: data.id, + outputs: output, + })) + const apiRequest = api.fetchApi(`${SettingUtils.API_PREFIX}/widget_values`, { method: "POST", headers: { "Content-Type": "application/json", @@ -100,6 +105,7 @@ app.registerExtension({ } ), }) + console.log(apiRequest) } }) @@ -151,7 +157,6 @@ app.registerExtension({ const desiredWidgets = widgets[inputName.value] ? Object.keys(widgets[inputName.value]) : []; showSchedulerInputs(this, inputName, desiredWidgets); - if (this.inputs[5].link !== null) { hideAllSchedulerWidgets(this); SettingUtils.hideWidget(this, findWidget(this, "scheduler_name")); @@ -167,8 +172,12 @@ app.registerExtension({ } function countWidgetsOfType(widgets, type) { + if (!Array.isArray(widgets)) { + console.error('Invalid widgets parameter:', widgets); + return 0; // or handle the error as needed + } return widgets.filter(widget => widget.type === type).length; - } + } function resizeNode(node, initialCount, originalSize) { const finalCount = countWidgetsOfType(node.widgets, "converted-widget"); diff --git a/web/js/sn0w.js b/web/js/sn0w.js index 8f6c8d7..103caff 100644 --- a/web/js/sn0w.js +++ b/web/js/sn0w.js @@ -1,7 +1,7 @@ import { api } from '../../../scripts/api.js'; export class SettingUtils { - static API_PREFIX = '/sn0w'; + static API_PREFIX = '/api/sn0w'; // SETTINGS static async getSetting(url) {