From 326b206d0868a765686861c9ec88134f03a78c48 Mon Sep 17 00:00:00 2001 From: xsl Date: Sun, 26 Jul 2026 16:49:21 +0800 Subject: [PATCH] =?UTF-8?q?feat(swapHair):=20webui=5Fsteps=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E5=8F=AF=E5=A4=96=E9=83=A8=E4=BC=A0=E5=85=A5(?= =?UTF-8?q?=E6=8E=A5=E5=8F=A32=E8=B0=83=E8=AF=95=E9=A1=B5=E5=8F=AF?= =?UTF-8?q?=E8=B0=83)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - gen_super_image.py: webui_img2img + build_body_v2 接收可选 steps 参数 - run_copy_cost_colorb64.py: swapHair 接口接收 webui_steps,透传给 webui_img2img - 未传时保持环境变量 WEBUI_STEPS 默认(15),向后兼容 --- project/hair_service_sd/gen_super_image.py | 8 ++++---- project/hair_service_sd/run_copy_cost_colorb64.py | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/project/hair_service_sd/gen_super_image.py b/project/hair_service_sd/gen_super_image.py index bcc0e6e..30d6839 100644 --- a/project/hair_service_sd/gen_super_image.py +++ b/project/hair_service_sd/gen_super_image.py @@ -84,13 +84,13 @@ class ControlnetRequestImg2Img: return encoded_image - def build_body_v2(self, dst_width, dst_height, cfg_scale, base_img, denoising_strength=0.7): + def build_body_v2(self, dst_width, dst_height, cfg_scale, base_img, denoising_strength=0.7, steps=None): self.body = { "prompt": self.prompt, "negative_prompt": self.neg_prompt, "sampler_name": "DPM++ 2M Karras", "batch_size": 1, - "steps": int(os.environ.get("WEBUI_STEPS", "15")), + "steps": int(steps) if steps is not None else int(os.environ.get("WEBUI_STEPS", "15")), "width": dst_width, "height": dst_height, "cfg_scale": cfg_scale, @@ -414,7 +414,7 @@ def encode_numpy_to_base64(img): encoded_image = base64.b64encode(bytes).decode('utf-8') return encoded_image -def webui_img2img(img=None, mask_img=None, in_gender=None, task_id=None, hair_id=None, lora_material_path=None, tag="", is_hr=False, denoising_strength=0.7, inference_port="57860", refiner_switch_at=0.5): +def webui_img2img(img=None, mask_img=None, in_gender=None, task_id=None, hair_id=None, lora_material_path=None, tag="", is_hr=False, denoising_strength=0.7, inference_port="57860", refiner_switch_at=0.5, webui_steps=None): # url = "http://hairservice.tslead.net:57860/sdapi/v1/img2img" neg_prompt = '(nsfw:1.5), ng_deepnegative_v1_75t, (badhandv4:1.2), (worst quality:2), (low quality:2), (normal quality:2), lowres, bad anatomy, bad hands, ((monochrome)), ((grayscale)) watermark, moles, large breast, big breast, bad_pictures,easynegative' @@ -430,7 +430,7 @@ def webui_img2img(img=None, mask_img=None, in_gender=None, task_id=None, hair_id control_net = ControlnetRequestImg2Img(prompt, neg_prompt, mask_img) # control_net.build_body_hr(dst_width=img.shape[1], dst_height=img.shape[0], cfg_scale=7, base_img=encoded_image, denoising_strength=denoising_strength) if not is_hr: - control_net.build_body_v2(dst_width=img.shape[1], dst_height=img.shape[0], cfg_scale=7, base_img=encoded_image, denoising_strength=denoising_strength) + control_net.build_body_v2(dst_width=img.shape[1], dst_height=img.shape[0], cfg_scale=7, base_img=encoded_image, denoising_strength=denoising_strength, steps=webui_steps) else: control_net.build_body_hr(dst_width=img.shape[1], dst_height=img.shape[0], cfg_scale=7, base_img=encoded_image, denoising_strength=denoising_strength, refiner_switch_at=refiner_switch_at) diff --git a/project/hair_service_sd/run_copy_cost_colorb64.py b/project/hair_service_sd/run_copy_cost_colorb64.py index bd70354..bed0d98 100644 --- a/project/hair_service_sd/run_copy_cost_colorb64.py +++ b/project/hair_service_sd/run_copy_cost_colorb64.py @@ -606,6 +606,8 @@ def change_hairstyle_v4(): else: p_tag = "" denoising_strength = float(input_info.get('denoising_strength', 0.6)) # 接口11 可调;默认 0.6 + webui_steps_raw = input_info.get('webui_steps', None) # 可选:webui img2img 步数,None用服务端默认 + webui_steps = int(webui_steps_raw) if webui_steps_raw is not None else None print(f"功能8:处理发型区域,耗时:{time.time() - start_time:.3f}s") # cv2.imwrite(f"{task_id}_mask_dilate.jpg", mask_dilate) # cv2.imwrite(f"{task_id}_final_img.jpg", final_img) @@ -619,7 +621,7 @@ def change_hairstyle_v4(): # mask_dilate = cv2.imread("/root/project/hair_service_sd/gt_mask_dilate.jpg") sd_result = webui_img2img(img=final_img, mask_img=mask_dilate, in_gender=in_gender, task_id=task_id, hair_id=hair_id, lora_material_path=hair_material_dir, tag=p_tag, is_hr=is_hr, - denoising_strength=denoising_strength, inference_port="57860") + denoising_strength=denoising_strength, inference_port="57860", webui_steps=webui_steps) print(f"功能:webui,耗时:{time.time() - start_time:.3f}s") # 功能:后处理并上传结果