|
|
|
@ -10,6 +10,20 @@ from Util.OssUtil import uploadOss
|
|
|
|
|
from Util.PngUtil import *
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def upload_img_file(png_file, file_path, model_id):
|
|
|
|
|
# 清除Exif信息
|
|
|
|
|
clearExif(file_path, file_path) # 清除Exif信息
|
|
|
|
|
# 上传到OSS
|
|
|
|
|
key = 'Images/User/' + str(model_id) + '/' + png_file
|
|
|
|
|
uploadOss(key, file_path)
|
|
|
|
|
# # 生成下载链接
|
|
|
|
|
url = 'http://hzkc.oss-cn-beijing.aliyuncs.com/' + key
|
|
|
|
|
# 删除本地文件
|
|
|
|
|
os.remove(file_path)
|
|
|
|
|
printf("成功生成1张图片,地址:" + url)
|
|
|
|
|
return url
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 文生图服务调用
|
|
|
|
|
def webui_txt_2_img(model_id, json_data, input_image, target_folder):
|
|
|
|
|
# 提示词
|
|
|
|
@ -26,15 +40,10 @@ def webui_txt_2_img(model_id, json_data, input_image, target_folder):
|
|
|
|
|
if len(args) > 1:
|
|
|
|
|
args[1]['input_image'] = encode_image(input_image[0])
|
|
|
|
|
|
|
|
|
|
# 宽度与高度
|
|
|
|
|
width = json_data['width']
|
|
|
|
|
height = json_data['height']
|
|
|
|
|
# 提示词
|
|
|
|
|
json_data['prompt'] = prompt
|
|
|
|
|
|
|
|
|
|
# 开始生成图片
|
|
|
|
|
printf("开始生成图片...")
|
|
|
|
|
|
|
|
|
|
# 调用生图服务
|
|
|
|
|
response = submit_post(txt2img_url, json_data)
|
|
|
|
|
# 创建文件名
|
|
|
|
@ -42,26 +51,13 @@ def webui_txt_2_img(model_id, json_data, input_image, target_folder):
|
|
|
|
|
# 创建文件的完整路径
|
|
|
|
|
file_path = os.path.join(target_folder, png_file)
|
|
|
|
|
save_encoded_image(response.json()['images'][0], file_path)
|
|
|
|
|
# 清除Exif信息
|
|
|
|
|
clearExif(file_path, file_path) # 清除Exif信息
|
|
|
|
|
# 上传到OSS
|
|
|
|
|
key = 'Images/User/' + str(model_id) + '/' + png_file
|
|
|
|
|
uploadOss(key, file_path)
|
|
|
|
|
# # 生成下载链接
|
|
|
|
|
url = 'http://hzkc.oss-cn-beijing.aliyuncs.com/' + key
|
|
|
|
|
# 删除本地文件
|
|
|
|
|
os.remove(file_path)
|
|
|
|
|
printf("成功生成1张图片,宽度:" + str(width) + ",高度:" + str(height) + " 地址:" + url)
|
|
|
|
|
url = upload_img_file(png_file, file_path, model_id)
|
|
|
|
|
# 添加到结果集合中
|
|
|
|
|
res.append(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 图生图服务调用
|
|
|
|
|
def webui_img_2_img(model_id, prompt_id, json_data, input_image, target_folder):
|
|
|
|
|
# 提示词
|
|
|
|
|
prompt = json_data['prompt']
|
|
|
|
|
# 图片
|
|
|
|
|
# 用户输入的图片
|
|
|
|
|
source_img = encode_image(input_image[0])
|
|
|
|
|
# 模型固定的参考图片
|
|
|
|
|
refer_source_img = r'./Image/' + str(model_id) + '/' + str(prompt_id) + '.jpg'
|
|
|
|
@ -85,10 +81,6 @@ def webui_img_2_img(model_id, prompt_id, json_data, input_image, target_folder):
|
|
|
|
|
if len(json_data["alwayson_scripts"]["ControlNet"]["args"]) == 2:
|
|
|
|
|
json_data["alwayson_scripts"]["ControlNet"]["args"][1]["input_image"] = refer_img
|
|
|
|
|
|
|
|
|
|
# 宽度与高度
|
|
|
|
|
width = json_data['width']
|
|
|
|
|
height = json_data['height']
|
|
|
|
|
|
|
|
|
|
# 开始生成图片
|
|
|
|
|
printf("开始生成图片...")
|
|
|
|
|
|
|
|
|
@ -99,18 +91,35 @@ def webui_img_2_img(model_id, prompt_id, json_data, input_image, target_folder):
|
|
|
|
|
# 创建文件的完整路径
|
|
|
|
|
file_path = os.path.join(target_folder, png_file)
|
|
|
|
|
save_encoded_image(response.json()['images'][0], file_path)
|
|
|
|
|
# 清除Exif信息
|
|
|
|
|
clearExif(file_path, file_path) # 清除Exif信息
|
|
|
|
|
# 上传到OSS
|
|
|
|
|
key = 'Images/User/' + str(model_id) + '/' + png_file
|
|
|
|
|
uploadOss(key, file_path)
|
|
|
|
|
# # 生成下载链接
|
|
|
|
|
url = 'http://hzkc.oss-cn-beijing.aliyuncs.com/' + key
|
|
|
|
|
# 删除本地文件
|
|
|
|
|
os.remove(file_path)
|
|
|
|
|
printf("成功生成1张图片,宽度:" + str(width) + ",高度:" + str(height) + " 地址:" + url)
|
|
|
|
|
# 添加到结果集合中
|
|
|
|
|
res.append(url)
|
|
|
|
|
url = upload_img_file(png_file, file_path, model_id)
|
|
|
|
|
res.append(url) # 添加到结果集合中
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def runComfyUI(model_id, json_data, input_image, target_folder):
|
|
|
|
|
# 生成一个唯一的客户端ID
|
|
|
|
|
client_id = str(uuid.uuid4())
|
|
|
|
|
|
|
|
|
|
# 上传图片
|
|
|
|
|
img = []
|
|
|
|
|
for x in input_image:
|
|
|
|
|
with open(x, "rb") as f:
|
|
|
|
|
y = upload_file(server_address, f, "", True)
|
|
|
|
|
img.append(y)
|
|
|
|
|
# 如果存在多个姿势图和风格图,那么在配置文件中写死,比如pose=post_1.jpg style=style_1.jpg
|
|
|
|
|
# 同时,由于ComfyUI需要把这个文件上传到服务器,所以,需要在json文件中指定哪个文件需要上传
|
|
|
|
|
# 填充输入
|
|
|
|
|
json_data = fill_input(json_data, img)
|
|
|
|
|
# 过滤器,哪些返回节点中获取到的图片是有用的
|
|
|
|
|
myfilter = getMyFilter(json_data)
|
|
|
|
|
# 生成
|
|
|
|
|
files = generate_clip(server_address, json_data, client_id, target_folder, myfilter)
|
|
|
|
|
|
|
|
|
|
# 上传到云存储,回写数据接口
|
|
|
|
|
for file in files:
|
|
|
|
|
png_file = file + '.png'
|
|
|
|
|
file_path = './Out/Images/User/' + str(model_id) + "/" + png_file
|
|
|
|
|
url = upload_img_file(png_file, file_path, model_id)
|
|
|
|
|
res.append(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def download_image(image_url, file_path):
|
|
|
|
@ -175,38 +184,6 @@ def fill_input(prompt_data, file_array):
|
|
|
|
|
return prompt_data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def runComfyUI(model_id, json_data, input_image, target_folder):
|
|
|
|
|
# 生成一个唯一的客户端ID
|
|
|
|
|
client_id = str(uuid.uuid4())
|
|
|
|
|
|
|
|
|
|
# 上传图片
|
|
|
|
|
img = []
|
|
|
|
|
for x in input_image:
|
|
|
|
|
with open(x, "rb") as f:
|
|
|
|
|
y = upload_file(server_address, f, "", True)
|
|
|
|
|
img.append(y)
|
|
|
|
|
# 如果存在多个姿势图和风格图,那么在配置文件中写死,比如pose=post_1.jpg style=style_1.jpg
|
|
|
|
|
# 同时,由于ComfyUI需要把这个文件上传到服务器,所以,需要在json文件中指定哪个文件需要上传
|
|
|
|
|
# 填充输入
|
|
|
|
|
json_data = fill_input(json_data, img)
|
|
|
|
|
# 过滤器,哪些返回节点中获取到的图片是有用的
|
|
|
|
|
myfilter = getMyFilter(json_data)
|
|
|
|
|
# 生成
|
|
|
|
|
files = generate_clip(server_address, json_data, client_id, target_folder, myfilter)
|
|
|
|
|
|
|
|
|
|
# 上传到云存储,回写数据接口
|
|
|
|
|
for file in files:
|
|
|
|
|
png_file = file + '.png'
|
|
|
|
|
file_path = './Out/Images/User/' + str(model_id) + "/" + png_file
|
|
|
|
|
# 清除Exif信息
|
|
|
|
|
clearExif(file_path, file_path) # 清除Exif信息
|
|
|
|
|
# 上传到OSS
|
|
|
|
|
key = 'Images/User/' + str(model_id) + '/' + png_file
|
|
|
|
|
uploadOss(key, file_path)
|
|
|
|
|
# # 生成下载链接
|
|
|
|
|
url = 'http://hzkc.oss-cn-beijing.aliyuncs.com/' + key
|
|
|
|
|
res.append(url)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 获取任务
|
|
|
|
|
def get_task():
|
|
|
|
@ -260,7 +237,8 @@ def get_task():
|
|
|
|
|
|
|
|
|
|
# 利用三元表达式输出
|
|
|
|
|
printf("发现需要处理的" + ("WebUI" if model_type_id in [1,
|
|
|
|
|
2] else "ComfyUI") + "任务,model_type_id=" + str(model_type_id) + ",model_id=" + str(
|
|
|
|
|
2] else "ComfyUI") + "任务,model_type_id=" + str(
|
|
|
|
|
model_type_id) + ",model_id=" + str(
|
|
|
|
|
model_id) + ",prompt_id=" + str(prompt_id) + ",task_id=" + str(task_id))
|
|
|
|
|
|
|
|
|
|
# 创建目标目录
|
|
|
|
|