Chaoses-Ib / ComfyScript

A Python frontend and library for ComfyUI
https://discord.gg/arqJbtEg7w
MIT License
432 stars 24 forks source link

thoughts on idiomatic way of making xy grid? #51

Closed ghostsquad closed 5 months ago

ghostsquad commented 5 months ago

Is there a more idiomatic way of making an xy grid in Python as opposed to using custom nodes?

Chaoses-Ib commented 5 months ago

You can use matplotlib to plot multiple images, though not out of the box. I guess this is what used by most custom nodes.

Alternatively, ipywidgets can also be used. There is already a widget for displaying multiple images in the repo. Adding titles to them won't be a lot of work. Though you can't save the grid as an image this way.

https://github.com/Chaoses-Ib/ComfyScript/blob/f6a34df041614de26435039f83f0e48a17ec137a/src/comfy_script/runtime/data/Images.py#L41-L116

Chaoses-Ib commented 5 months ago

Here is a simple example using the builtin widget:

def plot(x):
    image, _ = LoadImage(r'D:\ComfyUI\output\ComfyUI_00017_.png')
    image = ImageBlur(image, x)
    # PreviewImage(image).wait()[0] to get the PIL.Image
    return PreviewImage(image).wait()
images = []
for x in [1, 5, 10, 15, 20, 25, 30]:
    print(x)
    images.append(plot(x))
Images(*images)

image

ghostsquad commented 5 months ago

How would I add titles?

sorry for some of these newb questions. Sometimes I feel like I spend more time tweaking my workflow than I do generating images. ComfyScript has saved me a lot of time though so far. No more zooming and panning in the UI, and I can see all relevant parameters right on one screen.

Chaoses-Ib commented 5 months ago

Changing grid[i, j] = image to a widget containing both the image and the label should work. I'll add it later.

ghostsquad commented 5 months ago

If you have any suggestions for docs on widgets, please let me know. Happy to read up on it.

Chaoses-Ib commented 5 months ago

The docs of ipywidgets is here: https://ipywidgets.readthedocs.io/en/stable/

The usage is simple, just nesting widgets and display(). But it lacks some features, you may have to write some HTML/CSS in case there's no built-in option.

Another choice is Solara. It's like React, but in Python. It has some nice widgets, like the file drop used in metadata viewer, though the customization is also limited.

Chaoses-Ib commented 5 months ago

Titles are now supported.

Docs: https://github.com/Chaoses-Ib/ComfyScript/blob/main/docs/UI/ipywidgets.md

ghostsquad commented 5 months ago

thanks!