diff --git a/BaiHu/Image/10/1.jpg b/BaiHu/Image/10/1.jpg new file mode 100644 index 00000000..ad755840 Binary files /dev/null and b/BaiHu/Image/10/1.jpg differ diff --git a/BaiHu/Image/10/2.jpg b/BaiHu/Image/10/2.jpg new file mode 100644 index 00000000..9906d0f2 Binary files /dev/null and b/BaiHu/Image/10/2.jpg differ diff --git a/BaiHu/Image/10/3.jpg b/BaiHu/Image/10/3.jpg new file mode 100644 index 00000000..cdfffd06 Binary files /dev/null and b/BaiHu/Image/10/3.jpg differ diff --git a/BaiHu/Image/10/4.jpg b/BaiHu/Image/10/4.jpg new file mode 100644 index 00000000..2efec293 Binary files /dev/null and b/BaiHu/Image/10/4.jpg differ diff --git a/BaiHu/Image/10/5.jpg b/BaiHu/Image/10/5.jpg new file mode 100644 index 00000000..9c57fe83 Binary files /dev/null and b/BaiHu/Image/10/5.jpg differ diff --git a/BaiHu/JSON/10.json b/BaiHu/JSON/10.json deleted file mode 100644 index a535b375..00000000 --- a/BaiHu/JSON/10.json +++ /dev/null @@ -1,61 +0,0 @@ -{ - "model_name": "古风汉服", - "memo": "【半身】", - "pose_image": "./Image/model_10_controllnet.png", - "denoising_strength": 0, - "prompts": [ - "(photorealistic, best quality, ultra high res, extremely detailed eyes and face:1.3),(1girl, solo:1.3),skirt,jewelry,long_hair,necklace,earrings,perfect body,standing,large breasts,looking at viewer,chinese clothes,china dress,hanfu," - ], - "negative_prompt": "NSFW,blurry,low quality,watermark,monochrome,badhandv4,easynegative,ng_deepnegative_v1_75t,bad proportions,mutated hands and fingers,poorly drawn face,extra limb,missing limb,malformed limbs,disconnected limbs,ugly,floating limbs,extra legs,mutation,bad body,long neck,cross-eyed,text,Multiple people,cleavage,", - "seed": -1, - "sampler_name": "DPM++ 2M Karras", - "cfg_scale": 7, - "width": 1024, - "height": 1368, - "batch_size": 1, - "n_iter": 1, - "steps": 30, - "return_grid": true, - "send_images": true, - "save_images": false, - "do_not_save_samples": false, - "do_not_save_grid": false, - "override_settings": { - "sd_model_checkpoint": "SDXL古风汉服MAX_v1.0.safetensors [ba140e252c]", - "sd_vae": "Automatic" - }, - "alwayson_scripts": { - "ControlNet": { - "args": [ - { - "enabled": true, - "model": "ip-adapter_instant_id_sdxl [eb2d3ec0]", - "module": "instant_id_face_embedding", - "weight": 1, - "resize_mode": "Crop and Resize", - "guidance_start": 0, - "guidance_end": 1, - "pixel_perfect": true, - "processor_res": 512, - "save_detected_map": false, - "input_image": "{{input_image1}}", - "control_mode": "Balanced" - }, - { - "enabled": true, - "model": "control_instant_id_sdxl [c5c25a50]", - "module": "instant_id_face_keypoints", - "weight": 0.65, - "resize_mode": "Crop and Resize", - "guidance_start": 0, - "guidance_end": 1, - "pixel_perfect": true, - "processor_res": 512, - "save_detected_map": false, - "input_image": "{{input_image2}}", - "control_mode": "ControlNet is more important" - } - ] - } - } -} \ No newline at end of file diff --git a/BaiHu/JSON/10_1.json b/BaiHu/JSON/10_1.json new file mode 100644 index 00000000..781b85a2 --- /dev/null +++ b/BaiHu/JSON/10_1.json @@ -0,0 +1,57 @@ +{ + "override_settings": { + "sd_model_checkpoint": "SDXL古风汉服MAX_v1.0.safetensors [ba140e252c]", + "sd_vae": "Automatic" + }, + "prompt": "(photorealistic, best quality, ultra high res, extremely detailed eyes and face:1.3),(1girl, solo:1.3),skirt,jewelry,long_hair,necklace,earrings,perfect body,standing,large breasts,looking at viewer,chinese clothes,china dress,hanfu,", + "negative_prompt": "NSFW,blurry,low quality,watermark,monochrome,badhandv4,easynegative,ng_deepnegative_v1_75t,bad proportions,mutated hands and fingers,poorly drawn face,extra limb,missing limb,malformed limbs,disconnected limbs,ugly,floating limbs,extra legs,mutation,bad body,long neck,cross-eyed,text,cleavage,", + "steps": 25, + "sampler_name": "DPM++ 2M Karras", + "width": 1024, + "height": 1472, + "batch_size": 1, + "n_iter": 1, + "seed": 1, + "cfg_scale": 7, + "CLIP_stop_at_last_layers": 2, + "init_images": [ + "string" + ], + "restore_faces": false, + "enable_hr": true, + "denoising_strength": 0.5, + "alwayson_scripts": { + "ControlNet": { + "args": [ + { + "enabled": true, + "model": "ip-adapter_instant_id_sdxl [eb2d3ec0]", + "module": "instant_id_face_embedding", + "weight": 1, + "resize_mode": "Crop and Resize", + "guidance_start": 0, + "guidance_end": 1, + "pixel_perfect": true, + "processor_res": 512, + "save_detected_map": true, + "input_image": "string", + "control_mode": "My prompt is more important" + }, + { + "enabled": true, + "model": "control_instant_id_sdxl [c5c25a50]", + "module": "instant_id_face_keypoints", + "weight": 1, + "resize_mode": "Crop and Resize", + "guidance_start": 0, + "guidance_end": 1, + "pixel_perfect": true, + "processor_res": 512, + "save_detected_map": true, + "input_image": "string", + "control_mode": "ControlNet is more important" + } + ] + } + } +} \ No newline at end of file diff --git a/BaiHu/JSON/10_2.json b/BaiHu/JSON/10_2.json new file mode 100644 index 00000000..781b85a2 --- /dev/null +++ b/BaiHu/JSON/10_2.json @@ -0,0 +1,57 @@ +{ + "override_settings": { + "sd_model_checkpoint": "SDXL古风汉服MAX_v1.0.safetensors [ba140e252c]", + "sd_vae": "Automatic" + }, + "prompt": "(photorealistic, best quality, ultra high res, extremely detailed eyes and face:1.3),(1girl, solo:1.3),skirt,jewelry,long_hair,necklace,earrings,perfect body,standing,large breasts,looking at viewer,chinese clothes,china dress,hanfu,", + "negative_prompt": "NSFW,blurry,low quality,watermark,monochrome,badhandv4,easynegative,ng_deepnegative_v1_75t,bad proportions,mutated hands and fingers,poorly drawn face,extra limb,missing limb,malformed limbs,disconnected limbs,ugly,floating limbs,extra legs,mutation,bad body,long neck,cross-eyed,text,cleavage,", + "steps": 25, + "sampler_name": "DPM++ 2M Karras", + "width": 1024, + "height": 1472, + "batch_size": 1, + "n_iter": 1, + "seed": 1, + "cfg_scale": 7, + "CLIP_stop_at_last_layers": 2, + "init_images": [ + "string" + ], + "restore_faces": false, + "enable_hr": true, + "denoising_strength": 0.5, + "alwayson_scripts": { + "ControlNet": { + "args": [ + { + "enabled": true, + "model": "ip-adapter_instant_id_sdxl [eb2d3ec0]", + "module": "instant_id_face_embedding", + "weight": 1, + "resize_mode": "Crop and Resize", + "guidance_start": 0, + "guidance_end": 1, + "pixel_perfect": true, + "processor_res": 512, + "save_detected_map": true, + "input_image": "string", + "control_mode": "My prompt is more important" + }, + { + "enabled": true, + "model": "control_instant_id_sdxl [c5c25a50]", + "module": "instant_id_face_keypoints", + "weight": 1, + "resize_mode": "Crop and Resize", + "guidance_start": 0, + "guidance_end": 1, + "pixel_perfect": true, + "processor_res": 512, + "save_detected_map": true, + "input_image": "string", + "control_mode": "ControlNet is more important" + } + ] + } + } +} \ No newline at end of file diff --git a/BaiHu/JSON/10_3.json b/BaiHu/JSON/10_3.json new file mode 100644 index 00000000..781b85a2 --- /dev/null +++ b/BaiHu/JSON/10_3.json @@ -0,0 +1,57 @@ +{ + "override_settings": { + "sd_model_checkpoint": "SDXL古风汉服MAX_v1.0.safetensors [ba140e252c]", + "sd_vae": "Automatic" + }, + "prompt": "(photorealistic, best quality, ultra high res, extremely detailed eyes and face:1.3),(1girl, solo:1.3),skirt,jewelry,long_hair,necklace,earrings,perfect body,standing,large breasts,looking at viewer,chinese clothes,china dress,hanfu,", + "negative_prompt": "NSFW,blurry,low quality,watermark,monochrome,badhandv4,easynegative,ng_deepnegative_v1_75t,bad proportions,mutated hands and fingers,poorly drawn face,extra limb,missing limb,malformed limbs,disconnected limbs,ugly,floating limbs,extra legs,mutation,bad body,long neck,cross-eyed,text,cleavage,", + "steps": 25, + "sampler_name": "DPM++ 2M Karras", + "width": 1024, + "height": 1472, + "batch_size": 1, + "n_iter": 1, + "seed": 1, + "cfg_scale": 7, + "CLIP_stop_at_last_layers": 2, + "init_images": [ + "string" + ], + "restore_faces": false, + "enable_hr": true, + "denoising_strength": 0.5, + "alwayson_scripts": { + "ControlNet": { + "args": [ + { + "enabled": true, + "model": "ip-adapter_instant_id_sdxl [eb2d3ec0]", + "module": "instant_id_face_embedding", + "weight": 1, + "resize_mode": "Crop and Resize", + "guidance_start": 0, + "guidance_end": 1, + "pixel_perfect": true, + "processor_res": 512, + "save_detected_map": true, + "input_image": "string", + "control_mode": "My prompt is more important" + }, + { + "enabled": true, + "model": "control_instant_id_sdxl [c5c25a50]", + "module": "instant_id_face_keypoints", + "weight": 1, + "resize_mode": "Crop and Resize", + "guidance_start": 0, + "guidance_end": 1, + "pixel_perfect": true, + "processor_res": 512, + "save_detected_map": true, + "input_image": "string", + "control_mode": "ControlNet is more important" + } + ] + } + } +} \ No newline at end of file diff --git a/BaiHu/JSON/10_4.json b/BaiHu/JSON/10_4.json new file mode 100644 index 00000000..781b85a2 --- /dev/null +++ b/BaiHu/JSON/10_4.json @@ -0,0 +1,57 @@ +{ + "override_settings": { + "sd_model_checkpoint": "SDXL古风汉服MAX_v1.0.safetensors [ba140e252c]", + "sd_vae": "Automatic" + }, + "prompt": "(photorealistic, best quality, ultra high res, extremely detailed eyes and face:1.3),(1girl, solo:1.3),skirt,jewelry,long_hair,necklace,earrings,perfect body,standing,large breasts,looking at viewer,chinese clothes,china dress,hanfu,", + "negative_prompt": "NSFW,blurry,low quality,watermark,monochrome,badhandv4,easynegative,ng_deepnegative_v1_75t,bad proportions,mutated hands and fingers,poorly drawn face,extra limb,missing limb,malformed limbs,disconnected limbs,ugly,floating limbs,extra legs,mutation,bad body,long neck,cross-eyed,text,cleavage,", + "steps": 25, + "sampler_name": "DPM++ 2M Karras", + "width": 1024, + "height": 1472, + "batch_size": 1, + "n_iter": 1, + "seed": 1, + "cfg_scale": 7, + "CLIP_stop_at_last_layers": 2, + "init_images": [ + "string" + ], + "restore_faces": false, + "enable_hr": true, + "denoising_strength": 0.5, + "alwayson_scripts": { + "ControlNet": { + "args": [ + { + "enabled": true, + "model": "ip-adapter_instant_id_sdxl [eb2d3ec0]", + "module": "instant_id_face_embedding", + "weight": 1, + "resize_mode": "Crop and Resize", + "guidance_start": 0, + "guidance_end": 1, + "pixel_perfect": true, + "processor_res": 512, + "save_detected_map": true, + "input_image": "string", + "control_mode": "My prompt is more important" + }, + { + "enabled": true, + "model": "control_instant_id_sdxl [c5c25a50]", + "module": "instant_id_face_keypoints", + "weight": 1, + "resize_mode": "Crop and Resize", + "guidance_start": 0, + "guidance_end": 1, + "pixel_perfect": true, + "processor_res": 512, + "save_detected_map": true, + "input_image": "string", + "control_mode": "ControlNet is more important" + } + ] + } + } +} \ No newline at end of file diff --git a/BaiHu/JSON/10_5.json b/BaiHu/JSON/10_5.json new file mode 100644 index 00000000..781b85a2 --- /dev/null +++ b/BaiHu/JSON/10_5.json @@ -0,0 +1,57 @@ +{ + "override_settings": { + "sd_model_checkpoint": "SDXL古风汉服MAX_v1.0.safetensors [ba140e252c]", + "sd_vae": "Automatic" + }, + "prompt": "(photorealistic, best quality, ultra high res, extremely detailed eyes and face:1.3),(1girl, solo:1.3),skirt,jewelry,long_hair,necklace,earrings,perfect body,standing,large breasts,looking at viewer,chinese clothes,china dress,hanfu,", + "negative_prompt": "NSFW,blurry,low quality,watermark,monochrome,badhandv4,easynegative,ng_deepnegative_v1_75t,bad proportions,mutated hands and fingers,poorly drawn face,extra limb,missing limb,malformed limbs,disconnected limbs,ugly,floating limbs,extra legs,mutation,bad body,long neck,cross-eyed,text,cleavage,", + "steps": 25, + "sampler_name": "DPM++ 2M Karras", + "width": 1024, + "height": 1472, + "batch_size": 1, + "n_iter": 1, + "seed": 1, + "cfg_scale": 7, + "CLIP_stop_at_last_layers": 2, + "init_images": [ + "string" + ], + "restore_faces": false, + "enable_hr": true, + "denoising_strength": 0.5, + "alwayson_scripts": { + "ControlNet": { + "args": [ + { + "enabled": true, + "model": "ip-adapter_instant_id_sdxl [eb2d3ec0]", + "module": "instant_id_face_embedding", + "weight": 1, + "resize_mode": "Crop and Resize", + "guidance_start": 0, + "guidance_end": 1, + "pixel_perfect": true, + "processor_res": 512, + "save_detected_map": true, + "input_image": "string", + "control_mode": "My prompt is more important" + }, + { + "enabled": true, + "model": "control_instant_id_sdxl [c5c25a50]", + "module": "instant_id_face_keypoints", + "weight": 1, + "resize_mode": "Crop and Resize", + "guidance_start": 0, + "guidance_end": 1, + "pixel_perfect": true, + "processor_res": 512, + "save_detected_map": true, + "input_image": "string", + "control_mode": "ControlNet is more important" + } + ] + } + } +} \ No newline at end of file diff --git a/BaiHu/Temp/71bd1803-2c07-085b-3fbd-fee73700af5a.jpg b/BaiHu/Temp/71bd1803-2c07-085b-3fbd-fee73700af5a.jpg new file mode 100644 index 00000000..eadcf4e2 Binary files /dev/null and b/BaiHu/Temp/71bd1803-2c07-085b-3fbd-fee73700af5a.jpg differ diff --git a/BaiHu/Test/TestImg2Img.py b/BaiHu/Test/TestImg2Img.py index 806d12f0..62dea920 100644 --- a/BaiHu/Test/TestImg2Img.py +++ b/BaiHu/Test/TestImg2Img.py @@ -7,5 +7,36 @@ input_source_img = '../Image/1ae93e2587822c291362abf9504cb49ec.jpeg' # 输出图片 output_file = "../Out/Result.png" + +# 图生图函数 +def img2img(url,model_id, prompt_id, input_source_img, output_file): + # JSON文件模板 + templet_file = r'../JSON/' + str(model_id) + '_' + str(prompt_id) + '.json' + # 模型图片 + input_refer_img = '../Image/' + str(model_id) + '/' + str(prompt_id) + '.jpg' + + # 读取JSON文件 + with open(templet_file, 'r', encoding='utf-8') as file: + payload = json.load(file) + + # 用户输入的图片 + source_img = encode_image(input_source_img) + # 模型固定的参考图片 + refer_img = encode_image(input_refer_img) + + # 在ControlNet的第一个图片中使用用户输入的图片,用此图片的人脸进行换脸操作 + payload["alwayson_scripts"]["ControlNet"]["args"][0]["input_image"] = source_img + # 图生图,风格参考图是输入 + payload["init_images"] = [refer_img] + payload["alwayson_scripts"]["ControlNet"]["args"][1]["input_image"] = refer_img + # 调用SD服务 + response = requests.post(url=f'{url}/sdapi/v1/img2img', json=payload) + if response.status_code != 200: + print(response.text) + exit(0) + r = response.json() + # 保存图片 + save_encoded_image(response.json()['images'][0], output_file) + # 调用图生图 img2img(url, 28, 1, input_source_img, output_file) diff --git a/BaiHu/Util/CommonUtil.py b/BaiHu/Util/CommonUtil.py index b31b7031..db2b7096 100644 --- a/BaiHu/Util/CommonUtil.py +++ b/BaiHu/Util/CommonUtil.py @@ -104,33 +104,3 @@ def split_4_image(image_path, out_path): return res - -# 图生图函数 -def img2img(url,model_id, prompt_id, input_source_img, output_file): - # JSON文件模板 - templet_file = r'../JSON/' + str(model_id) + '_' + str(prompt_id) + '.json' - # 模型图片 - input_refer_img = '../Image/' + str(model_id) + '/' + str(prompt_id) + '.jpg' - - # 读取JSON文件 - with open(templet_file, 'r', encoding='utf-8') as file: - payload = json.load(file) - - # 用户输入的图片 - source_img = encode_image(input_source_img) - # 模型固定的参考图片 - refer_img = encode_image(input_refer_img) - - # 在ControlNet的第一个图片中使用用户输入的图片,用此图片的人脸进行换脸操作 - payload["alwayson_scripts"]["ControlNet"]["args"][0]["input_image"] = source_img - # 图生图,风格参考图是输入 - payload["init_images"] = [refer_img] - payload["alwayson_scripts"]["ControlNet"]["args"][1]["input_image"] = refer_img - # 调用SD服务 - response = requests.post(url=f'{url}/sdapi/v1/img2img', json=payload) - if response.status_code != 200: - print(response.text) - exit(0) - r = response.json() - # 保存图片 - save_encoded_image(response.json()['images'][0], output_file) \ No newline at end of file diff --git a/BaiHu/Util/__pycache__/CommonUtil.cpython-310.pyc b/BaiHu/Util/__pycache__/CommonUtil.cpython-310.pyc index d7e9bb6e..16481382 100644 Binary files a/BaiHu/Util/__pycache__/CommonUtil.cpython-310.pyc and b/BaiHu/Util/__pycache__/CommonUtil.cpython-310.pyc differ diff --git a/BaiHu/doTask.py b/BaiHu/doTask.py index 33aa269f..9de5fadb 100644 --- a/BaiHu/doTask.py +++ b/BaiHu/doTask.py @@ -64,26 +64,33 @@ def webui_txt_2_img(model_id, json_data, input_image): # 图生图服务调用 -def webui_img_2_img(model_id, json_data, input_image): +def webui_img_2_img(model_id, prompt_id, json_data, input_image): # 提示词 prompt = json_data['prompt'] # 图片 - args = json_data['alwayson_scripts']['ControlNet']['args'] - pose_image = json_data['pose_image'] - args[0]['input_image'] = encode_image(input_image[0]) - # 如果有特殊的姿态要求,那就用模板指定的姿态图 - if len(pose_image) > 0: - if len(args) > 1: - args[1]['input_image'] = encode_image(pose_image) - else: # 如果没有特殊的姿态要求,那么就统一用一张图片 - if len(args) > 1: - args[1]['input_image'] = encode_image(input_image[0]) + # 用户输入的图片 + source_img = encode_image(input_image[0]) + # 模型固定的参考图片 + refer_source_img = r'./Image/' + str(model_id) + '/' + str(prompt_id) + '.jpg' + if not os.path.exists(refer_source_img): + refer_source_img = r'./Image/' + str(model_id) + '/' + str(prompt_id) + '.png' + # 都找不到,报错 + if not os.path.exists(refer_source_img): + print("模型:" + str(model_id) + ",参考图:" + str(prompt_id) + "不存在,请检查!") + exit(0) + + # 找到参考图 + refer_img = encode_image(refer_source_img) + + # 在ControlNet的第一个图片中使用用户输入的图片,用此图片的人脸进行换脸操作 + json_data["alwayson_scripts"]["ControlNet"]["args"][0]["input_image"] = source_img + # 图生图,风格参考图是输入 + json_data["init_images"] = [refer_img] + json_data["alwayson_scripts"]["ControlNet"]["args"][1]["input_image"] = refer_img # 宽度与高度 width = json_data['width'] height = json_data['height'] - # 提示词 - json_data['prompt'] = prompt # 开始生成图片 printf("开始生成图片...") @@ -268,7 +275,7 @@ def get_task(): vjson_data = json.load(file) # 利用三元表达式输出 - printf("发现需要处理的" + ("WebUI" if model_type_id == 1 else "ComfyUI") + "任务,model_id=" + str( + printf("发现需要处理的" + ("WebUI" if model_type_id in [1, 3] else "ComfyUI") + "任务,model_id=" + str( model_id) + ",task_id=" + str(task_id)) # SD_TXT2IMG @@ -283,7 +290,7 @@ def get_task(): # SD_IMG2IMG if model_type_id == 3: - webui_img_2_img(model_id=model_id, json_data=vjson_data, input_image=input_image) + webui_img_2_img(model_id=model_id, prompt_id=prompt_id, json_data=vjson_data, input_image=input_image) return task_id elif success == 0: