Compare commits

...
Author SHA1 Message Date
tzwm f9466e029a Merge branch 'main' into xyz 2024-01-11 10:20:17 +08:00
tzwm 71e18925e9 rename select_inputs node 2024-01-11 10:18:45 +08:00
tzwm a83d902507 remove unfinished node 2024-01-11 10:17:20 +08:00
Samwise Wang 8a2ec63a3f Merge pull request #14 from talesofai/load_image_by_url
add basic load_image_by_url node
2024-01-10 20:02:19 +08:00
tzwm 5abbc50890 add preview to select_inputs 2024-01-10 11:45:59 +08:00
tzwm 0545ceb556 finish basic select_inputs node 2024-01-10 00:38:45 +08:00
tzwm 92bc0ce868 add UI of select_inputs and xyz_plot nodes 2024-01-09 22:24:31 +08:00
4 changed files with 135 additions and 1 deletions
+3 -1
View File
@@ -5,7 +5,7 @@ import server
from .utils import collections_path, browser_path, sources_path, download_logs_path
from .routes import sources, collections, config, files, downloads
from .nodes import load_image_by_url
from .nodes import select_inputs, load_image_by_url
browser_app = web.Application()
browser_app.add_routes([
@@ -42,7 +42,9 @@ for dir in [collections_path, sources_path, download_logs_path]:
WEB_DIRECTORY = "web"
NODE_CLASS_MAPPINGS = {
"LoadImageByUrl //Browser": load_image_by_url.LoadImageByUrl,
"SelectInputs //Browser": select_inputs.SelectInputs,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"LoadImageByUrl //Browser": "Load Image By URL",
"SelectInputs //Browser": "Select Node Inputs",
}
+46
View File
@@ -0,0 +1,46 @@
class SelectInputs:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"input_1": [["none"], {}],
"input_2": [["none"], {}],
"input_3": [["none"], {}],
"input_4": [["none"], {}],
"preview": ["STRING", {"multiline": True}],
}
}
@classmethod
def VALIDATE_INPUTS(s, input_1, input_2, input_3, input_4):
return True
# {
# "node_id": 4,
# "node_type": "CheckpointLoaderSimple",
# "widget_name": "ckpt_name",
# }
RETURN_TYPES = ("INPUT", "INPUT", "INPUT", "INPUT",)
RETURN_NAMES = ("input_1", "input_2", "input_3", "input_4",)
FUNCTION = "run"
OUTPUT_NODE = True
CATEGORY = "Browser"
def run(self, input_1, input_2, input_3, input_4):
ret = ()
for input in [input_1, input_2, input_3, input_3]:
node_id, node_type, widget_name = input.split("::")
ret = ret + ({
"node_id": node_id[1:],
"node_type": node_type,
"widget_name": widget_name,
},)
return ret
+3
View File
@@ -5,6 +5,9 @@ import time
from typing import TypedDict, List
import folder_paths
from comfy.cli_args import args
SERVER_BASE_URL = f'http://{args.listen}:{args.port}'
browser_path = path.dirname(__file__)
collections_path = path.join(browser_path, 'collections')
+83
View File
@@ -0,0 +1,83 @@
import { app } from "../../../scripts/app.js";
const selectInputsNodeType = 'SelectInputs //Browser';
const SPLITTER = '::';
function getGraphInputs(graph) {
let inputs = [];
graph._nodes?.forEach(n => {
n.widgets?.forEach(w => {
inputs.push([`#${n.id}`, n.type, w.name].join(SPLITTER));
});
});
return inputs;
}
function refreshPreview(node) {
let values = [];
node.widgets.forEach(w => {
if (w.type === 'combo' && w.name.startsWith('input_')) {
const v = w.value.split(SPLITTER);
values.push({
node_id: v[0].substring(1),
node_type: v[1],
widget_name: v[2],
});
}
});
const preview = node.widgets.find(w => w.name === 'preview');
preview.value = JSON.stringify(values);
}
function refreshInputs(node, app) {
const inputs = getGraphInputs(app.graph);
node.widgets.forEach(w => {
if (w.type != 'combo') {
return;
}
w.options.values = inputs;
w.value = inputs[0];
});
const size = node.computeSize();
node.setSize([size[0] * 1.5, size[1]]);
refreshPreview(node);
}
app.registerExtension({
name: "Browser.Nodes.SelectInputs",
nodeCreated(node, app) {
if (node.constructor.type != selectInputsNodeType) {
return;
}
node.widgets.forEach(w => {
if (w.name === 'preview') {
if (w.element) {
w.element.disabled = true;
}
}
if (w.type === 'combo' && w.name.startsWith('input_')) {
const oriCallback = w.callback;
w.callback = () => {
oriCallback?.apply(arguments);
refreshPreview(node)
};
}
});
node.addWidget(
"button", 'Refresh', '',
() => refreshInputs(node, app)
);
refreshInputs(node, app);
},
loadedGraphNode(node, app) {
if (node.type != selectInputsNodeType) {
return;
}
refreshInputs(node, app);
}
});