|
|
import json
|
|
|
|
|
|
|
|
|
# file_array = ["./Image/C17/1.jpg"]
|
|
|
# 根据输入的图片集合,填充到prompt_data中
|
|
|
def fill_input(prompt_data, file_array):
|
|
|
# 是不是不存在配置节
|
|
|
if "source_images" not in prompt_data:
|
|
|
print("配置文件不包含source_images配置节,程序无法继续!")
|
|
|
exit(0)
|
|
|
# 是不是个数不匹配
|
|
|
if len(prompt_data["source_images"]) != len(file_array):
|
|
|
print("输入的图片数量与预替换的图片数量不一致,程序无法继续!")
|
|
|
exit(0)
|
|
|
# 替换
|
|
|
for i in range(len(prompt_data["source_images"])):
|
|
|
x = prompt_data["source_images"][i]
|
|
|
# 替换配置节内容
|
|
|
array = x.split(",")
|
|
|
prompt_data[array[0]][array[1]][array[2]] = file_array[i]
|
|
|
return prompt_data
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
# JSON文件
|
|
|
json_file = r'../JSON/17_test.json'
|
|
|
|
|
|
# 读取JSON文件
|
|
|
with open(json_file, 'r', encoding='utf-8') as file:
|
|
|
prompt_data = json.load(file)
|
|
|
|
|
|
if "source_images" not in prompt_data:
|
|
|
print("未正确配置source_images配置节,程序无法继续!")
|
|
|
exit(0)
|
|
|
else:
|
|
|
print("已正确配置了source_images配置节!")
|
|
|
|
|
|
# 输入的图片地址
|
|
|
file_path = ["./Image/C17/1.jpg"]
|
|
|
if len(prompt_data["source_images"]) != len(file_path):
|
|
|
print("输入的图片数量与预替换的图片数量不一致,程序无法继续!")
|
|
|
exit(0)
|
|
|
|
|
|
for i in range(len(prompt_data["source_images"])):
|
|
|
x = prompt_data["source_images"][i]
|
|
|
# 替换配置节内容
|
|
|
array = x.split(",")
|
|
|
prompt_data[array[0]][array[1]][array[2]] = file_path[i]
|
|
|
# print(prompt_data["331"]["inputs"]["image"])
|
|
|
|
|
|
# print(json.dumps(prompt_data, sort_keys=True, indent=4)) # 美化格式化输出
|
|
|
print(json.dumps(prompt_data, sort_keys=True, ensure_ascii=False)) # 生成可以正确显示中文的json格式输出
|
|
|
|
|
|
# 一、姿势图 风格图 都是需要封装到json文件内部的是,是固定的,是死的,不需要代码去处理
|
|
|
# 二、源图 source_images,这个需要代码去处理,因为
|
|
|
# (1) 每个输入放在哪个配置节下,是不一样的
|
|
|
# (2) 可能不止一张
|