From 1d67af71672de6c8642364bdc5abdc475900ba94 Mon Sep 17 00:00:00 2001 From: SayanoAI <28544690+SayanoAI@users.noreply.github.com> Date: Sat, 27 Jul 2024 16:47:07 -0400 Subject: [PATCH] slice node --- __init__.py | 8 +++-- conda-start-lowvram.bat | 2 +- conda-start.bat | 2 +- custom_nodes/utils.py | 37 +++++++++++++++++++++-- web/js/ui_handlers.js | 66 +++++------------------------------------ 5 files changed, 49 insertions(+), 66 deletions(-) diff --git a/__init__.py b/__init__.py index 5b92113..b52cb13 100644 --- a/__init__.py +++ b/__init__.py @@ -3,7 +3,7 @@ from .custom_nodes.uvr import UVR5Node from .custom_nodes.rvc import RVCNode from .custom_nodes.loaders import DownloadAudio, LoadAudio, LoadWhisperModelNode, LoadRVCModelNode, LoadHubertModel, LoadPitchExtractionParams from .custom_nodes.output import PreviewAudio -from .custom_nodes.utils import AudioBatchValueNode, MergeImageBatches, MergeLatentBatches, ImageRepeatInterleavedNode, LatentRepeatInterleavedNode, MergeAudioNode, SimpleMathNode +from .custom_nodes.utils import AudioBatchValueNode, MergeImageBatches, MergeLatentBatches, ImageRepeatInterleavedNode, LatentRepeatInterleavedNode, MergeAudioNode, SimpleMathNode, SliceNode # Set the web directory, any .js file in that directory will be loaded by the frontend as a frontend extension WEB_DIRECTORY = "./web" @@ -28,7 +28,8 @@ NODE_CLASS_MAPPINGS = { "LatentRepeatInterleavedNode": LatentRepeatInterleavedNode, "DownloadAudio": DownloadAudio, "BatchedTranscriptionEncoderNode": BatchedTranscriptionEncoderNode, - "SimpleMathNode": SimpleMathNode + "SimpleMathNode": SimpleMathNode, + "SliceNode": SliceNode } # A dictionary that contains the friendly/humanly readable titles for the nodes @@ -50,5 +51,6 @@ NODE_DISPLAY_NAME_MAPPINGS = { "ImageRepeatInterleavedNode": "🌺Image Repeat Interleaved", "LatentRepeatInterleavedNode": "🌺Latent Repeat Interleaved", "BatchedTranscriptionEncoderNode": "🌺Batched CLIP Transcription Encode (Prompt)", - "SimpleMathNode": "🌺Simple Math Operations" + "SimpleMathNode": "🌺Simple Math Operations", + "SliceNode": "🌺Slice Array" } \ No newline at end of file diff --git a/conda-start-lowvram.bat b/conda-start-lowvram.bat index fb8fec4..a59ede5 100644 --- a/conda-start-lowvram.bat +++ b/conda-start-lowvram.bat @@ -43,7 +43,7 @@ if %errorlevel% == 0 ( rem install CUDA torch CALL pip install torch==2.0.1+cu118 torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118 - CALL python main.py --preview-method=taesd --lowvram + CALL python main.py --disable-smart-memory --lowvram ) else ( echo Failed to activate environment... ) diff --git a/conda-start.bat b/conda-start.bat index 3e26858..b461fdf 100644 --- a/conda-start.bat +++ b/conda-start.bat @@ -43,7 +43,7 @@ if %errorlevel% == 0 ( rem install CUDA torch CALL pip install torch==2.0.1+cu118 torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu118 - CALL python main.py --preview-method=taesd + CALL python main.py --disable-smart-memory ) else ( echo Failed to activate environment... ) diff --git a/custom_nodes/utils.py b/custom_nodes/utils.py index aaa429c..6675639 100644 --- a/custom_nodes/utils.py +++ b/custom_nodes/utils.py @@ -393,8 +393,6 @@ class MergeAudioNode: audio_name = os.path.basename(audio_path) return {"ui": {"preview": [{"filename": audio_name, "type": "temp", "subfolder": "preview", "widgetId": widgetId}]}, "result": (lambda: audio_to_bytes(*merged_audio),)} - - class SimpleMathNode: def __init__(self): pass @@ -434,4 +432,37 @@ class SimpleMathNode: num_to_int = math.ceil if round_up else math.floor if len(number)>1: # handles list inputs return (list(map(num_to_int,number)), list(map(float,number)),) - else: return (num_to_int(number[0]), float(number[0]), ) \ No newline at end of file + else: return (num_to_int(number[0]), float(number[0]), ) + +# FROM: https://github.com/theUpsider/ComfyUI-Logic/blob/master/nodes.py#L11 +class AlwaysEqualProxy(str): + def __eq__(self, _): + return True + + def __ne__(self, _): + return False + +class SliceNode: + def __init__(self): + pass + + @classmethod + def INPUT_TYPES(s): + return { + "optional": { + "start": ("INT", {"default": 0, "min": 0}), + "end": ("INT", {"default": -1}), + }, + "required": { + "array": (AlwaysEqualProxy("*"),), + }, + } + + RETURN_TYPES = (AlwaysEqualProxy("*"),) + RETURN_NAMES = ("array",) + FUNCTION = "slice" + CATEGORY = CATEGORY + + def slice(self, array, start=0, end=-1): + if end==-1: end=len(array) + return (array[start:end],) \ No newline at end of file diff --git a/web/js/ui_handlers.js b/web/js/ui_handlers.js index c2e25f1..f8f1cde 100644 --- a/web/js/ui_handlers.js +++ b/web/js/ui_handlers.js @@ -37,7 +37,7 @@ function addPreviewWidget(nodeType, nodeData, widgetName="audio", when="onNodeCr // }) break; case "onExecuted": - chainCallback(nodeType.prototype, "onExecuted", function (data) { + chainCallback(nodeType.prototype, when, function (data) { const widgetId = `opt_widget-${Math.random()}` nodeData.input.hidden = { ...nodeData.input.hidden, @@ -131,61 +131,6 @@ function previewAudio(node,options={filename: null, type: "input", widgetName: " return previewWidget } -function audioPreview(node, inputName, inputData, app) { - - const options = inputData.pop() - const audioWidget = node.widgets.find((w) => w.name === options.widgetName); - if (!audioWidget) return null - - /* - A method that returns the required style for the html - */ - var default_value = audioWidget.value; - Object.defineProperty(audioWidget, "value", { - set : function(value) { - this._real_value = value; - }, - - get : function() { - let value = ""; - if (this._real_value) { - value = this._real_value; - } else { - return default_value; - } - - if (value.filename) { - let real_value = value; - value = ""; - if (real_value.subfolder) { - value = real_value.subfolder + "/"; - } - - value += real_value.filename; - - if(real_value.type && real_value.type !== "input") - value += ` [${real_value.type}]`; - } - return value; - } - }); - - let element = previewAudio(node, {filename: audioWidget.value, ...options}); - const cb = node.callback; - audioWidget.callback = function () { - element = previewAudio(node, {filename: audioWidget.value, ...options}); - if (cb) { - return cb.apply(this, arguments); - } - }; - // document.body.append(element); - // console.log({element}) - // let uploadWidget = this.addWidget(element); - // uploadWidget.options.serialize = false; - - return { widget: element }; -} - function chainCallback(object, property, callback) { if (object == undefined) { //This should not happen. @@ -335,8 +280,6 @@ function addUploadWidget(nodeType, nodeData, widgetName, type="video") { }); } -// ComfyWidgets.AUDIOPREVIEW = audioPreview; - app.registerExtension({ name: "RVC-Studio.UI", async beforeRegisterNodeDef(nodeType, nodeData, app) { @@ -359,6 +302,13 @@ app.registerExtension({ addPreviewWidget(nodeType, nodeData, "audio", "onExecuted" ) break; + case "SliceNode": + chainCallback(nodeType.prototype, "onConnectInput", function (data, inputs) { + nodeType.nodeData.output[0] = inputs[1] + console.log({nodeType, nodeData, data, inputs, node: app}) + }) + break; + default: break