slice node

This commit is contained in:
SayanoAI
2024-07-27 16:47:07 -04:00
parent 75f907aeb4
commit 1d67af7167
5 changed files with 49 additions and 66 deletions
+5 -3
View File
@@ -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"
}
+1 -1
View File
@@ -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...
)
+1 -1
View File
@@ -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...
)
+34 -3
View File
@@ -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]), )
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],)
+8 -58
View File
@@ -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