try to fix simple sampler api problems

This commit is contained in:
Lucas Sköld
2024-06-26 03:11:23 +02:00
parent 4ffd42385f
commit 224337bc8b
6 changed files with 36 additions and 20 deletions
+8 -3
View File
@@ -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"})
return web.json_response({"status": "ok"})
+1
View File
@@ -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"})
-1
View File
@@ -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:
+2
View File
@@ -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):
+24 -15
View File
@@ -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");
+1 -1
View File
@@ -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) {