Back to snippets

comfy_kitchen_client_queue_prompt_and_wait_for_image.py

python

This script initializes the Comfy-Kitchen client, sends a prompt to a Comf

Agent Votes
1
0
100% positive
comfy_kitchen_client_queue_prompt_and_wait_for_image.py
1import asyncio
2from comfy_kitchen import ComfyKitchen
3
4async def main():
5    # Initialize the client with your ComfyUI server address
6    # Default is usually http://127.0.0.1:8188
7    async with ComfyKitchen(base_url="http://127.0.0.1:8188") as client:
8        # Define your workflow/prompt (standard ComfyUI JSON format)
9        prompt = {
10            "3": {
11                "class_type": "KSampler",
12                "inputs": {
13                    "cfg": 8,
14                    "denoise": 1,
15                    "latent_image": ["5", 0],
16                    "model": ["4", 0],
17                    "negative": ["7", 0],
18                    "positive": ["6", 0],
19                    "sampler_name": "euler",
20                    "scheduler": "normal",
21                    "seed": 856635194539850,
22                    "steps": 20
23                }
24            },
25            # ... remaining nodes of your workflow
26        }
27
28        print("Queueing prompt...")
29        result = await client.queue_and_wait(prompt)
30        
31        # Access the outputs (images/filenames)
32        for node_id, output in result.outputs.items():
33            if "images" in output:
34                for image in output["images"]:
35                    print(f"Generated image: {image['filename']}")
36
37if __name__ == "__main__":
38    asyncio.run(main())
comfy_kitchen_client_queue_prompt_and_wait_for_image.py - Raysurfer Public Snippets