43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
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
|
|
|
|
def queue_prompt(prompt):
|
|
p = {"prompt": prompt}
|
|
|
|
# If the workflow contains API nodes, you can add a Comfy API key to the `extra_data`` field of the payload.
|
|
# p["extra_data"] = {
|
|
# "api_key_comfy_org": "comfyui-87d01e28d*******************************************************" # replace with real key
|
|
# }
|
|
# See: https://docs.comfy.org/tutorials/api-nodes/overview
|
|
# Generate a key here: https://platform.comfy.org/login
|
|
|
|
data = json.dumps(p).encode('utf-8')
|
|
req = request.Request("http://127.0.0.1:8188/prompt", data=data)
|
|
request.urlopen(req)
|
|
|
|
|
|
with open('/home/szlc/basic_api.json', 'r', encoding='utf-8') as file:
|
|
prompt_text = file.read()
|
|
|
|
prompt = json.loads(prompt_text)
|
|
#set the text prompt for our positive CLIPTextEncode
|
|
prompt["6"]["inputs"]["text"] = "masterpiece best quality man"
|
|
|
|
#set the seed for our KSampler node
|
|
prompt["3"]["inputs"]["seed"] = 5
|
|
|
|
|
|
queue_prompt(prompt)
|
|
|
|
|