diff --git a/BaiHu/Test/TestImg2Img.py b/BaiHu/Test/TestImg2Img.py index 3f7469a4..eaadbf90 100644 --- a/BaiHu/Test/TestImg2Img.py +++ b/BaiHu/Test/TestImg2Img.py @@ -2,21 +2,24 @@ 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" +# API地址 +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,," +# 反向提示词 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') +encoded_source_image = encode_image('../Image/1ae93e2587822c291362abf9504cb49ec.jpeg') payload = { # 模型设置 @@ -27,8 +30,8 @@ payload = { # 基本参数 "prompt": prompt, "negative_prompt": negative_prompt, - "steps": 30, - "sampler_name": "Euler a", + "steps": 20, + "sampler_name": "DPM++ 2M Karras", "width": 1024, "height": 1472, "batch_size": 1, @@ -39,12 +42,9 @@ payload = { "init_images": [encoded_image], # 面部修复 face fix "restore_faces": False, - # 高清修复 highres fix - # "enable_hr": True, + "enable_hr": True, "denoising_strength": 0.5, - # "hr_scale": 2, - # "hr_upscaler": "Latent", "alwayson_scripts": { "ControlNet": { "args": [ @@ -81,9 +81,6 @@ payload = { } } -#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]))) diff --git a/BaiHu/Test/output.png b/BaiHu/Test/output.png index a08e627f..686f0249 100644 Binary files a/BaiHu/Test/output.png and b/BaiHu/Test/output.png differ