feat(swapHair): webui_steps参数可外部传入(接口2调试页可调)
- gen_super_image.py: webui_img2img + build_body_v2 接收可选 steps 参数 - run_copy_cost_colorb64.py: swapHair 接口接收 webui_steps,透传给 webui_img2img - 未传时保持环境变量 WEBUI_STEPS 默认(15),向后兼容
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
# 功能:后处理并上传结果
|
||||
|
||||
Reference in New Issue
Block a user