Chaoses-Ib / ComfyScript

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

int and Int #76

Open sneccc opened 1 month ago

sneccc commented 1 month ago
---> [28](vscode-notebook-cell:?execution_count=40&line=28) for i in range(batch_count):  
     [29](vscode-notebook-cell:?execution_count=40&line=29)     title =f" image {i}"
     [30](vscode-notebook-cell:?execution_count=40&line=30)     images_list.append(ImageFromBatch(final_image,i,batch_count))

TypeError: 'Int' object cannot be interpreted as an integer

Cant use Int returned by comfy script as a normal python int

with Workflow(queue=False):
    pos='beautiful scenery nature glass bottle landscape, purple galaxy bottle, fractal, nested images'
    neg='text, watermark, blurry, low quality'
    batch_size=4
    final_image=sample(model_name=CheckpointLoader.ckpt_name.sd15_Deliberate_v3, pos=pos, neg=neg, seed=42, batch_size=batch_size, images=None)

    batch_count=BatchCount(final_image)
    print(type(batch_count))
    images_list=[]
    title_list=[]

    for i in range(batch_count):  
        title =f" image {i}"
        images_list.append(ImageFromBatch(final_image,i,batch_count))
        title_list.append(title)

    best=AestheticsV2(image=final_image,text=pos)
    images_list.append(best)
    title_list.append("best")

    ui.ipy.ImageViewer(images_list,title_list)
Chaoses-Ib commented 1 month ago

In virtual mode, the output of nodes can't be directly used as normal Python values, see #29 for details.

However, you don't actually need to use BatchCount and ImageFromBatch, use PreviewImage(final_image).wait().wait() and it will return a list of images:

from PIL import Image

image = EmptyImage(512, 512, 1)
image = PreviewImage(image)

image_batch = image.wait()

# Get the first image
image: Image.Image = image_batch[0]

# Get all images in the batch
images: list[Image.Image] = image_batch.wait()

batch_count = len(images)
sneccc commented 1 month ago

Damn that was fast, thanks!

sneccc commented 1 month ago

image

import comfy_script.ui as ui
queue.watch_display(False)

images = []
titles = []
def gen(steps: int):
    pos = 'beautiful scenery nature glass bottle landscape, purple galaxy bottle, fractal, nested images'
    neg = 'text, watermark, blurry, low quality'
    latent = EmptyLatentImage(512, 512, 1)
    model, clip, vae = CheckpointLoaderSimple(ckpt_name=CheckpointLoader.ckpt_name.sd15_Deliberate_v3)
    latent = KSampler(model, 123, steps, 7, sampler_name=SamplerSelector.sampler_name.euler_ancestral, 
                    positive=CLIPTextEncode(pos, clip), negative=CLIPTextEncode(neg, clip), 
                    latent_image=latent, denoise=1)
    image = VAEDecode(latent, vae)
    return PreviewImage(image).wait()

with Workflow():
    for x in [10,20,30,50,80]:
        title = f'steps {x}'
        #print(title)
        images.append(gen(x))
        titles.append(title)

ui.ipy.ImageViewer(images, titles=titles)

how do i prevent unnecessary logging and btw do u have discord?

Chaoses-Ib commented 1 month ago

how do i prevent unnecessary logging

These progress bars are not from ComfyScript, but ComfyUI itself. To avoid them, you can launch ComfyUI in a separate process and connect it with load()/load('http://127.0.0.1:8188/'). Alternatively,

load()

import comfy.utils
comfy.utils.set_progress_bar_enabled(False)

and btw do u have discord?

https://discord.com/users/811863445703229492

sneccc commented 1 month ago

https://discord.com/users/811863445703229492

this doesn't seem to work it opens discord web but doesn't trigger any add popup give me your username instead image

Chaoses-Ib commented 1 month ago

chaoses_ib

Edit: Server https://discord.gg/arqJbtEg7w