"""Seed the isolated backend: one fake-ComfyUI endpoint + two workflows.""" import json import sys import urllib.request BASE = "http://127.0.0.1:8247" def call(method, path, payload=None): data = json.dumps(payload).encode() if payload is not None else None req = urllib.request.Request( BASE + path, data=data, method=method, headers={"Content-Type": "application/json"} ) with urllib.request.urlopen(req) as r: body = r.read() return json.loads(body) if body else {} IMAGE_WF = { "1": { "class_type": "CLIPTextEncode", "inputs": {"text": "默认提示词"}, "_meta": {"title": "(Input:prompt) 正向提示词"}, }, "2": { "class_type": "PrimitiveInt", "inputs": {"value": 42}, "_meta": {"title": "(Input:seed) 种子"}, }, "9": { "class_type": "SaveImage", "inputs": {"images": "x"}, "_meta": {"title": "(Output:image) 图片输出"}, }, } VIDEO_WF = { "1": { "class_type": "CLIPTextEncode", "inputs": {"text": "镜头缓慢推近"}, "_meta": {"title": "(Input:prompt) 正向提示词"}, }, "2": { "class_type": "PrimitiveFloat", "inputs": {"value": 6}, "_meta": {"title": "(Input:duration) 时长"}, }, "9": { "class_type": "VHS_VideoCombine", "inputs": {}, "_meta": {"title": "(Output:video) 视频输出"}, }, } if __name__ == "__main__": # Idempotent: drop same-named workflows and the old fake endpoint first. for w in call("GET", "/api/workflows"): if w["name"] in ("文生图·回归", "文生视频·回归"): call("DELETE", f"/api/workflows/{w['id']}") for e in call("GET", "/api/comfyui/endpoints")["endpoints"]: if e["base_url"] == "http://127.0.0.1:18188": call("DELETE", f"/api/comfyui/endpoints/{e['id']}") r = call( "POST", "/api/comfyui/endpoints", {"name": "假 ComfyUI", "base_url": "http://127.0.0.1:18188", "auth_type": "none"}, ) eps = [e for e in r["endpoints"] if e["base_url"] == "http://127.0.0.1:18188"] call("POST", f"/api/comfyui/endpoints/{eps[0]['id']}/activate") img_id = call( "POST", "/api/workflows", {"name": "文生图·回归", "kind": "image", "workflow_json": IMAGE_WF} )["id"] vid_id = call( "POST", "/api/workflows", {"name": "文生视频·回归", "kind": "video", "workflow_json": VIDEO_WF} )["id"] print(json.dumps({"image_wf": img_id, "video_wf": vid_id, "endpoint": eps[0]["id"]}))