even better comfyui handling, dynamic node ids

This commit is contained in:
Concedo 2025-05-03 11:21:22 +08:00
parent 6cb36ce1ae
commit 1228f91ccb

View file

@ -1495,31 +1495,26 @@ def sd_load_model(model_filename,vae_filename,lora_filename,t5xxl_filename,clipl
def sd_comfyui_tranform_params(genparams): def sd_comfyui_tranform_params(genparams):
promptobj = genparams.get('prompt', None) promptobj = genparams.get('prompt', None)
if promptobj and isinstance(promptobj, dict): if promptobj and isinstance(promptobj, dict):
temp = promptobj.get('3', {})
temp = temp.get('inputs', {})
genparams["seed"] = temp.get("seed", -1)
genparams["steps"] = temp.get("steps", 20)
genparams["cfg_scale"] = temp.get("cfg", 5)
genparams["sampler_name"] = temp.get("sampler_name", "euler")
temp = promptobj.get('5', {})
temp = temp.get('inputs', {})
genparams["width"] = temp.get("width", 512)
genparams["height"] = temp.get("height", 512)
temp = promptobj.get('6', {})
temp = temp.get('inputs', {})
genparams["prompt"] = temp.get("text", "")
temp = promptobj.get('7', {})
temp = temp.get('inputs', {})
genparams["negative_prompt"] = temp.get("text", "")
#okay, if the prompt is empty something likely went wrong. try find the prompt node dynamically
if genparams.get("prompt","")=="":
for node_id, node_data in promptobj.items(): for node_id, node_data in promptobj.items():
class_type = node_data.get("class_type","") class_type = node_data.get("class_type","")
if class_type == "KSampler" or class_type == "KSamplerAdvanced": if class_type == "KSampler" or class_type == "KSamplerAdvanced":
inp = node_data.get("inputs",{}) inp = node_data.get("inputs",{})
pos = inp.get("positive",[])
neg = inp.get("negative",[]) # sampler settings from this node
genparams["seed"] = inp.get("seed", -1)
genparams["steps"] = inp.get("steps", 20)
genparams["cfg_scale"] = inp.get("cfg", 5)
genparams["sampler_name"] = inp.get("sampler_name", "euler")
pos = inp.get("positive",[]) #positive prompt node
neg = inp.get("negative",[]) #negative prompt node
imgsize = inp.get("latent_image",[]) #image size node
if imgsize and isinstance(imgsize, list) and len(imgsize) > 0:
temp = promptobj.get(str(imgsize[0]), {})
temp = temp.get('inputs', {})
genparams["width"] = temp.get("width", 512)
genparams["height"] = temp.get("height", 512)
if neg and isinstance(neg, list) and len(neg) > 0: if neg and isinstance(neg, list) and len(neg) > 0:
temp = promptobj.get(str(neg[0]), {}) temp = promptobj.get(str(neg[0]), {})
temp = temp.get('inputs', {}) temp = temp.get('inputs', {})