save code

This commit is contained in:
xsl
2025-08-10 23:07:52 +08:00
parent 30c624e5af
commit 8b55a66079
3 changed files with 984 additions and 4 deletions
+76 -4
View File
@@ -15,6 +15,9 @@ import redis
# from check_img_body import is_thigh_visible
import logging
from config import *
import websockets
import asyncio
import traceback
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
@@ -311,8 +314,75 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, human_url, no2)
prompt_id = response.json()["prompt_id"]
# 2. 轮询队列,直到任务完成
async def listen_node_output(prompt_id, target_node_id):
uri = "ws://localhost:8188/ws"
async with websockets.connect(uri) as websocket:
await websocket.send(json.dumps({"prompt_id": prompt_id}))
while True:
message = await websocket.recv()
# 1. 处理二进制数据
if isinstance(message, bytes):
try:
message = message.decode("utf-8")
except UnicodeDecodeError:
print(f"[{datetime.now().strftime('%H:%M:%S')}] 收到二进制数据 (长度: {len(message)} bytes)")
continue
# 2. 解析JSON
try:
data = json.loads(message)
print(f"cur data {data}")
except json.JSONDecodeError:
print(f"[{datetime.now().strftime('%H:%M:%S')}] 非JSON数据: {message[:100]}...")
continue
if data.get("type") == "progress":
pdata = data.get('data', {})
print(f"cur progress {pdata}")
# if value >= max:
# return f"finished value:{value} max:{max}"
if data.get("type") == "progress_state":
nodes = data.get('data', {}).get('nodes', {})
for node in nodes:
if node.get("state", None) != 'finished':
print(f"progress_state node:{node}")
# 3. 输出运行状态
if data.get("type") == "status":
print(f"[{datetime.now().strftime('%H:%M:%S')}] 系统状态: {data.get('data', {}).get('status', {})}")
status = data.get('data', {}).get('status', None)
print(f"statue:{status}")
if status:
exec_info = status.get('exec_info', None)
print(f"exec_info:{exec_info}")
if exec_info:
queue_remaining = exec_info.get('queue_remaining', None)
print(f"queue_remaining:{queue_remaining}")
if queue_remaining == 0:
return "process end"
continue
if data.get("type") == "executing":
node_id = data.get("data", {}).get("node")
progress = data.get("data", {}).get("progress", 0)
print(f"[{datetime.now().strftime('%H:%M:%S')}] 正在执行节点 {node_id} (进度: {progress:.0%})")
# 4. 目标节点完成
if data.get("type") == "executed" and data.get("data", {}).get("node") == target_node_id:
output = data.get("data", {}).get("output")
print(f"[{datetime.now().strftime('%H:%M:%S')}] 节点 {target_node_id} 完成!")
return output
# 调用方式保持不变
output = asyncio.run(listen_node_output(prompt_id, "104"))
print("最终输出:", output)
while True:
# response = requests.post("http://localhost:8188/interrupt")
queue = requests.get("http://localhost:8188/queue").json()
# print(queue)
if not queue["queue_running"] and not queue["queue_pending"]:
@@ -556,7 +626,9 @@ def do_change_cloth():
try:
return process_change_cloth(human_filename, cloth_filename, output_format, cloth_url, human_url, no2)
except:
except Exception as e:
traceback.print_exc()
print(f"错误详情:{e}")
return jsonify({
"ret":-1,
"state": -1,
@@ -663,7 +735,7 @@ def change_cloth_base64():
return jsonify({"ret":-1, 'msg': 'Failed to save cloth image'}), 500
data['cloth_img'] = None
cloth_url = f"http://112.126.94.241:{remote_port}/static/imgs/{cloth_filename}"
cloth_url = f"http://112.126.94.241:{base64_test_port}/static/imgs/{cloth_filename}"
data["human_url"] = human_url
data["cloth_url"] = cloth_url
@@ -675,7 +747,7 @@ def change_cloth_base64():
# 在内部调用第二个HTTP请求
try:
# 调用第二个API(可以是外部服务或自己的另一个端点)
response = requests.post(f'http://112.126.94.241:{remote_port}/do_change_cloth', json=data)
response = requests.post(f'http://112.126.94.241:{base64_test_port}/do_change_cloth', json=data)
return Response(
response=response.content,
+908
View File
@@ -0,0 +1,908 @@
{
"3": {
"inputs": {
"seed": 953738907275871,
"steps": 20,
"cfg": 1,
"sampler_name": "euler",
"scheduler": "simple",
"denoise": 1,
"model": [
"13",
0
],
"positive": [
"17",
0
],
"negative": [
"17",
1
],
"latent_image": [
"17",
2
]
},
"class_type": "KSampler",
"_meta": {
"title": "KSampler"
}
},
"6": {
"inputs": {
"text": "",
"clip": [
"12",
0
]
},
"class_type": "CLIPTextEncode",
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"7": {
"inputs": {
"text": "",
"clip": [
"12",
0
]
},
"class_type": "CLIPTextEncode",
"_meta": {
"title": "CLIP Text Encode (Prompt)"
}
},
"8": {
"inputs": {
"samples": [
"3",
0
],
"vae": [
"16",
0
]
},
"class_type": "VAEDecode",
"_meta": {
"title": "VAE Decode"
}
},
"10": {
"inputs": {
"strength": 1.0000000000000002,
"strength_type": "multiply",
"conditioning": [
"11",
0
],
"style_model": [
"79",
0
],
"clip_vision_output": [
"20",
0
]
},
"class_type": "StyleModelApply",
"_meta": {
"title": "Apply Style Model"
}
},
"11": {
"inputs": {
"guidance": 30,
"conditioning": [
"6",
0
]
},
"class_type": "FluxGuidance",
"_meta": {
"title": "FluxGuidance"
}
},
"12": {
"inputs": {
"clip_name1": "flux/t5xxl_fp16.safetensors",
"clip_name2": "clip_l.safetensors",
"type": "flux",
"device": "default"
},
"class_type": "DualCLIPLoader",
"_meta": {
"title": "DualCLIPLoader"
}
},
"13": {
"inputs": {
"model": [
"75",
0
]
},
"class_type": "DifferentialDiffusion",
"_meta": {
"title": "Differential Diffusion"
}
},
"16": {
"inputs": {
"vae_name": "ae.safetensors"
},
"class_type": "VAELoader",
"_meta": {
"title": "Load VAE"
}
},
"17": {
"inputs": {
"noise_mask": false,
"positive": [
"10",
0
],
"negative": [
"7",
0
],
"vae": [
"16",
0
],
"pixels": [
"27",
1
],
"mask": [
"27",
2
]
},
"class_type": "InpaintModelConditioning",
"_meta": {
"title": "InpaintModelConditioning"
}
},
"20": {
"inputs": {
"crop": "center",
"clip_vision": [
"21",
0
],
"image": [
"25",
0
]
},
"class_type": "CLIPVisionEncode",
"_meta": {
"title": "CLIP Vision Encode"
}
},
"21": {
"inputs": {
"clip_name": "sigclip_vision_patch14_384.safetensors"
},
"class_type": "CLIPVisionLoader",
"_meta": {
"title": "Load CLIP Vision"
}
},
"22": {
"inputs": {
"image": "微信图片_20250810123345_95.jpg"
},
"class_type": "LoadImage",
"_meta": {
"title": "Load Image"
}
},
"25": {
"inputs": {
"width": [
"94",
0
],
"height": [
"94",
0
],
"interpolation": "nearest",
"method": "keep proportion",
"condition": "always",
"multiple_of": 0,
"image": [
"22",
0
]
},
"class_type": "ImageResize+",
"_meta": {
"title": "🔧 Image Resize"
}
},
"26": {
"inputs": {
"width": [
"94",
0
],
"height": [
"94",
0
],
"interpolation": "nearest",
"method": "keep proportion",
"condition": "always",
"multiple_of": 0,
"image": [
"61",
0
]
},
"class_type": "ImageResize+",
"_meta": {
"title": "🔧 Image Resize"
}
},
"27": {
"inputs": {
"context_expand_pixels": 20,
"context_expand_factor": 1.0000000000000002,
"fill_mask_holes": true,
"blur_mask_pixels": 10,
"invert_mask": false,
"blend_pixels": 16,
"rescale_algorithm": "bicubic",
"mode": "ranged size",
"force_width": 1024,
"force_height": 1024,
"rescale_factor": 1.0000000000000002,
"min_width": 512,
"min_height": 512,
"max_width": 1800,
"max_height": 1800,
"padding": 32,
"image": [
"42",
0
],
"mask": [
"30",
0
],
"optional_context_mask": [
"40",
0
]
},
"class_type": "InpaintCrop",
"_meta": {
"title": "(OLD 💀, use the new ✂️ Inpaint Crop node)"
}
},
"28": {
"inputs": {
"mask": [
"96",
0
]
},
"class_type": "MaskToImage",
"_meta": {
"title": "Convert Mask to Image"
}
},
"29": {
"inputs": {
"width": [
"94",
0
],
"height": [
"94",
0
],
"interpolation": "nearest",
"method": "keep proportion",
"condition": "always",
"multiple_of": 0,
"image": [
"28",
0
]
},
"class_type": "ImageResize+",
"_meta": {
"title": "🔧 Image Resize"
}
},
"30": {
"inputs": {
"channel": "red",
"image": [
"43",
0
]
},
"class_type": "ImageToMask",
"_meta": {
"title": "Convert Image to Mask"
}
},
"34": {
"inputs": {
"rescale_algorithm": "bislerp",
"stitch": [
"27",
0
],
"inpainted_image": [
"8",
0
]
},
"class_type": "InpaintStitch",
"_meta": {
"title": "(OLD 💀, use the new ✂️ Inpaint Stitch node)"
}
},
"37": {
"inputs": {
"direction": "right",
"match_image_size": true,
"image1": [
"38",
0
],
"image2": [
"57",
0
]
},
"class_type": "ImageConcanate",
"_meta": {
"title": "Image Concatenate"
}
},
"38": {
"inputs": {
"mask": [
"71:2",
1
]
},
"class_type": "MaskToImage",
"_meta": {
"title": "Convert Mask to Image"
}
},
"40": {
"inputs": {
"channel": "red",
"image": [
"37",
0
]
},
"class_type": "ImageToMask",
"_meta": {
"title": "Convert Image to Mask"
}
},
"42": {
"inputs": {
"direction": "right",
"match_image_size": true,
"image1": [
"25",
0
],
"image2": [
"26",
0
]
},
"class_type": "ImageConcanate",
"_meta": {
"title": "Image Concatenate"
}
},
"43": {
"inputs": {
"direction": "right",
"match_image_size": true,
"image1": [
"59",
0
],
"image2": [
"29",
0
]
},
"class_type": "ImageConcanate",
"_meta": {
"title": "Image Concatenate"
}
},
"45": {
"inputs": {
"images": [
"42",
0
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
},
"57": {
"inputs": {
"brightness": -1,
"contrast": 0,
"saturation": 0,
"sharpness": 0,
"blur": 0,
"gaussian_blur": 0,
"edge_enhance": 0,
"detail_enhance": "false",
"image": [
"26",
0
]
},
"class_type": "Image Filter Adjustments",
"_meta": {
"title": "Image Filter Adjustments"
}
},
"59": {
"inputs": {
"brightness": -1,
"contrast": 1.0000000000000002,
"saturation": 1.0000000000000002,
"sharpness": 1.0000000000000002,
"blur": 0,
"gaussian_blur": 48.1,
"edge_enhance": 0,
"detail_enhance": "false",
"image": [
"25",
0
]
},
"class_type": "Image Filter Adjustments",
"_meta": {
"title": "Image Filter Adjustments"
}
},
"61": {
"inputs": {
"image": "微信图片_20250809133614_84.jpg"
},
"class_type": "LoadImage",
"_meta": {
"title": "Load Image"
}
},
"75": {
"inputs": {
"model_path": "svdq-fp4_r32-flux.1-fill-dev.safetensors",
"cache_threshold": 0,
"attention": "nunchaku-fp16",
"cpu_offload": "auto",
"device_id": 0,
"data_type": "bfloat16",
"i2f_mode": "enabled"
},
"class_type": "NunchakuFluxDiTLoader",
"_meta": {
"title": "Nunchaku FLUX DiT Loader"
}
},
"79": {
"inputs": {
"style_model_name": "flux1-redux-dev.safetensors"
},
"class_type": "StyleModelLoader",
"_meta": {
"title": "Load Style Model"
}
},
"83": {
"inputs": {
"images": [
"29",
0
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
},
"84": {
"inputs": {
"images": [
"43",
0
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
},
"85": {
"inputs": {
"mask": [
"30",
0
]
},
"class_type": "MaskPreview",
"_meta": {
"title": "MaskPreview"
}
},
"86": {
"inputs": {
"mask": [
"71:2",
1
]
},
"class_type": "MaskPreview+",
"_meta": {
"title": "🔧 Mask Preview"
}
},
"87": {
"inputs": {
"images": [
"38",
0
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
},
"88": {
"inputs": {
"images": [
"37",
0
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
},
"89": {
"inputs": {
"images": [
"57",
0
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
},
"90": {
"inputs": {
"images": [
"59",
0
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
},
"91": {
"inputs": {
"images": [
"27",
1
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
},
"93": {
"inputs": {
"mask": [
"27",
2
]
},
"class_type": "MaskPreview",
"_meta": {
"title": "MaskPreview"
}
},
"94": {
"inputs": {
"value": 2048
},
"class_type": "PrimitiveInt",
"_meta": {
"title": "Int"
}
},
"95": {
"inputs": {
"detect_hand": "disable",
"detect_body": "enable",
"detect_face": "disable",
"resolution": 512,
"bbox_detector": "yolo_nas_m_fp16.onnx",
"pose_estimator": "dw-ll_ucoco_384.onnx",
"scale_stick_for_xinsr_cn": "disable",
"image": [
"61",
0
]
},
"class_type": "DWPreprocessor",
"_meta": {
"title": "DWPose Estimator"
}
},
"96": {
"inputs": {
"cloth_len": "腰",
"line_len": 0.4000000000000001,
"cloth_short": true,
"kps": [
"95",
1
]
},
"class_type": "RenderPeopleKpsMask",
"_meta": {
"title": "My RenderPeopleKps Mask"
}
},
"98": {
"inputs": {
"mask": [
"96",
0
]
},
"class_type": "MaskPreview",
"_meta": {
"title": "MaskPreview"
}
},
"99": {
"inputs": {
"width": [
"108",
0
],
"height": [
"107",
1
],
"x": [
"109",
0
],
"y": 0,
"image": [
"34",
0
]
},
"class_type": "ImageCrop",
"_meta": {
"title": "Image Crop"
}
},
"102": {
"inputs": {
"filename_prefix": "my_test_out",
"images": [
"99",
0
]
},
"class_type": "SaveImage",
"_meta": {
"title": "Save Image"
}
},
"104": {
"inputs": {
"image": [
"61",
0
]
},
"class_type": "GetImageSize",
"_meta": {
"title": "Get Image Size"
}
},
"106": {
"inputs": {
"op": "Mul",
"a": [
"107",
1
],
"b": [
"104",
0
]
},
"class_type": "CM_IntBinaryOperation",
"_meta": {
"title": "IntBinaryOperation"
}
},
"107": {
"inputs": {
"image": [
"34",
0
]
},
"class_type": "GetImageSize",
"_meta": {
"title": "Get Image Size"
}
},
"108": {
"inputs": {
"op": "Div",
"a": [
"106",
0
],
"b": [
"104",
1
]
},
"class_type": "CM_IntBinaryOperation",
"_meta": {
"title": "IntBinaryOperation"
}
},
"109": {
"inputs": {
"op": "Sub",
"a": [
"107",
0
],
"b": [
"108",
0
]
},
"class_type": "CM_IntBinaryOperation",
"_meta": {
"title": "IntBinaryOperation"
}
},
"119": {
"inputs": {
"anything": [
"10",
0
]
},
"class_type": "easy cleanGpuUsed",
"_meta": {
"title": "Clean VRAM Used"
}
},
"120": {
"inputs": {
"anything": [
"10",
0
]
},
"class_type": "easy clearCacheAll",
"_meta": {
"title": "Clear Cache All"
}
},
"124": {
"inputs": {
"images": [
"95",
0
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
},
"128": {
"inputs": {
"mask": [
"96",
0
]
},
"class_type": "MaskPreview",
"_meta": {
"title": "MaskPreview"
}
},
"71:1": {
"inputs": {
"model_name": "GroundingDINO_SwinT_OGC (694MB)"
},
"class_type": "GroundingDinoModelLoader (segment anything)",
"_meta": {
"title": "GroundingDinoModelLoader (segment anything)"
}
},
"71:0": {
"inputs": {
"model_name": "sam_vit_h (2.56GB)"
},
"class_type": "SAMModelLoader (segment anything)",
"_meta": {
"title": "SAMModelLoader (segment anything)"
}
},
"71:2": {
"inputs": {
"prompt": "cloth",
"threshold": 0.30000000000000004,
"sam_model": [
"71:0",
0
],
"grounding_dino_model": [
"71:1",
0
],
"image": [
"25",
0
]
},
"class_type": "GroundingDinoSAMSegment (segment anything)",
"_meta": {
"title": "GroundingDinoSAMSegment (segment anything)"
}
},
"71:3": {
"inputs": {
"images": [
"71:2",
0
]
},
"class_type": "PreviewImage",
"_meta": {
"title": "Preview Image"
}
}
}
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB