comfyui github地址: GitHub - comfyanonymous/ComfyUI: The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface.The most powerful and modular diffusion model GUI, api and backend with a graph/nodes interface. - comfyanonymous/ComfyUIhttps://github.com/comfyanonymous/ComfyUI
github上提供了生成的python代码 ComfyUI/script_examples at master · comfyanonymous/ComfyUI · GitHub
使用提供的案例代码 上传到comfyui服务器上,把prompt换成自己的prompt 等任务完成之后 使用history获取生成的图片结果为空
而使用同样的prompt 在同一个服务上使用web页面生成图片就可以成功, 有大佬碰到过这样的问题吗?
脚步代码如下:
import logging#This is an example that uses the websockets api to know when a prompt execution is done
#Once the prompt execution is done it downloads the images using the /history endpointimport websocket #NOTE: websocket-client (https://github.com/websocket-client/websocket-client)
import uuid
import json
import urllib.request
import urllib.parseserver_address = "127.0.0.1:8188"
client_id = str(uuid.uuid4())def queue_prompt(prompt):p = {"prompt": prompt, "client_id": client_id}data = json.dumps(p).encode('utf-8')req = urllib.request.Request("http://{}/prompt".format(server_address), data=data)return json.loads(urllib.request.urlopen(req).read())def get_image(filename, subfolder, folder_type):data = {"filename": filename, "subfolder": subfolder, "type": folder_type}url_values = urllib.parse.urlencode(data)with urllib.request.urlopen("http://{}/view?{}".format(server_address, url_values)) as response:return response.read()def get_history(prompt_id):with urllib.request.urlopen("http://{}/history/{}".format(server_address, prompt_id)) as response:return json.loads(response.read())def get_history_all():with urllib.request.urlopen("http://{}/history".format(server_address)) as response:return json.loads(response.read())def get_extensions():with urllib.request.urlopen("http://{}/extensions".format(server_address)) as response:return json.loads(response.read())def get_queue():with urllib.request.urlopen("http://{}/queue".format(server_address)) as response:return json.loads(response.read())def get_images(ws, prompt):queue = queue_prompt(prompt)print("queue_prompt, {}".format(queue))prompt_id = queue['prompt_id']output_images = {}while True:out = ws.recv()print("wx接收响应, out: {}".format(out))if isinstance(out, str):message = json.loads(out)if message['type'] == 'executing':data = message['data']if data['node'] is None and data['prompt_id'] == prompt_id:break #Execution is doneelse:# If you want to be able to decode the binary stream for latent previews, here is how you can do it:# bytesIO = BytesIO(out[8:])# preview_image = Image.open(bytesIO) # This is your preview in PIL image format, store it in a globalcontinue #previews are binary datagetHistory = get_history(prompt_id)print("getHistory, gethistory: {}".format(getHistory))history = getHistory[prompt_id]for node_id in history['outputs']:node_output = history['outputs'][node_id]print("node_output, {}".format(node_output))images_output = []if 'images' in node_output:for image in node_output['images']:image_data = get_image(image['filename'], image['subfolder'], image['type'])images_output.append(image_data)output_images[node_id] = images_output# resp = get_extensions()# print('extensions_resp', resp)resp = get_queue()print('queue', resp)historyAll = get_history_all()print('historyAll', historyAll)return output_imagesprompt_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]}}
}
"""test = {"server_address": "127.0.0.1:8188","nas_file_path": "/root/ComfyUI","client_id": "f7fdb85f7b0f435498a348772b8e45b1","record_id": "73","user_type": "1","user_id": "123","output_filename": "1727312980636","oss_file_path": "comfyui_output/portrait/123/","prompt": "{\"22\":{\"class_type\":\"PulidModelLoader\",\"inputs\":{\"pulid_file\":\"ip-adapter_pulid_sdxl_fp16.safetensors\"},\"_meta\":{\"title\":\"PuLID模型加载器\"}},\"44\":{\"class_type\":\"InstantIDModelLoader\",\"inputs\":{\"instantid_file\":\"ip-adapter.bin\"},\"_meta\":{\"title\":\"InstnatID模型加载器\"}},\"88\":{\"class_type\":\"UpscaleModelLoader\",\"inputs\":{\"model_name\":\"4x_NMKD-Siax_200k.pth\"},\"_meta\":{\"title\":\"放大模型加载器\"}},\"23\":{\"class_type\":\"PulidEvaClipLoader\",\"inputs\":{},\"_meta\":{\"title\":\"PuLIDEVAClip加载器\"}},\"45\":{\"class_type\":\"InstantIDFaceAnalysis\",\"inputs\":{\"provider\":\"CPU\"},\"_meta\":{\"title\":\"InstantID面部分析\"}},\"89\":{\"class_type\":\"ImageScaleBy\",\"inputs\":{\"image\":[\"87\",0],\"scale_by\":0.38,\"upscale_method\":\"nearest-exact\"},\"_meta\":{\"title\":\"图像按系数缩放\"}},\"46\":{\"class_type\":\"ControlNetLoader\",\"inputs\":{\"control_net_name\":\"diffusion_pytorch_model.safetensors\"},\"_meta\":{\"title\":\"ControlNet加载器\"}},\"47\":{\"class_type\":\"KSampler (Efficient)\",\"inputs\":{\"vae_decode\":\"true\",\"latent_image\":[\"90\",0],\"seed\":[\"93\",0],\"cfg\":5,\"positive\":[\"43\",1],\"steps\":25,\"script\":[\"75\",0],\"scheduler\":\"karras\",\"negative\":[\"43\",2],\"denoise\":0.58,\"sampler_name\":\"dpmpp_2m_sde\",\"optional_vae\":[\"11\",4],\"preview_method\":\"none\",\"model\":[\"43\",0]},\"_meta\":{\"title\":\"K采样器(效率)\"}},\"29\":{\"class_type\":\"ApplyPulid\",\"inputs\":{\"end_at\":1,\"image\":[\"86\",0],\"pulid\":[\"22\",0],\"method\":\"fidelity\",\"weight\":0.3,\"model\":[\"10\",0],\"eva_clip\":[\"23\",0],\"face_analysis\":[\"76\",0],\"start_at\":0},\"_meta\":{\"title\":\"应用PuLID\"}},\"90\":{\"class_type\":\"VAEEncode\",\"inputs\":{\"pixels\":[\"89\",0],\"vae\":[\"11\",4]},\"_meta\":{\"title\":\"VAE编码\"}},\"92\":{\"class_type\":\"String Literal\",\"inputs\":{\"string\":\"professional,4k,highly detailed,medium portrait soft light, beautiful model,vivid,photorealistic, vivid colors, \",\"speak_and_recognation\":true},\"_meta\":{\"title\":\"String Literal\"}},\"93\":{\"class_type\":\"Seed Generator\",\"inputs\":{\"seed\":1047523952660796},\"_meta\":{\"title\":\"Seed Generator\"}},\"94\":{\"class_type\":\"String Literal\",\"inputs\":{\"string\":\"1man,indoors,business suit,necktie,,upper_body,portrait, \",\"speak_and_recognation\":true},\"_meta\":{\"title\":\"String Literal\"}},\"75\":{\"class_type\":\"Noise Control Script\",\"inputs\":{\"seed\":813662192183951,\"cfg_denoiser\":false,\"add_seed_noise\":false,\"weight\":0.015,\"rng_source\":\"gpu\"},\"_meta\":{\"title\":\"控制噪波\"}},\"10\":{\"class_type\":\"Efficient Loader\",\"inputs\":{\"lora_name\":\"None\",\"weight_interpretation\":\"A1111\",\"batch_size\":2,\"empty_latent_width\":832,\"empty_latent_height\":1216,\"speak_and_recognation\":true,\"token_normalization\":\"mean\",\"lora_stack\":[\"103\",0],\"positive\":[\"99\",0],\"lora_clip_strength\":1,\"ckpt_name\":\"leosamsHelloworldXL_helloworldXL70.safetensors\",\"negative\":\"(worst quality, low quality, blurry, bad eye, wrong hand, bad anatomy, wrong anatomy, open mouth, deformed, distorted, disfigured, cgi, illustration, cartoon, poorly drawn, watermark),nsfw,nipples,flag,american_flag, \",\"lora_model_strength\":1,\"clip_skip\":-1,\"vae_name\":\"Baked VAE\"},\"_meta\":{\"title\":\"效率加载器\"}},\"76\":{\"class_type\":\"PulidInsightFaceLoader\",\"inputs\":{\"provider\":\"CPU\"},\"_meta\":{\"title\":\"PuLIDInsightFace加载器\"}},\"11\":{\"class_type\":\"KSampler (Efficient)\",\"inputs\":{\"vae_decode\":\"true\",\"latent_image\":[\"10\",3],\"seed\":[\"93\",0],\"cfg\":6,\"positive\":[\"10\",1],\"steps\":25,\"script\":[\"75\",0],\"scheduler\":\"karras\",\"negative\":[\"10\",2],\"denoise\":1,\"sampler_name\":\"dpmpp_2m_sde\",\"optional_vae\":[\"10\",4],\"preview_method\":\"none\",\"model\":[\"29\",0]},\"_meta\":{\"title\":\"K采样器(效率)\"}},\"99\":{\"class_type\":\"Text Concatenate\",\"inputs\":{\"delimiter\":\", \",\"text_a\":[\"94\",0],\"clean_whitespace\":\"true\",\"text_c\":[\"92\",0],\"text_b\":[\"100\",0]},\"_meta\":{\"title\":\"文本连锁\"}},\"16\":{\"class_type\":\"LoadImage\",\"inputs\":{\"image\":\"94a506e555b24c20969b19a401825986.png\",\"upload\":\"image\"},\"_meta\":{\"title\":\"加载图像\"}},\"100\":{\"class_type\":\"String Literal\",\"inputs\":{\"string\":\"\",\"speak_and_recognation\":true},\"_meta\":{\"title\":\"String Literal\"}},\"103\":{\"class_type\":\"easy loraStack\",\"inputs\":{\"lora_3_name\":\"None\",\"lora_6_name\":\"None\",\"lora_7_strength\":1,\"lora_9_clip_strength\":1,\"lora_1_strength\":0.6,\"lora_9_model_strength\":1,\"lora_5_model_strength\":1,\"lora_4_clip_strength\":1,\"lora_2_clip_strength\":1,\"lora_4_strength\":1,\"mode\":\"simple\",\"num_loras\":1,\"lora_6_clip_strength\":1,\"lora_8_name\":\"None\",\"lora_7_name\":\"None\",\"lora_8_model_strength\":1,\"lora_5_strength\":1,\"lora_4_name\":\"None\",\"lora_4_model_strength\":1,\"lora_1_name\":\"None\",\"lora_2_strength\":1,\"lora_2_model_strength\":1,\"lora_3_clip_strength\":1,\"lora_8_clip_strength\":1,\"lora_10_model_strength\":1,\"lora_7_model_strength\":1,\"lora_8_strength\":1,\"toggle\":false,\"lora_1_clip_strength\":1,\"lora_2_name\":\"None\",\"lora_10_name\":\"None\",\"lora_10_clip_strength\":1,\"lora_10_strength\":1,\"lora_1_model_strength\":1,\"lora_5_name\":\"None\",\"lora_3_model_strength\":1,\"lora_9_strength\":1,\"lora_3_strength\":1,\"lora_5_clip_strength\":1,\"lora_6_model_strength\":1,\"lora_6_strength\":1,\"lora_7_clip_strength\":1,\"lora_9_name\":\"None\"},\"_meta\":{\"title\":\"简易Lora堆\"}},\"85\":{\"class_type\":\"LayerUtility: SaveImagePlus\",\"inputs\":{\"preview\":false,\"filename_prefix\":\"comfyui\",\"images\":[\"47\",5],\"save_workflow_as_json\":false,\"custom_path\":\"\",\"format\":\"png\",\"meta_data\":false,\"blind_watermark\":\"\",\"timestamp\":\"None\",\"quality\":100},\"_meta\":{\"title\":\"LayerUtility: SaveImage Plus\"}},\"86\":{\"class_type\":\"CropFace\",\"inputs\":{\"image\":[\"16\",0],\"facedetection\":\"retinaface_resnet50\"},\"_meta\":{\"title\":\"裁剪面部\"}},\"43\":{\"class_type\":\"ApplyInstantID\",\"inputs\":{\"instantid\":[\"44\",0],\"end_at\":1,\"image\":[\"86\",0],\"negative\":[\"11\",2],\"control_net\":[\"46\",0],\"insightface\":[\"45\",0],\"image_kps\":[\"89\",0],\"weight\":0.8,\"model\":[\"11\",0],\"positive\":[\"11\",1],\"start_at\":0},\"_meta\":{\"title\":\"应用InstantID\"}},\"87\":{\"class_type\":\"ImageUpscaleWithModel\",\"inputs\":{\"image\":[\"11\",5],\"upscale_model\":[\"88\",0]},\"_meta\":{\"title\":\"图像通过模型放大\"}}}","image_type": "1",}result = json.dumps(test)resultJson = json.loads(result)print('类型', type(resultJson))
print(resultJson)prompt = json.loads(resultJson['prompt'])
#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"] = 5ws = websocket.WebSocket()
ws.connect("ws://{}/ws?clientId={}".format(server_address, client_id))
images = get_images(ws, prompt)
print(images)
ws.close() # for in case this example is used in an environment where it will be repeatedly called, like in a Gradio app. otherwise, you'll randomly receive connection timeouts
#Commented out code to display the output images:# for node_id in images:
# for image_data in images[node_id]:
# from PIL import Image
# import io
# image = Image.open(io.BytesIO(image_data))
# image.show()
自己的prompt如下:
{"22": {"class_type": "PulidModelLoader","inputs": {"pulid_file": "ip-adapter_pulid_sdxl_fp16.safetensors"},"_meta": {"title": "PuLID模型加载器"}},"44": {"class_type": "InstantIDModelLoader","inputs": {"instantid_file": "ip-adapter.bin"},"_meta": {"title": "InstnatID模型加载器"}},"88": {"class_type": "UpscaleModelLoader","inputs": {"model_name": "4x_NMKD-Siax_200k.pth"},"_meta": {"title": "放大模型加载器"}},"23": {"class_type": "PulidEvaClipLoader","inputs": {},"_meta": {"title": "PuLIDEVAClip加载器"}},"45": {"class_type": "InstantIDFaceAnalysis","inputs": {"provider": "CPU"},"_meta": {"title": "InstantID面部分析"}},"89": {"class_type": "ImageScaleBy","inputs": {"image": ["87",0],"scale_by": 0.38,"upscale_method": "nearest-exact"},"_meta": {"title": "图像按系数缩放"}},"46": {"class_type": "ControlNetLoader","inputs": {"control_net_name": "diffusion_pytorch_model.safetensors"},"_meta": {"title": "ControlNet加载器"}},"47": {"class_type": "KSampler (Efficient)","inputs": {"vae_decode": "true","latent_image": ["90",0],"seed": ["93",0],"cfg": 5,"positive": ["43",1],"steps": 25,"script": ["75",0],"scheduler": "karras","negative": ["43",2],"denoise": 0.58,"sampler_name": "dpmpp_2m_sde","optional_vae": ["11",4],"preview_method": "none","model": ["43",0]},"_meta": {"title": "K采样器(效率)"}},"29": {"class_type": "ApplyPulid","inputs": {"end_at": 1,"image": ["86",0],"pulid": ["22",0],"method": "fidelity","weight": 0.3,"model": ["10",0],"eva_clip": ["23",0],"face_analysis": ["76",0],"start_at": 0},"_meta": {"title": "应用PuLID"}},"90": {"class_type": "VAEEncode","inputs": {"pixels": ["89",0],"vae": ["11",4]},"_meta": {"title": "VAE编码"}},"92": {"class_type": "String Literal","inputs": {"string": "professional,4k,highly detailed,medium portrait soft light, beautiful model,vivid,photorealistic, vivid colors, ","speak_and_recognation": true},"_meta": {"title": "String Literal"}},"93": {"class_type": "Seed Generator","inputs": {"seed": 1047523952660796},"_meta": {"title": "Seed Generator"}},"94": {"class_type": "String Literal","inputs": {"string": "1man,indoors,business suit,necktie,,upper_body,portrait, ","speak_and_recognation": true},"_meta": {"title": "String Literal"}},"75": {"class_type": "Noise Control Script","inputs": {"seed": 813662192183951,"cfg_denoiser": false,"add_seed_noise": false,"weight": 0.015,"rng_source": "gpu"},"_meta": {"title": "控制噪波"}},"10": {"class_type": "Efficient Loader","inputs": {"lora_name": "None","weight_interpretation": "A1111","batch_size": 2,"empty_latent_width": 832,"empty_latent_height": 1216,"speak_and_recognation": true,"token_normalization": "mean","lora_stack": ["103",0],"positive": ["99",0],"lora_clip_strength": 1,"ckpt_name": "leosamsHelloworldXL_helloworldXL70.safetensors","negative": "(worst quality, low quality, blurry, bad eye, wrong hand, bad anatomy, wrong anatomy, open mouth, deformed, distorted, disfigured, cgi, illustration, cartoon, poorly drawn, watermark),nsfw,nipples,flag,american_flag, ","lora_model_strength": 1,"clip_skip": -1,"vae_name": "Baked VAE"},"_meta": {"title": "效率加载器"}},"76": {"class_type": "PulidInsightFaceLoader","inputs": {"provider": "CPU"},"_meta": {"title": "PuLIDInsightFace加载器"}},"11": {"class_type": "KSampler (Efficient)","inputs": {"vae_decode": "true","latent_image": ["10",3],"seed": ["93",0],"cfg": 6,"positive": ["10",1],"steps": 25,"script": ["75",0],"scheduler": "karras","negative": ["10",2],"denoise": 1,"sampler_name": "dpmpp_2m_sde","optional_vae": ["10",4],"preview_method": "none","model": ["29",0]},"_meta": {"title": "K采样器(效率)"}},"99": {"class_type": "Text Concatenate","inputs": {"delimiter": ", ","text_a": ["94",0],"clean_whitespace": "true","text_c": ["92",0],"text_b": ["100",0]},"_meta": {"title": "文本连锁"}},"16": {"class_type": "LoadImage","inputs": {"image": "94a506e555b24c20969b19a401825986.png","upload": "image"},"_meta": {"title": "加载图像"}},"100": {"class_type": "String Literal","inputs": {"string": "","speak_and_recognation": true},"_meta": {"title": "String Literal"}},"103": {"class_type": "easy loraStack","inputs": {"lora_3_name": "None","lora_6_name": "None","lora_7_strength": 1,"lora_9_clip_strength": 1,"lora_1_strength": 0.6,"lora_9_model_strength": 1,"lora_5_model_strength": 1,"lora_4_clip_strength": 1,"lora_2_clip_strength": 1,"lora_4_strength": 1,"mode": "simple","num_loras": 1,"lora_6_clip_strength": 1,"lora_8_name": "None","lora_7_name": "None","lora_8_model_strength": 1,"lora_5_strength": 1,"lora_4_name": "None","lora_4_model_strength": 1,"lora_1_name": "None","lora_2_strength": 1,"lora_2_model_strength": 1,"lora_3_clip_strength": 1,"lora_8_clip_strength": 1,"lora_10_model_strength": 1,"lora_7_model_strength": 1,"lora_8_strength": 1,"toggle": false,"lora_1_clip_strength": 1,"lora_2_name": "None","lora_10_name": "None","lora_10_clip_strength": 1,"lora_10_strength": 1,"lora_1_model_strength": 1,"lora_5_name": "None","lora_3_model_strength": 1,"lora_9_strength": 1,"lora_3_strength": 1,"lora_5_clip_strength": 1,"lora_6_model_strength": 1,"lora_6_strength": 1,"lora_7_clip_strength": 1,"lora_9_name": "None"},"_meta": {"title": "简易Lora堆"}},"85": {"class_type": "LayerUtility: SaveImagePlus","inputs": {"preview": false,"filename_prefix": "comfyui","images": ["47",5],"save_workflow_as_json": false,"custom_path": "","format": "png","meta_data": false,"blind_watermark": "","timestamp": "None","quality": 100},"_meta": {"title": "LayerUtility: SaveImage Plus"}},"86": {"class_type": "CropFace","inputs": {"image": ["16",0],"facedetection": "retinaface_resnet50"},"_meta": {"title": "裁剪面部"}},"43": {"class_type": "ApplyInstantID","inputs": {"instantid": ["44",0],"end_at": 1,"image": ["86",0],"negative": ["11",2],"control_net": ["46",0],"insightface": ["45",0],"image_kps": ["89",0],"weight": 0.8,"model": ["11",0],"positive": ["11",1],"start_at": 0},"_meta": {"title": "应用InstantID"}},"87": {"class_type": "ImageUpscaleWithModel","inputs": {"image": ["11",5],"upscale_model": ["88",0]},"_meta": {"title": "图像通过模型放大"}}
}