Closed pranaykoppula closed 4 months ago
In ComfyScript's real mode, nodes are also just imported, but with a wrapped __new__
to handle the arguments. You can modify it directly:
from comfy_script.runtime.real import *
load()
from comfy_script.runtime.real.nodes import *
print(getattr(LoadImage, LoadImage.FUNCTION))
# <function LoadImage.load_image at 0x0000021B17F70160>
def my_load_image(self, image):
print('LoadImage is called')
setattr(LoadImage, LoadImage.FUNCTION, my_load_image)
LoadImage('test.png')
# LoadImage is called
By the way, there are already built-in nodes installed by ComfyScript to pass PIL images directly:
def PILToImage(
images: PilImage
) -> Image
def PILToMask(
images: PilImage
) -> Image
def ImageToPIL(
images: Image
) -> PilImage
Thank you! This was very helpful
For example, in nodes.py in the main ComfyUI directory, the code for the Load Image class is as follows:
In load_image, I want to change
into this:
because I wanna pass the PIL Image object directly rather than giving it a path. I want to make similar changes to the SaveImage class.
This is possible to do and integrate in the ComfyUI-to-Python-Extension because it just imports the original ComfyUI nodes as is. But that extension hasn't been updated in a year, and the same thing doesn't seem to work in ComfyScript
I imagine this is because of the way the nodes are being imported. Is there a way around this?