parent
344db544e7
commit
08b075e7ac
@ -1,92 +0,0 @@
|
||||
import requests
|
||||
import io
|
||||
import base64
|
||||
from PIL import Image
|
||||
import cv2
|
||||
|
||||
def encode_image(image_path):
|
||||
with open(image_path, "rb") as i:
|
||||
b64 = base64.b64encode(i.read())
|
||||
return b64.decode("utf-8")
|
||||
|
||||
url = "http://192.168.1.21:7860"
|
||||
|
||||
prompt = "(8k, RAW photo, highest quality),hyperrealistic abstract style portrait of an otherworldly being with metallic skin,glowing orbs for eyes,and intricate fractal patterns emanating from their face,non-representational,colors and shapes,expression of feelings,imaginative,highly detailed,(pink Fluorescent eyeshadow:1.2),eyeliner,makeup,lipstick,watery eyes,(Mole under eye:1.2),(seductive_smile:1.2),XURE Dunhuang Flying XL,1girl,<lora:绪儿 敦煌飞天XL:0.6>,"
|
||||
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,"
|
||||
|
||||
# 此处为读取一张图片作为输入图像
|
||||
encoded_image = encode_image('../Image/28/1.jpg')
|
||||
encoded_source_image =encode_image('../Image/1ae93e2587822c291362abf9504cb49ec.jpeg')
|
||||
|
||||
payload = {
|
||||
# 模型设置
|
||||
"override_settings": {
|
||||
"sd_model_checkpoint": "绪儿-一青十色XL_V2 VAE.safetensors [9f9290ac66]",
|
||||
"sd_vae": "Automatic"
|
||||
},
|
||||
# 基本参数
|
||||
"prompt": prompt,
|
||||
"negative_prompt": negative_prompt,
|
||||
"steps": 30,
|
||||
"sampler_name": "Euler a",
|
||||
"width": 1024,
|
||||
"height": 1472,
|
||||
"batch_size": 1,
|
||||
"n_iter": 1,
|
||||
"seed": 1,
|
||||
"cfg_scale": 3,
|
||||
"CLIP_stop_at_last_layers": 2,
|
||||
"init_images": [encoded_image],
|
||||
# 面部修复 face fix
|
||||
"restore_faces": False,
|
||||
|
||||
# 高清修复 highres fix
|
||||
# "enable_hr": True,
|
||||
"denoising_strength": 0.5,
|
||||
# "hr_scale": 2,
|
||||
# "hr_upscaler": "Latent",
|
||||
"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": encoded_source_image,
|
||||
"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": encoded_image,
|
||||
"control_mode": "ControlNet is more important"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#payload["alwayson_scripts"]["ControlNet"]["args"][0]["input_image"] = encoded_source_image
|
||||
#payload["alwayson_scripts"]["ControlNet"]["args"][1]["input_image"] = encoded_image
|
||||
|
||||
response = requests.post(url=f'{url}/sdapi/v1/img2img', json=payload)
|
||||
r = response.json()
|
||||
image = Image.open(io.BytesIO(base64.b64decode(r['images'][0])))
|
||||
|
||||
image.show()
|
||||
image.save('output.png')
|
@ -1,33 +1,92 @@
|
||||
from Util import ConfigUtil
|
||||
from Util.CommonUtil import *
|
||||
import requests
|
||||
import io
|
||||
import base64
|
||||
from PIL import Image
|
||||
import cv2
|
||||
|
||||
if __name__ == '__main__':
|
||||
# 配置文件
|
||||
config = ConfigUtil.getConfig()
|
||||
# 图生图服务地址
|
||||
img2img_url = config['webui']['img2img_url']
|
||||
def encode_image(image_path):
|
||||
with open(image_path, "rb") as i:
|
||||
b64 = base64.b64encode(i.read())
|
||||
return b64.decode("utf-8")
|
||||
|
||||
# 用户传的源图
|
||||
source_img = "../Image/1ae93e2587822c291362abf9504cb49ec.jpeg"
|
||||
url = "http://192.168.1.21:7860"
|
||||
|
||||
# 参照图片路径
|
||||
refer_img = "../Image/28/1.jpg"
|
||||
prompt = "(8k, RAW photo, highest quality),hyperrealistic abstract style portrait of an otherworldly being with metallic skin,glowing orbs for eyes,and intricate fractal patterns emanating from their face,non-representational,colors and shapes,expression of feelings,imaginative,highly detailed,(pink Fluorescent eyeshadow:1.2),eyeliner,makeup,lipstick,watery eyes,(Mole under eye:1.2),(seductive_smile:1.2),XURE Dunhuang Flying XL,1girl,<lora:绪儿 敦煌飞天XL:0.6>,"
|
||||
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,"
|
||||
|
||||
# 生成的JSON文件
|
||||
with open("../JSON/28_1.json", 'r', encoding='utf-8') as f:
|
||||
v_data = json.load(f)
|
||||
# 此处为读取一张图片作为输入图像
|
||||
encoded_image = encode_image('../Image/28/1.jpg')
|
||||
encoded_source_image =encode_image('../Image/1ae93e2587822c291362abf9504cb49ec.jpeg')
|
||||
|
||||
# 源图
|
||||
source_image = encode_image(source_img)
|
||||
refer_image = encode_image(refer_img)
|
||||
# https://blog.csdn.net/wangwenzhe222/article/details/139059131
|
||||
# ControlNet
|
||||
#v_data['alwayson_scripts']['ControlNet']['args'][0]['image'] = source_image
|
||||
#v_data['alwayson_scripts']['ControlNet']['args'][1]['image'] = refer_image
|
||||
v_data['init_images'] = [refer_image]
|
||||
payload = {
|
||||
# 模型设置
|
||||
"override_settings": {
|
||||
"sd_model_checkpoint": "绪儿-一青十色XL_V2 VAE.safetensors [9f9290ac66]",
|
||||
"sd_vae": "Automatic"
|
||||
},
|
||||
# 基本参数
|
||||
"prompt": prompt,
|
||||
"negative_prompt": negative_prompt,
|
||||
"steps": 30,
|
||||
"sampler_name": "Euler a",
|
||||
"width": 1024,
|
||||
"height": 1472,
|
||||
"batch_size": 1,
|
||||
"n_iter": 1,
|
||||
"seed": 1,
|
||||
"cfg_scale": 3,
|
||||
"CLIP_stop_at_last_layers": 2,
|
||||
"init_images": [encoded_image],
|
||||
# 面部修复 face fix
|
||||
"restore_faces": False,
|
||||
|
||||
#print(json.dumps(v_data, sort_keys=True, ensure_ascii=False,indent=4)) # 生成可以正确显示中文的json格式输出
|
||||
# 高清修复 highres fix
|
||||
# "enable_hr": True,
|
||||
"denoising_strength": 0.5,
|
||||
# "hr_scale": 2,
|
||||
# "hr_upscaler": "Latent",
|
||||
"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": encoded_source_image,
|
||||
"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": encoded_image,
|
||||
"control_mode": "ControlNet is more important"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response = submit_post(img2img_url, v_data)
|
||||
save_encoded_image(response.json()['images'][0], "../Out/result.png")
|
||||
#payload["alwayson_scripts"]["ControlNet"]["args"][0]["input_image"] = encoded_source_image
|
||||
#payload["alwayson_scripts"]["ControlNet"]["args"][1]["input_image"] = encoded_image
|
||||
|
||||
response = requests.post(url=f'{url}/sdapi/v1/img2img', json=payload)
|
||||
r = response.json()
|
||||
image = Image.open(io.BytesIO(base64.b64decode(r['images'][0])))
|
||||
|
||||
image.show()
|
||||
image.save('output.png')
|
||||
|
Before Width: | Height: | Size: 2.3 MiB After Width: | Height: | Size: 2.3 MiB |
Loading…
Reference in new issue