From 467bc66bfd67c18c56aac2ac343e8c0fd2cc4f2b Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 21 Jun 2025 06:51:22 +0000 Subject: [PATCH] I've added a script to execute a default pipeline and updated the README. This update introduces a new Python script, `script_examples/execute_default_pipeline.py`, that allows you to execute a predefined ComfyUI pipeline. The script: - Defines a default pipeline structure in JSON format. - Sends the pipeline to a running ComfyUI server instance for execution. - Prints a success message upon queuing the prompt. The `README.md` has been updated to include: - A new section "Running a Default Pipeline". - Step-by-step instructions on how to run the new script. - Information on where to find the generated output images. - A note about the required checkpoint file (`v1-5-pruned-emaonly.safetensors`). --- README.md | 18 +++ script_examples/execute_default_pipeline.py | 115 ++++++++++++++++++++ 2 files changed, 133 insertions(+) create mode 100644 script_examples/execute_default_pipeline.py diff --git a/README.md b/README.md index 000d76801..fcab8a699 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,24 @@ This ui will let you design and execute advanced stable diffusion pipelines using a graph/nodes/flowchart based interface. For some workflow examples and see what ComfyUI can do you can check out: ### [ComfyUI Examples](https://comfyanonymous.github.io/ComfyUI_examples/) +## Running a Default Pipeline + +A script to execute a default pipeline is available in `script_examples/execute_default_pipeline.py`. + +To run this script: + +1. **Ensure ComfyUI Server is Running:** + Start the ComfyUI server by running `python main.py` in your terminal from the root directory of this project. By default, the server runs at `http://127.0.0.1:8188`. +2. **Execute the Script:** + Open another terminal, navigate to the `script_examples/` directory, and run the script: + ```bash + python execute_default_pipeline.py + ``` +3. **Find the Output:** + If the execution is successful, the script will print "Prompt queued successfully!". The generated image will be saved in the `output/` directory with a filename starting with `ComfyUI` (e.g., `ComfyUI_00001_.png`). + +**Note:** The default pipeline uses the `v1-5-pruned-emaonly.safetensors` checkpoint. Make sure this checkpoint is available in your `models/checkpoints/` directory. If not, you can either download it or modify the `ckpt_name` in the `execute_default_pipeline.py` script to use a checkpoint you have. + ### [Installing ComfyUI](#installing) ## Features diff --git a/script_examples/execute_default_pipeline.py b/script_examples/execute_default_pipeline.py new file mode 100644 index 000000000..6c41d1ff8 --- /dev/null +++ b/script_examples/execute_default_pipeline.py @@ -0,0 +1,115 @@ +import json +from urllib import request + +# This is the ComfyUI api prompt format. + +# If you want it for a specific workflow you can "enable dev mode options" +# in the settings of the UI (gear beside the "Queue Size: ") this will enable +# a button on the UI to save workflows in api format. + +# keep in mind ComfyUI is pre alpha software so this format will change a bit. + +# this is the one for the default workflow +prompt_text = """ +{ + "3": { + "class_type": "KSampler", + "inputs": { + "cfg": 8, + "denoise": 1, + "latent_image": [ + "5", + 0 + ], + "model": [ + "4", + 0 + ], + "negative": [ + "7", + 0 + ], + "positive": [ + "6", + 0 + ], + "sampler_name": "euler", + "scheduler": "normal", + "seed": 8566257, + "steps": 20 + } + }, + "4": { + "class_type": "CheckpointLoaderSimple", + "inputs": { + "ckpt_name": "v1-5-pruned-emaonly.safetensors" + } + }, + "5": { + "class_type": "EmptyLatentImage", + "inputs": { + "batch_size": 1, + "height": 512, + "width": 512 + } + }, + "6": { + "class_type": "CLIPTextEncode", + "inputs": { + "clip": [ + "4", + 1 + ], + "text": "masterpiece best quality girl" + } + }, + "7": { + "class_type": "CLIPTextEncode", + "inputs": { + "clip": [ + "4", + 1 + ], + "text": "bad hands" + } + }, + "8": { + "class_type": "VAEDecode", + "inputs": { + "samples": [ + "3", + 0 + ], + "vae": [ + "4", + 2 + ] + } + }, + "9": { + "class_type": "SaveImage", + "inputs": { + "filename_prefix": "ComfyUI", + "images": [ + "8", + 0 + ] + } + } +} +""" + +def queue_prompt(prompt): + p = {"prompt": prompt} + data = json.dumps(p).encode('utf-8') + req = request.Request("http://127.0.0.1:8188/prompt", data=data) + request.urlopen(req) + print("Prompt queued successfully!") + +if __name__ == "__main__": + prompt = json.loads(prompt_text) + # You can modify the prompt here if needed, for example: + # prompt["6"]["inputs"]["text"] = "masterpiece best quality man" + # prompt["3"]["inputs"]["seed"] = 5 + + queue_prompt(prompt)