Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to execute comfyscript when called via function #65

Closed
dhiraj-salian opened this issue Aug 16, 2024 · 7 comments
Closed

Unable to execute comfyscript when called via function #65

dhiraj-salian opened this issue Aug 16, 2024 · 7 comments
Labels
bug Something isn't working pending Pending ComfyUI or custom node changes runtime

Comments

@dhiraj-salian
Copy link

dhiraj-salian commented Aug 16, 2024

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:

  • main.py : Executing main.py fails with the above error
import image

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
Copy link
Owner

* 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
Copy link
Author

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
Copy link
Owner

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

@dhiraj-salian
Copy link
Author

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
Copy link
Owner

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

@Chaoses-Ib Chaoses-Ib added bug Something isn't working runtime pending Pending ComfyUI or custom node changes labels Aug 16, 2024
@dhiraj-salian
Copy link
Author

Thank you @Chaoses-Ib

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

@doctorpangloss
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending Pending ComfyUI or custom node changes runtime
Projects
None yet
Development

No branches or pull requests

3 participants