Chaoses-Ib / ComfyScript

A Python frontend and library for ComfyUI
MIT License
369 stars 20 forks source link

Unable to execute comfyscript when called via function #65

Closed dhiraj-salian closed 5 days ago

dhiraj-salian commented 3 weeks ago

I am trying to write a script using comfyscript to generate images. When the comfyscript is called using function it throws the following error:

Failed to validate prompt for output SaveImage.0:
* CheckpointLoaderSimple CheckpointLoaderSimple.0:
  - Value not in list: ckpt_name: 'artium_v20Turboboosted.safetensors' not in (list of length 35)
Output will be ignored
invalid prompt: {'type': 'prompt_outputs_failed_validation', 'message': 'Prompt outputs failed validation', 'details': '', 'extra_info': {}}
ComfyScript: Failed to queue prompt: <ClientResponse(http://127.0.0.1:8188/prompt) [400 Bad Request]>
<CIMultiDictProxy('Content-Type': 'application/json; charset=utf-8', 'Content-Length': '545', 'Date': 'Fri, 16 Aug 2024 14:07:58 GMT', 'Server': 'Python/3.11 aiohttp/3.10.3')>
<ClientResponse(http://127.0.0.1:8188/prompt) [400 Bad Request]>
<CIMultiDictProxy('Content-Type': 'application/json; charset=utf-8', 'Content-Length': '545', 'Date': 'Fri, 16 Aug 2024 14:07:58 GMT', 'Server': 'Python/3.11 aiohttp/3.10.3')>
{
  "error": {
    "type": "prompt_outputs_failed_validation",
    "message": "Prompt outputs failed validation",
    "details": "",
    "extra_info": {}
  },
  "node_errors": {
    "CheckpointLoaderSimple.0": {
      "errors": [
        {
          "type": "value_not_in_list",
          "message": "Value not in list",
          "details": "ckpt_name: 'artium_v20Turboboosted.safetensors' not in (list of length 35)",
          "extra_info": {
            "input_name": "ckpt_name",
            "input_config": null,
            "received_value": "artium_v20Turboboosted.safetensors"
          }
        }
      ],
      "dependent_outputs": [
        "SaveImage.0"
      ],
      "class_type": "CheckpointLoaderSimple"
    }
  }
}

Steps to reproduce:

def main(name: str): prompt = "Dark, misty forest with twisted tree branches like skeletal fingers reaching towards a full moon hanging low in the sky, casting an eerie glow on a worn dirt path that winds through the trees. The air is heavy with the scent of damp earth and decaying leaves. In the distance, a faint light flickers from a lantern hung outside a small, weathered cottage, its windows like empty eyes staring back at you." image.generate_image(prompt, name)

if name == "main": main("story1")

* image.py: Executing image.py succeeds

from comfy_script.runtime import load, Workflow

load("comfyui")

from comfy_script.runtime.nodes import ( CheckpointLoaderSimple, CLIPTextEncode, EmptyLatentImage, KSampler, VAEDecode, SaveImage, )

negative_prompt = "ugly, deformed, noisy, blurry, noisy, low contrast (((bad anatomy))) watermark, bad hands, (((incomplete limbs))) ((((looking at viewer))))(((bad anatomy))) ((exaggerated anatomy))"

def generate_image(positive_prompt: str, output: str): global negative_prompt

with Workflow():
    model, clip, vae = CheckpointLoaderSimple("artium_v20Turboboosted.safetensors")
    positive_conditioning = CLIPTextEncode(positive_prompt, clip)
    negative_conditioning = CLIPTextEncode(negative_prompt, clip)
    latent = EmptyLatentImage(1024, 576, 1)
    latent = KSampler(
        model,
        156680208700286,
        20,
        7,
        "dpmpp_2m",
        "karras",
        positive_conditioning,
        negative_conditioning,
        latent,
        1,
    )
    image = VAEDecode(latent, vae)
    SaveImage(image, output)

if name == "main": prompt = "Dark, misty forest with twisted tree branches like skeletal fingers reaching towards a full moon hanging low in the sky, casting an eerie glow on a worn dirt path that winds through the trees. The air is heavy with the scent of damp earth and decaying leaves. In the distance, a faint light flickers from a lantern hung outside a small, weathered cottage, its windows like empty eyes staring back at you." generate_image(prompt, "story1")



I have tried to play around by moving load() and Workflow() to main.py but was facing the same issue.
Please help check if I am missing something.

Thanks for the help.
Chaoses-Ib commented 3 weeks ago
* CheckpointLoaderSimple CheckpointLoaderSimple.0:
  - Value not in list: ckpt_name: 'artium_v20Turboboosted.safetensors' not in (list of length 35)

This error means ComfyUI can't find the model 'artium_v20Turboboosted.safetensors'. You may put it in the wrong directory.

To print all the models found by ComfyUI:

from comfy_script.runtime import load
load("comfyui")
from comfy_script.runtime.nodes import Checkpoints

print(list(Checkpoints))
dhiraj-salian commented 3 weeks ago

I have verified the location. When executing main.py, it is not finding the model:

[<Checkpoints.Anything_V3_0: 'Anything-V3.0.ckpt'>, <Checkpoints.Realistic_Vision_V5_1_fp16_no_ema: 'Realistic_Vision_V5.1_fp16-no-ema.safetensors'>, <Checkpoints.Realistic_Vision_V6_0_NV_B1_fp16: 'Realistic_Vision_V6.0_NV_B1_fp16.safetensors'>, <Checkpoints.anyloraCheckpoint_bakedvaeBlessedFp16: 'anyloraCheckpoint_bakedvaeBlessedFp16.safetensors'>, <Checkpoints.aura_flow_0_1: 'aura_flow_0.1.safetensors'>, <Checkpoints.cardosAnime_v10: 'cardosAnime_v10.safetensors'>, <Checkpoints.cosxl: 'cosxl.safetensors'>, <Checkpoints.cosxl_edit: 'cosxl_edit.safetensors'>, <Checkpoints.counterfeitV30_v30: 'counterfeitV30_v30.safetensors'>, <Checkpoints.dreamshaperXL_v21TurboDPMSDE: 'dreamshaperXL_v21TurboDPMSDE.safetensors'>, <Checkpoints.dreamshaper_8: 'dreamshaper_8.safetensors'>, <Checkpoints.hunyuan_dit_1_0: 'hunyuan_dit_1.0.safetensors'>, <Checkpoints.hunyuan_dit_1_1: 'hunyuan_dit_1.1.safetensors'>, <Checkpoints.hunyuan_dit_1_2: 'hunyuan_dit_1.2.safetensors'>, <Checkpoints.juggernautXL_v9Rundiffusionphoto2: 'juggernautXL_v9Rundiffusionphoto2.safetensors'>, <Checkpoints.picxReal_10: 'picxReal_10.safetensors'>, <Checkpoints.realvisxlV40_v40Bakedvae: 'realvisxlV40_v40Bakedvae.safetensors'>, <Checkpoints.revAnimated_v2Rebirth: 'revAnimated_v2Rebirth.safetensors'>, <Checkpoints.sd3_medium: 'sd3_medium.safetensors'>, <Checkpoints.sd3_medium_incl_clips: 'sd3_medium_incl_clips.safetensors'>, <Checkpoints.sd3_medium_incl_clips_t5xxlfp8: 'sd3_medium_incl_clips_t5xxlfp8.safetensors'>, <Checkpoints.sd_xl_base_1_0: 'sd_xl_base_1.0.safetensors'>, <Checkpoints.sd_xl_refiner_1_0: 'sd_xl_refiner_1.0.safetensors'>, <Checkpoints.sd_xl_turbo_1_0: 'sd_xl_turbo_1.0.safetensors'>, <Checkpoints.sd_xl_turbo_1_0_fp16: 'sd_xl_turbo_1.0_fp16.safetensors'>, <Checkpoints.stable_audio_open_1_0: 'stable_audio_open_1.0.safetensors'>, <Checkpoints.stable_cascade_stage_b: 'stable_cascade_stage_b.safetensors'>, <Checkpoints.stable_cascade_stage_c: 'stable_cascade_stage_c.safetensors'>, <Checkpoints.stage_a: 'stage_a.safetensors'>, <Checkpoints.v1_5_pruned_emaonly: 'v1-5-pruned-emaonly.safetensors'>, <Checkpoints.v1_5_pruned: 'v1-5-pruned.safetensors'>, <Checkpoints.v2_1_768_ema_pruned: 'v2-1_768-ema-pruned.ckpt'>, <Checkpoints.wd_illusion_fp16: 'wd-illusion-fp16.safetensors'>]

But when executing image.py within the same directory, it is able to find the model:

[<Checkpoints.Anything_V3_0: 'Anything-V3.0.ckpt'>, <Checkpoints.Realistic_Vision_V5_1_fp16_no_ema: 'Realistic_Vision_V5.1_fp16-no-ema.safetensors'>, <Checkpoints.Realistic_Vision_V6_0_NV_B1_fp16: 'Realistic_Vision_V6.0_NV_B1_fp16.safetensors'>, <Checkpoints.anyloraCheckpoint_bakedvaeBlessedFp16: 'anyloraCheckpoint_bakedvaeBlessedFp16.safetensors'>, <Checkpoints.artium_v20Turboboosted: 'artium_v20Turboboosted.safetensors'>, <Checkpoints.aura_flow_0_1: 'aura_flow_0.1.safetensors'>, <Checkpoints.cardosAnime_v10: 'cardosAnime_v10.safetensors'>, <Checkpoints.cosxl: 'cosxl.safetensors'>, <Checkpoints.cosxl_edit: 'cosxl_edit.safetensors'>, <Checkpoints.counterfeitV30_v30: 'counterfeitV30_v30.safetensors'>, <Checkpoints.dreamshaperXL_v21TurboDPMSDE: 'dreamshaperXL_v21TurboDPMSDE.safetensors'>, <Checkpoints.dreamshaper_8: 'dreamshaper_8.safetensors'>, <Checkpoints.hunyuan_dit_1_0: 'hunyuan_dit_1.0.safetensors'>, <Checkpoints.hunyuan_dit_1_1: 'hunyuan_dit_1.1.safetensors'>, <Checkpoints.hunyuan_dit_1_2: 'hunyuan_dit_1.2.safetensors'>, <Checkpoints.juggernautXL_v9Rundiffusionphoto2: 'juggernautXL_v9Rundiffusionphoto2.safetensors'>, <Checkpoints.picxReal_10: 'picxReal_10.safetensors'>, <Checkpoints.realvisxlV40_v40Bakedvae: 'realvisxlV40_v40Bakedvae.safetensors'>, <Checkpoints.revAnimated_v2Rebirth: 'revAnimated_v2Rebirth.safetensors'>, <Checkpoints.sd3_medium: 'sd3_medium.safetensors'>, <Checkpoints.sd3_medium_incl_clips: 'sd3_medium_incl_clips.safetensors'>, <Checkpoints.sd3_medium_incl_clips_t5xxlfp8: 'sd3_medium_incl_clips_t5xxlfp8.safetensors'>, <Checkpoints.sd_xl_base_1_0: 'sd_xl_base_1.0.safetensors'>, <Checkpoints.sd_xl_refiner_1_0: 'sd_xl_refiner_1.0.safetensors'>, <Checkpoints.sd_xl_turbo_1_0: 'sd_xl_turbo_1.0.safetensors'>, <Checkpoints.sd_xl_turbo_1_0_fp16: 'sd_xl_turbo_1.0_fp16.safetensors'>, <Checkpoints.stable_audio_open_1_0: 'stable_audio_open_1.0.safetensors'>, <Checkpoints.stable_cascade_stage_b: 'stable_cascade_stage_b.safetensors'>, <Checkpoints.stable_cascade_stage_c: 'stable_cascade_stage_c.safetensors'>, <Checkpoints.stage_a: 'stage_a.safetensors'>, <Checkpoints.v1_5_pruned_emaonly: 'v1-5-pruned-emaonly.safetensors'>, <Checkpoints.v1_5_pruned: 'v1-5-pruned.safetensors'>, <Checkpoints.v2_1_768_ema_pruned: 'v2-1_768-ema-pruned.ckpt'>, <Checkpoints.wd_illusion_fp16: 'wd-illusion-fp16.safetensors'>]
Chaoses-Ib commented 3 weeks ago

That's weird. Did you put the model in the same directory as others? Or it's in a separate directory?

dhiraj-salian commented 3 weeks ago

This is my folder structure. The models, main.py and image.py are at same hierarchy in same directory:

image

Not sure but I feel it has something to do with asynchronous loading.

Chaoses-Ib commented 3 weeks ago

There is a bug in the comfyui package. If you name the script main.py, it won't use the current directory as the base path. A simple workaround is to rename your main.py to other names, or use the official ComfyUI.

Related code: https://github.com/hiddenswitch/ComfyUI/blob/3e91f98aa22fb620f339e0602f059bfa1fb5bf6d/comfy/cmd/folder_paths.py#L83-L84

dhiraj-salian commented 3 weeks ago

Thank you @Chaoses-Ib

The workaround of renaming main.py helps resolve the issue.

doctorpangloss commented 5 days ago

this is resolved upstream @dhiraj-salian thanks for reporting the issue