-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to get value from the output of a node and perform math or other operations #29
Comments
Currently you cannot do this directly. This is the main limitation of virtual mode:
There are several workarounds:
|
By the way, And |
Thanks! Yeah I kinda got desperate to get anything from the workflow and just threw everything at it. |
I haven't written much about node results in the docs because there are many refactors not done yet. There will be some built-in interop support for basic types in the future, so that one can And |
Thinking about this some, I wonder if some simple built-in eval utility nodes would be too out of scope for ComfyScript? I may look into writing a solution for this I just wonder if there was any chance you saw this as a possible enhancement already. |
Being able to mix Python code with nodes is one of the goals of ComfyScript. If ComfyUI is running in the same process as ComfyScript, this goal can be archived by directly executing nodes as normal Python functions, which is what real mode does. If ComfyUI is running remotely, either node value or user code needs to be passed around the client and the server. Passing value around is more flexible in that the client can do anything to the value, like calling external libraries and showing GUIs to let the user input the new value. However, it has the disadvantage that passing big values (e.g. models) would be slow. Passing code is more limited than passing values, but can be faster in this case. So solutions of both ways are useful in certain cases and would both be added in the future. The most common "pass code around" solution is using eval nodes. There are already many eval nodes made by the community, but most of them are bloated, including many other nodes unrelated to eval and not very useful with ComfyScript. So I didn't select one as built-in. If you are going to make one that isn't bloated, I'm very willing to add it as built-in. And the "pass value around" solution I'm going to implement is to add a node to apply callbacks to values. For example: audio, sr, duration = LoadAudio(params.snd_filename)
audio = ConvertAudio(audio, sr, model_sr, 1)
audio = ClipAudio(audio, Apply(duration, lambda x: x - 10.0), duration, model_sr)
# or
audio = ClipAudio(audio, duration.apply(lambda x: x - 10.0), duration, model_sr) The only requirement of Also note that currently none of these solutions can change workflow structures at runtime, i.e. no real control flows in the workflow (unless do some hacks to ComfyUI). As mentioned above, I'm waiting for comfyanonymous/ComfyUI#2666 to be merged. It allows a workflow to be dynamic, i.e. nodes can return sub-workflows to be executed at runtime. This allows the client to change the workflow structure at runtime, and doesn't have the inefficiency problem of the "run multiple times" solution. |
Hello! I have this code here
And I would like to perform math on the resulting duration from LoadAudio. If I try to use it raw, it will just throw the error
TypeError: unsupported operand type(s) for -: 'Float' and 'float'
Is it possible to get the result here?The text was updated successfully, but these errors were encountered: