Chaoses-Ib / ComfyScript

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

Was Node Suite Image Save is not transpiled #19

Open lingondricka2 opened 10 months ago

lingondricka2 commented 10 months ago

workflow (79).json

Not transpiled, also when I added the "was node suite image save" to my script manually and ran the script it embedded the whole script to the image and not the workflow.

ImageSave(
        image,             # images: Image,
        path,                # output_path: str = '[time(%Y-%m-%d)]',
        'ComfyUI',       #filename_prefix: str = 'ComfyUI',
        '_',                    #filename_delimiter: str = '_',
        4,                      #filename_number_padding: int = 4,
        'false',               #filename_number_start: ImageSave.filename_number_start = 'false',
        'webp',             #extension: ImageSave.extension = 'png',
        80,                    #quality: int = 100,
        'true',                 #lossless_webp: ImageSave.lossless_webp = 'false',
        'false',               #overwrite_mode: ImageSave.overwrite_mode = 'false',
        'false',               #show_history: ImageSave.show_history = 'false',
        'true',               #show_history_by_prefix: ImageSave.show_history_by_prefix = 'true',
        'true',               #embed_workflow: ImageSave.embed_workflow = 'true',
        'true',               #show_previews: ImageSave.show_previews = 'true'
        )
Chaoses-Ib commented 10 months ago

Every output node will be transpiled with its own script. The problem is, the hook is only triggered when the metadata is written to a png file. Other formats, like webp, will not triggerd it. It works this way because the transpiler doens't know which node may save images.

I'm not sure what you are using the transpiler for. Using it in the web UI is designed to be used to generate a human-reable format of the workflow. If you want to convert workflows to scripts to use in code, then the CLI is probably better. I've also made a simply GUI for it, but not uploaded. If you want a GUI instead of a CLI, tell me, I'll polish it and upload.

Chaoses-Ib commented 10 months ago

As for the "workflow", it's an internal format used by the web UI (Differences from ComfyUI's web UI). The server only needs "prompt". So the runtime doesn't use or generate workflows in the web UI's internal format. However, you can drag and drop the image generated by the runtime to the web UI, and it'll convert it to the internal format. Can you let me know why would you need it?

By the way, you can turn off saving the script source by load(save_script_source=False). Though the compact version of the script is still saved, as it's equivalent to the "prompt" and doesn't save any more info.

lingondricka2 commented 10 months ago

Thank you for your help, I was unclear, the workflow is not loaded when I drag and drop the webp file, but It is loaded with a png file, with or without load(save_script_source=False). (The workflow is loaded when I drag and drop the webp file generated from the web UI)

Using a webp file over a png is not terrible important for me and I realize this might be a bit of an edge case, so you can close this issue if you want.

Chaoses-Ib commented 10 months ago

I dug a bit and found that this is a bug of the node itself: https://github.com/WASasquatch/was-node-suite-comfyui/blob/33534f2e48682ddcf580436ea39cffc7027cbb89/WAS_Node_Suite.py#L7227-L7238. It saves the prompt in Prompt, but the web UI only supports prompt. But workflow and Workflow are all supported in the web UI, and it's commented with "Support loading workflows from that webp custom node". I don't know why WAS not make them compatible with the web UI and why it's patched in the web UI instead of WAS. But anyway, a small PR to ComfyUI can fix this.

Chaoses-Ib commented 10 months ago

https://github.com/comfyanonymous/ComfyUI/pull/2707. Hope it will be merged soon. Or you can modify app.js as the PR does.

lingondricka2 commented 10 months ago

It was merged and I updated ComfyUI, checked app.js for the change. Still does not work. Can't upload webp to github, so here is link https://drive.google.com/file/d/1IxlsA5OMxaHD0f3sYbrwExV-hxhMDqWl/view?usp=sharing

The embedding looks a bit weird, it starts with Workflow: NUL Prompt :{"CheckpointLoaderSimple.0": {"inputs": {"ckpt_name": "xl\\turbovisionxlSuperFastXLBasedOnNew_alphaV0101Bakedvae.safetensors"},...

A webp generated from the web UI looks like: Workflow:{"last_node_id": 144, "last_link_id": 264, "nodes": [{"id": 70, "type": "CLIPTextEncode",...

Chaoses-Ib commented 10 months ago

Oh, I didn't notice that there is another bug in WAS Image Save: it will save Workflow regardless of whether it is available. And if Workflow exists, the web UI will use it instead of Prompt even if it's NUL. This one is surely a bug of the node itself and shouldn't be patched in ComfyUI. I've created a issue in WAS: https://github.com/WASasquatch/was-node-suite-comfyui/issues/340.