You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
1 year ago
|
from Util import ConfigUtil
|
||
|
from Util.CommonUtil import *
|
||
|
|
||
|
|
||
|
# 图生图
|
||
|
def img2img(url, img_path, v_data, save_path):
|
||
|
image = encode_image(img_path)
|
||
|
v_data['init_images'] = [image]
|
||
|
v_data['alwayson_scripts']['controlnet']['args'][0]['image'] = image
|
||
|
response = submit_post(url, v_data)
|
||
|
save_encoded_image(response.json()['images'][0], save_path)
|
||
|
|
||
|
|
||
|
if __name__ == '__main__':
|
||
|
# 配置文件
|
||
|
config = ConfigUtil.getConfig()
|
||
|
# 图生图服务地址
|
||
|
img2img_url = config['webui']['img2img_url']
|
||
|
|
||
|
# 图片路径
|
||
|
image_path = "../Image/mote.png"
|
||
|
# 生成的JSON文件
|
||
|
data = \
|
||
|
{
|
||
|
"init_images": [],
|
||
|
"sampler_name": "Euler",
|
||
|
"alwayson_scripts": {
|
||
|
"controlnet": {
|
||
|
"args": [
|
||
|
{
|
||
|
"image": "",
|
||
|
"module": "none", "model": "control_openpose-fp16 [9ca67cc5]",
|
||
|
}
|
||
|
]
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
img2img(img2img_url, image_path, data, "../Out/result.png")
|
||
|
# print(json.dumps(data, sort_keys=True, ensure_ascii=False)) # 生成可以正确显示中文的json格式输出
|