mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-05-15 03:27:24 +08:00
Improvement to range widgets
This commit is contained in:
parent
864b439819
commit
065e2a7e28
39
execution.py
39
execution.py
@ -35,12 +35,7 @@ def get_input_data_batches(input_data_all):
|
|||||||
|
|
||||||
batches = []
|
batches = []
|
||||||
|
|
||||||
print("GET" + str(input_data_all))
|
|
||||||
print("ALL " + str(index_to_values))
|
|
||||||
print("INPS " + str(input_to_index))
|
|
||||||
|
|
||||||
for combination in list(itertools.product(*index_to_values)):
|
for combination in list(itertools.product(*index_to_values)):
|
||||||
print("COMBO " + str(combination))
|
|
||||||
batch = {}
|
batch = {}
|
||||||
for input_name, value in input_data_all.items():
|
for input_name, value in input_data_all.items():
|
||||||
if isinstance(value, dict) and "combinatorial" in value:
|
if isinstance(value, dict) and "combinatorial" in value:
|
||||||
@ -102,7 +97,6 @@ def get_input_data(inputs, class_def, unique_id, outputs={}, prompt={}, extra_da
|
|||||||
input_data_all[x] = [extra_data['extra_pnginfo']]
|
input_data_all[x] = [extra_data['extra_pnginfo']]
|
||||||
if h[x] == "UNIQUE_ID":
|
if h[x] == "UNIQUE_ID":
|
||||||
input_data_all[x] = [unique_id]
|
input_data_all[x] = [unique_id]
|
||||||
print("=== GetInputData: " + str(inputs))
|
|
||||||
|
|
||||||
input_data_all_batches = get_input_data_batches(input_data_all)
|
input_data_all_batches = get_input_data_batches(input_data_all)
|
||||||
|
|
||||||
@ -139,11 +133,7 @@ def map_node_over_list(obj, input_data_all, func, allow_interrupt=False):
|
|||||||
s.append(st)
|
s.append(st)
|
||||||
return "( " + ", ".join(s) + " )"
|
return "( " + ", ".join(s) + " )"
|
||||||
|
|
||||||
print("+++ Obj: " + str(obj))
|
|
||||||
print("+++ Inputs: " + format_dict(input_data_all))
|
|
||||||
max_len_input = max(len(x) for x in input_data_all.values())
|
max_len_input = max(len(x) for x in input_data_all.values())
|
||||||
print("MaxLen " + str(max_len_input))
|
|
||||||
print("0 " + str(slice_lists_into_dict(input_data_all, 0)))
|
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
if inputs_are_lists:
|
if inputs_are_lists:
|
||||||
@ -161,10 +151,8 @@ def get_output_data(obj, input_data_all_batches, server, unique_id, prompt_id):
|
|||||||
all_outputs = []
|
all_outputs = []
|
||||||
all_outputs_ui = []
|
all_outputs_ui = []
|
||||||
total_batches = len(input_data_all_batches)
|
total_batches = len(input_data_all_batches)
|
||||||
print("TOTAL: " + str(total_batches))
|
|
||||||
|
|
||||||
for i, batch in enumerate(input_data_all_batches):
|
for batch_num, batch in enumerate(input_data_all_batches):
|
||||||
print("***** BATCH: " + str(i))
|
|
||||||
return_values = map_node_over_list(obj, batch, obj.FUNCTION, allow_interrupt=True)
|
return_values = map_node_over_list(obj, batch, obj.FUNCTION, allow_interrupt=True)
|
||||||
|
|
||||||
uis = []
|
uis = []
|
||||||
@ -193,21 +181,20 @@ def get_output_data(obj, input_data_all_batches, server, unique_id, prompt_id):
|
|||||||
else:
|
else:
|
||||||
output.append([o[i] for o in results])
|
output.append([o[i] for o in results])
|
||||||
|
|
||||||
output_ui = dict()
|
output_ui = None
|
||||||
if len(uis) > 0:
|
if len(uis) > 0:
|
||||||
output_ui = {k: [y for x in uis for y in x[k]] for k in uis[0].keys()}
|
output_ui = {k: [y for x in uis for y in x[k]] for k in uis[0].keys()}
|
||||||
|
|
||||||
# update the UI after each batch finishes
|
# update the UI after each batch finishes
|
||||||
if len(output_ui) > 0:
|
if server.client_id is not None:
|
||||||
if server.client_id is not None:
|
message = {
|
||||||
message = {
|
"node": unique_id,
|
||||||
"node": unique_id,
|
"output": output_ui,
|
||||||
"output": output_ui,
|
"prompt_id": prompt_id,
|
||||||
"prompt_id": prompt_id,
|
"batch_num": batch_num,
|
||||||
"batch": i,
|
"total_batches": total_batches
|
||||||
"total_batches": total_batches
|
}
|
||||||
}
|
server.send_sync("executed", message, server.client_id)
|
||||||
server.send_sync("executed", message, server.client_id)
|
|
||||||
|
|
||||||
all_outputs.append(output)
|
all_outputs.append(output)
|
||||||
all_outputs_ui.append(output_ui)
|
all_outputs_ui.append(output_ui)
|
||||||
@ -234,7 +221,7 @@ def recursive_execute(server, prompt, outputs, current_item, extra_data, execute
|
|||||||
input_data_all_batches = get_input_data(inputs, class_def, unique_id, outputs, prompt, extra_data)
|
input_data_all_batches = get_input_data(inputs, class_def, unique_id, outputs, prompt, extra_data)
|
||||||
if server.client_id is not None:
|
if server.client_id is not None:
|
||||||
server.last_node_id = unique_id
|
server.last_node_id = unique_id
|
||||||
server.send_sync("executing", { "node": unique_id, "prompt_id": prompt_id }, server.client_id)
|
server.send_sync("executing", { "node": unique_id, "prompt_id": prompt_id, "total_batches": len(input_data_all_batches) }, server.client_id)
|
||||||
obj = class_def()
|
obj = class_def()
|
||||||
|
|
||||||
output_data_from_batches, output_ui_from_batches = get_output_data(obj, input_data_all_batches, server, unique_id, prompt_id)
|
output_data_from_batches, output_ui_from_batches = get_output_data(obj, input_data_all_batches, server, unique_id, prompt_id)
|
||||||
@ -413,6 +400,8 @@ def get_raw_inputs(raw_val):
|
|||||||
|
|
||||||
def clamp_input(val, info, class_type, obj_class, x):
|
def clamp_input(val, info, class_type, obj_class, x):
|
||||||
if is_combinatorial_input(val):
|
if is_combinatorial_input(val):
|
||||||
|
if len(val["values"]) == 0:
|
||||||
|
return (False, "Combinatorial input has no values in its list. {}, {}".format(class_type, x))
|
||||||
for i, val_choice in enumerate(val["values"]):
|
for i, val_choice in enumerate(val["values"]):
|
||||||
r = clamp_input(val_choice, info, class_type, obj_class, x)
|
r = clamp_input(val_choice, info, class_type, obj_class, x)
|
||||||
if r[0] == False:
|
if r[0] == False:
|
||||||
|
|||||||
@ -196,19 +196,17 @@ app.registerExtension({
|
|||||||
this.serialize_widgets = true;
|
this.serialize_widgets = true;
|
||||||
this.isVirtualNode = true;
|
this.isVirtualNode = true;
|
||||||
this.properties ||= {}
|
this.properties ||= {}
|
||||||
this.properties.isRange = false;
|
this.properties.enableRange = false;
|
||||||
this.properties.rangeMin = 0;
|
this.properties.rangeStepBy = 64;
|
||||||
this.properties.rangeMax = 1024;
|
|
||||||
this.properties.rangeSteps = 2;
|
this.properties.rangeSteps = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
getRange(min, max, steps) {
|
getRange(min, stepBy, steps) {
|
||||||
const range = [];
|
let result = [];
|
||||||
const stepSize = (max - min) / (steps - 1);
|
|
||||||
for (let i = 0; i < steps; i++) {
|
for (let i = 0; i < steps; i++) {
|
||||||
range.push(Math.round((min + i * stepSize) * 100) / 100);
|
result.push(min + i * stepBy);
|
||||||
}
|
}
|
||||||
return range;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
applyToGraph() {
|
applyToGraph() {
|
||||||
@ -227,8 +225,9 @@ app.registerExtension({
|
|||||||
if (widget.callback) {
|
if (widget.callback) {
|
||||||
widget.callback(widget.value, app.canvas, node, app.canvas.graph_mouse, {});
|
widget.callback(widget.value, app.canvas, node, app.canvas.graph_mouse, {});
|
||||||
}
|
}
|
||||||
if (widget.type === "number" && this.properties.isRange) {
|
const isNumberWidget = widget.type === "number" || widget.origType === "number";
|
||||||
const values = this.getRange(this.properties.rangeMin, this.properties.rangeMax, this.properties.rangeSteps);
|
if (isNumberWidget && this.properties.enableRange) {
|
||||||
|
const values = this.getRange(widget.value, this.properties.rangeStepBy, this.properties.rangeSteps);
|
||||||
widget.value = { __inputType__: "combinatorial", values: values }
|
widget.value = { __inputType__: "combinatorial", values: values }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -297,6 +296,15 @@ app.registerExtension({
|
|||||||
this.#createWidget(widget.config, theirNode, widget.name);
|
this.#createWidget(widget.config, theirNode, widget.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onPropertyChanged(property, value) {
|
||||||
|
if (property === "enableRange") {
|
||||||
|
if (this.stepByWidget)
|
||||||
|
this.stepByWidget.disabled = !value
|
||||||
|
if (this.stepsWidget)
|
||||||
|
this.stepsWidget.disabled = !value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#createWidget(inputData, node, widgetName) {
|
#createWidget(inputData, node, widgetName) {
|
||||||
let type = inputData[0];
|
let type = inputData[0];
|
||||||
|
|
||||||
@ -320,10 +328,11 @@ app.registerExtension({
|
|||||||
|
|
||||||
if (widget.type === "number") {
|
if (widget.type === "number") {
|
||||||
addValueControlWidget(this, widget, "fixed");
|
addValueControlWidget(this, widget, "fixed");
|
||||||
this.addWidget("toggle", "Enable Range", this.properties.isRange, "isRange");
|
this.addWidget("toggle", "Enable Range", this.properties.enableRange, "enableRange");
|
||||||
this.addWidget("number", "Range Min.", this.properties.rangeMin, "rangeMin");
|
this.stepByWidget = this.addWidget("number", "Range Step By", this.properties.rangeStepBy, "rangeStepBy");
|
||||||
this.addWidget("number", "Range Max.", this.properties.rangeMax, "rangeMax");
|
this.stepByWidget.disabled = !this.properties.enableRange;
|
||||||
this.addWidget("number", "Range Steps", this.properties.rangeSteps, "rangeSteps", { min: 1, max: 128, step: 10 });
|
this.stepsWidget = this.addWidget("number", "Range Steps", this.properties.rangeSteps, "rangeSteps", { min: 1, max: 128, step: 10 });
|
||||||
|
this.stepsWidget.disabled = !this.properties.enableRange;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When our value changes, update other widgets to reflect our changes
|
// When our value changes, update other widgets to reflect our changes
|
||||||
|
|||||||
@ -1266,7 +1266,8 @@ export class ComfyApp {
|
|||||||
|
|
||||||
for (let i = 0; i < batchCount; i++) {
|
for (let i = 0; i < batchCount; i++) {
|
||||||
const result = await this.graphToPrompt();
|
const result = await this.graphToPrompt();
|
||||||
if (result.totalExecuted > 128 && !confirm("You are about to execute " + result.totalExecuted + " nodes total across " + result.totalCombinatorialNodes + " combinatorial axes. Are you sure you want to do this?")) {
|
const warnExecutedAmount = 256;
|
||||||
|
if (result.totalExecuted > warnExecutedAmount && !confirm("You are about to execute " + result.totalExecuted + " nodes total across " + result.totalCombinatorialNodes + " combinatorial axes. Are you sure you want to do this?")) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const p = result.prompt;
|
const p = result.prompt;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user