Skip to content

Commit

Permalink
FIXED: front compatibility fix
Browse files Browse the repository at this point in the history
- selectors of wildcards, lbw, promptbuilder
  • Loading branch information
ltdrdata committed Nov 30, 2024
1 parent 18f02d9 commit 8db9411
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 163 deletions.
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import importlib

version_code = [1, 7]
version_code = [1, 8]
version_str = f"V{version_code[0]}.{version_code[1]}" + (f'.{version_code[2]}' if len(version_code) > 2 else '')
print(f"### Loading: ComfyUI-Inspire-Pack ({version_str})")

Expand Down
168 changes: 83 additions & 85 deletions js/lora_block_weight.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,17 @@ app.registerExtension({

node._value = "Preset";

node.widgets[preset_i].callback = (v, canvas, node, pos, e) => {
node.widgets[vector_i].value = node._value.split(':')[1];
if(node.widgets_values) {
node.widgets_values[vector_i] = node.widgets[preset_i].value;
}
}

Object.defineProperty(node.widgets[preset_i], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(value != "Preset") {
node.widgets[vector_i].value = value.split(':')[1];
if(node.widgets_values) {
node.widgets_values[vector_i] = node.widgets[preset_i].value;
}
}
}

node._value = value;
if(value != "Preset")
node._value = value;
},
get: () => {
return node._value;
Expand Down Expand Up @@ -77,86 +75,86 @@ app.registerExtension({
let preset_i = 9;
let vector_i = 10;
node._value = "Preset";
Object.defineProperty(node.widgets[preset_i], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(value != "Preset") {
if(!value.startsWith('@') && node.widgets[vector_i].value != "")
node.widgets[vector_i].value += "\n";
if(value.startsWith('@')) {
let spec = value.split(':')[1];
var n;
var sub_n = null;
var block = null;

if(isNaN(spec)) {
let sub_spec = spec.split(',');

if(sub_spec.length != 3) {
node.widgets_values[vector_i] = '!! SPEC ERROR !!';
node._value = '';
return;
}

n = parseInt(sub_spec[0].trim());
sub_n = parseInt(sub_spec[1].trim());
block = parseInt(sub_spec[2].trim());
}
else {
n = parseInt(spec.trim());
}

node.widgets[vector_i].value = "";
if(sub_n == null) {
for(let i=1; i<=n; i++) {
var temp = "";
for(let j=1; j<=n; j++) {
if(temp!='')
temp += ',';
if(j==i)
temp += 'A';
else
temp += '0';
}

node.widgets[vector_i].value += `B${i}:${temp}\n`;
}
}
else {
for(let i=1; i<=sub_n; i++) {
var temp = "";
for(let j=1; j<=n; j++) {
if(temp!='')
temp += ',';

if(block!=j)
temp += '0';
else {
temp += ' ';
for(let k=1; k<=sub_n; k++) {
if(k==i)
temp += 'A ';
else
temp += '0 ';
}
}
}

node.widgets[vector_i].value += `B${block}.SUB${i}:${temp}\n`;
}
}
}
node.widgets[preset_i].callback = (v, canvas, node, pos, e) => {
let value = node._value;
if(!value.startsWith('@') && node.widgets[vector_i].value != "")
node.widgets[vector_i].value += "\n";
if(value.startsWith('@')) {
let spec = value.split(':')[1];
var n;
var sub_n = null;
var block = null;

if(isNaN(spec)) {
let sub_spec = spec.split(',');

if(sub_spec.length != 3) {
node.widgets_values[vector_i] = '!! SPEC ERROR !!';
node._value = '';
return;
}

n = parseInt(sub_spec[0].trim());
sub_n = parseInt(sub_spec[1].trim());
block = parseInt(sub_spec[2].trim());
}
else {
n = parseInt(spec.trim());
}

node.widgets[vector_i].value = "";
if(sub_n == null) {
for(let i=1; i<=n; i++) {
var temp = "";
for(let j=1; j<=n; j++) {
if(temp!='')
temp += ',';
if(j==i)
temp += 'A';
else
temp += '0';
}

node.widgets[vector_i].value += `B${i}:${temp}\n`;
}
}
else {
for(let i=1; i<=sub_n; i++) {
var temp = "";
for(let j=1; j<=n; j++) {
if(temp!='')
temp += ',';

if(block!=j)
temp += '0';
else {
node.widgets[vector_i].value += `${value}/${value.split(':')[0]}`;
}
if(node.widgets_values) {
node.widgets_values[vector_i] = node.widgets[preset_i].value;
temp += ' ';
for(let k=1; k<=sub_n; k++) {
if(k==i)
temp += 'A ';
else
temp += '0 ';
}
}
}

node.widgets[vector_i].value += `B${block}.SUB${i}:${temp}\n`;
}
}
}
else {
node.widgets[vector_i].value += `${value}/${value.split(':')[0]}`;
}
if(node.widgets_values) {
node.widgets_values[vector_i] = node.widgets[preset_i].value;
}
}

node._value = value;
Object.defineProperty(node.widgets[preset_i], "value", {
set: (value) => {
if(value != 'Preset')
node._value = value;
},
get: () => {
return node._value;
Expand Down
152 changes: 76 additions & 76 deletions js/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,35 +42,38 @@ app.registerExtension({
// lora selector, wildcard selector
let combo_id = 5;

Object.defineProperty(node.widgets[combo_id], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(value != "Select the LoRA to add to the text") {
let lora_name = value;
if (lora_name.endsWith('.safetensors')) {
lora_name = lora_name.slice(0, -12);
}

wildcard_text_widget.value += `<lora:${lora_name}>`;
}
}
},
get: () => { return "Select the LoRA to add to the text"; }
});
// lora
node.widgets[combo_id].callback = (value, canvas, node, pos, e) => {
let lora_name = node._value;
if(lora_name.endsWith('.safetensors')) {
lora_name = lora_name.slice(0, -12);
}

wildcard_text_widget.value += `<lora:${lora_name}>`;
}

Object.defineProperty(node.widgets[combo_id], "value", {
set: (value) => {
if (value !== "Select the LoRA to add to the text")
node._value = value;
},

get: () => { return "Select the LoRA to add to the text"; }
});

// wildcard
node.widgets[combo_id+1].callback = (value, canvas, node, pos, e) => {
if(wildcard_text_widget.value != '')
wildcard_text_widget.value += ', '

wildcard_text_widget.value += node._wildcard_value;
}

Object.defineProperty(node.widgets[combo_id+1], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(value != "Select the Wildcard to add to the text") {
if(wildcard_text_widget.value != '')
wildcard_text_widget.value += ', '

wildcard_text_widget.value += value;
}
}
},
if (value !== "Select the Wildcard to add to the text")
node._wildcard_value = value;
},
get: () => { return "Select the Wildcard to add to the text"; }
});

Expand Down Expand Up @@ -115,47 +118,46 @@ app.registerExtension({
// lora selector, wildcard selector
let combo_id = 5;

node.widgets[combo_id].callback = (value, canvas, node, pos, e) => {
let lora_name = node._lora_value;
if (lora_name.endsWith('.safetensors')) {
lora_name = lora_name.slice(0, -12);
}

if(direction_widget.value) {
pos_wildcard_text_widget.value += `<lora:${lora_name}>`;
}
else {
neg_wildcard_text_widget.value += `<lora:${lora_name}>`;
}
}
Object.defineProperty(node.widgets[combo_id], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(value != "Select the LoRA to add to the text") {
let lora_name = value;
if (lora_name.endsWith('.safetensors')) {
lora_name = lora_name.slice(0, -12);
}

if(direction_widget.value) {
pos_wildcard_text_widget.value += `<lora:${lora_name}>`;
}
else {
neg_wildcard_text_widget.value += `<lora:${lora_name}>`;
}
}
}
if (value !== "Select the LoRA to add to the text")
node._lora_value = value;
},
get: () => { return "Select the LoRA to add to the text"; }
});

node.widgets[combo_id+1].callback = (value, canvas, node, pos, e) => {
let w = null;
if(direction_widget.value) {
w = pos_wildcard_text_widget;
}
else {
w = neg_wildcard_text_widget;
}

if(w.value != '')
w.value += ', '

w.value += node._wildcard_value;
}

Object.defineProperty(node.widgets[combo_id+1], "value", {
set: (value) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(value != "Select the Wildcard to add to the text") {
let w = null;
if(direction_widget.value) {
w = pos_wildcard_text_widget;
}
else {
w = neg_wildcard_text_widget;
}

if(w.value != '')
w.value += ', '

w.value += value;
}
}
if (value !== "Select the Wildcard to add to the text")
node._wildcard_value = value;
},
get: () => { return "Select the Wildcard to add to the text"; }
});
Expand Down Expand Up @@ -205,24 +207,22 @@ app.registerExtension({
}
});

Object.defineProperty(preset_widget, "value", {
set: (x) => {
const stackTrace = new Error().stack;
if(stackTrace.includes('inner_value_change')) {
if(node.widgets[2].value) {
node.widgets[2].value += ', ';
}

const y = x.split(':');
if(y.length == 2)
node.widgets[2].value += y[1].trim();
else
node.widgets[2].value += x.trim();
preset_widget.callback = (value, canvas, node, pos, e) => {
if(node.widgets[2].value) {
node.widgets[2].value += ', ';
}

const y = node._preset_value.split(':');
if(y.length == 2)
node.widgets[2].value += y[1].trim();
else
node.widgets[2].value += node._preset_value.trim();
}

if(node.widgets_values) {
node.widgets_values[2] = node.widgets[2].values;
}
};
Object.defineProperty(preset_widget, "value", {
set: (value) => {
if (value !== "#PRESET")
node._preset_value = value;
},
get: () => { return '#PRESET'; }
});
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-inspire-pack"
description = "This extension provides various nodes to support Lora Block Weight, Regional Nodes, Backend Cache, Prompt Utils, List Utils, Noise(Seed) Utils, ... and the Impact Pack."
version = "1.7"
version = "1.8"
license = { file = "LICENSE" }
dependencies = ["matplotlib", "cachetools"]

Expand Down

0 comments on commit 8db9411

Please sign in to comment.