parent
ac65adc72b
commit
1d56c920ab
@ -1,39 +1,11 @@
|
||||
import base64
|
||||
import json
|
||||
|
||||
|
||||
def encode_image(image_path):
|
||||
with open(image_path, "rb") as i:
|
||||
b64 = base64.b64encode(i.read())
|
||||
return b64.decode("utf-8")
|
||||
|
||||
|
||||
# 读取JSON文件
|
||||
json_file = r'../JSON/28_1.json'
|
||||
with open(json_file, 'r', encoding='utf-8') as file:
|
||||
payload = json.load(file)
|
||||
|
||||
# 此处为读取一张图片作为输入图像
|
||||
refer_img = encode_image('../Image/28/1.jpg')
|
||||
source_img = encode_image('../Image/1ae93e2587822c291362abf9504cb49ec.jpeg')
|
||||
|
||||
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
|
||||
print(json.dumps(payload, sort_keys=False, ensure_ascii=False, indent=4)) # 生成可以正确显示中文的json格式输出
|
||||
from Util.CommonUtil import *
|
||||
|
||||
# API地址
|
||||
url = "http://192.168.1.21:7860"
|
||||
# response = requests.post(url=f'{url}/sdapi/v1/img2img', json=payload)
|
||||
|
||||
# if response.status_code != 200:
|
||||
# print(response.text)
|
||||
# exit(0)
|
||||
# r = response.json()
|
||||
|
||||
# image = Image.open(io.BytesIO(base64.b64decode(r['images'][0])))
|
||||
|
||||
# 用户输入的源图
|
||||
input_source_img = '../Image/1ae93e2587822c291362abf9504cb49ec.jpeg'
|
||||
# 输出图片
|
||||
output_file = "../Out/Result.png"
|
||||
|
||||
# print(payload)
|
||||
# image.show()
|
||||
# image.save('output.png')
|
||||
# 调用图生图
|
||||
img2img(url, 28, 1, input_source_img, output_file)
|
||||
|
Binary file not shown.
Loading…
Reference in new issue