CoolFace
Apppublic

brunvelop/ComfyUI

sourceHugging Faceupdated 3y agoView on Hugging Face
2likes
basic_api_example.py121 linesDownload Raw Back to script_examples
1import json2from urllib import request, parse3import random4 5#This is the ComfyUI api prompt format.6 7#If you want it for a specific workflow you can "enable dev mode options"8#in the settings of the UI (gear beside the "Queue Size: ") this will enable9#a button on the UI to save workflows in api format.10 11#keep in mind ComfyUI is pre alpha software so this format will change a bit.12 13#this is the one for the default workflow14prompt_text = """15{16    "3": {17        "class_type": "KSampler",18        "inputs": {19            "cfg": 8,20            "denoise": 1,21            "latent_image": [22                "5",23                024            ],25            "model": [26                "4",27                028            ],29            "negative": [30                "7",31                032            ],33            "positive": [34                "6",35                036            ],37            "sampler_name": "euler",38            "scheduler": "normal",39            "seed": 8566257,40            "steps": 2041        }42    },43    "4": {44        "class_type": "CheckpointLoaderSimple",45        "inputs": {46            "ckpt_name": "v1-5-pruned-emaonly.ckpt"47        }48    },49    "5": {50        "class_type": "EmptyLatentImage",51        "inputs": {52            "batch_size": 1,53            "height": 512,54            "width": 51255        }56    },57    "6": {58        "class_type": "CLIPTextEncode",59        "inputs": {60            "clip": [61                "4",62                163            ],64            "text": "masterpiece best quality girl"65        }66    },67    "7": {68        "class_type": "CLIPTextEncode",69        "inputs": {70            "clip": [71                "4",72                173            ],74            "text": "bad hands"75        }76    },77    "8": {78        "class_type": "VAEDecode",79        "inputs": {80            "samples": [81                "3",82                083            ],84            "vae": [85                "4",86                287            ]88        }89    },90    "9": {91        "class_type": "SaveImage",92        "inputs": {93            "filename_prefix": "ComfyUI",94            "images": [95                "8",96                097            ]98        }99    }100}101"""102 103def queue_prompt(prompt):104    p = {"prompt": prompt}105    data = json.dumps(p).encode('utf-8')106    req =  request.Request("http://127.0.0.1:8188/prompt", data=data)107    request.urlopen(req)108 109 110prompt = json.loads(prompt_text)111#set the text prompt for our positive CLIPTextEncode112prompt["6"]["inputs"]["text"] = "masterpiece best quality man"113 114#set the seed for our KSampler node115prompt["3"]["inputs"]["seed"] = 5116 117 118queue_prompt(prompt)119 120 121