save code
This commit is contained in:
+87
-13
@@ -97,6 +97,31 @@ def GetPicDesc(img_url):
|
|||||||
print(text)
|
print(text)
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
def GetHumanDesDesc(img_url):
|
||||||
|
response = client.chat.completions.create(
|
||||||
|
# 指定您创建的方舟推理接入点 ID,此处已帮您修改为您的推理接入点 ID
|
||||||
|
model="doubao-1.5-vision-pro-250328",
|
||||||
|
messages=[
|
||||||
|
{
|
||||||
|
"role": "user",
|
||||||
|
"content": [
|
||||||
|
{
|
||||||
|
"type": "image_url",
|
||||||
|
"image_url": {
|
||||||
|
"url": img_url
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{"type": "text", "text": "图片是一个人物的照片,返回为json格式, 第一个字段'性别', 判断一下性别,只要答案, 选项有(男、女). 第二个字段'人物',判断一下图片是否有人,只要答案,选项有(有人、没人)"},
|
||||||
|
],
|
||||||
|
}
|
||||||
|
],
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
text = response.choices[0].message.content
|
||||||
|
print(text)
|
||||||
|
return text
|
||||||
|
|
||||||
def takeoff_cloth_first(human_name):
|
def takeoff_cloth_first(human_name):
|
||||||
print('换泳装')
|
print('换泳装')
|
||||||
queue = requests.get("http://localhost:8188/queue").json()
|
queue = requests.get("http://localhost:8188/queue").json()
|
||||||
@@ -152,7 +177,7 @@ def takeoff_cloth_first(human_name):
|
|||||||
return out_img_file_name
|
return out_img_file_name
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def generate_from_face(human_name, is_girl = True):
|
def generate_from_face(human_name, sex_girl):
|
||||||
print('生成写真')
|
print('生成写真')
|
||||||
queue = requests.get("http://localhost:8188/queue").json()
|
queue = requests.get("http://localhost:8188/queue").json()
|
||||||
if queue["queue_running"] or queue["queue_pending"]:
|
if queue["queue_running"] or queue["queue_pending"]:
|
||||||
@@ -166,7 +191,7 @@ def generate_from_face(human_name, is_girl = True):
|
|||||||
|
|
||||||
prompt["93"]["inputs"]["image"] = human_name
|
prompt["93"]["inputs"]["image"] = human_name
|
||||||
|
|
||||||
if is_girl:
|
if sex_girl:
|
||||||
prompt["6"]["inputs"]["text"] = "full body shot(1.9),complete figure,front-facing,model pose, Hands are at the sides of the body, smile,clear skin glow,wearing black micro skirt,simple white background,clean composition,32k,high detail,professional beauty photography style,"
|
prompt["6"]["inputs"]["text"] = "full body shot(1.9),complete figure,front-facing,model pose, Hands are at the sides of the body, smile,clear skin glow,wearing black micro skirt,simple white background,clean composition,32k,high detail,professional beauty photography style,"
|
||||||
else:
|
else:
|
||||||
prompt["6"]["inputs"]["text"] = "full body shot(1.9),complete figure,front-facing,model pose,Hands are at the sides of the body,smile,clear skin glow,wearing fitted vest and tight shortst,simple white background,clean composition,32k,high detail,professional beauty photography style,"
|
prompt["6"]["inputs"]["text"] = "full body shot(1.9),complete figure,front-facing,model pose,Hands are at the sides of the body,smile,clear skin glow,wearing fitted vest and tight shortst,simple white background,clean composition,32k,high detail,professional beauty photography style,"
|
||||||
@@ -204,7 +229,16 @@ def generate_from_face(human_name, is_girl = True):
|
|||||||
return out_img_file_name
|
return out_img_file_name
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def change(human_name, cloth_name, c_width, c_height, cloth_url, is_generated):
|
def change(human_name, cloth_name, c_width, c_height, cloth_url, human_url, no2):
|
||||||
|
human_json_str = GetHumanDesDesc(human_url)
|
||||||
|
print(f"human_json_str {human_json_str}")
|
||||||
|
human_json_data = json.loads(human_json_str)
|
||||||
|
sex_type = human_json_data['性别']
|
||||||
|
sex_girl = True
|
||||||
|
if '男' in sex_type:
|
||||||
|
sex_girl = False
|
||||||
|
|
||||||
|
|
||||||
json_str = GetPicDesc(cloth_url)
|
json_str = GetPicDesc(cloth_url)
|
||||||
json_data = json.loads(json_str)
|
json_data = json.loads(json_str)
|
||||||
cloth_len = json_data['服装长度']
|
cloth_len = json_data['服装长度']
|
||||||
@@ -212,14 +246,18 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, is_generated):
|
|||||||
if '长袖' in json_data['衣袖']:
|
if '长袖' in json_data['衣袖']:
|
||||||
cloth_short = False
|
cloth_short = False
|
||||||
if cloth_len == '难以辨认':
|
if cloth_len == '难以辨认':
|
||||||
return None, "get image type error"
|
return None, None, sex_girl, "get image type error"
|
||||||
|
|
||||||
|
if no2:
|
||||||
|
print(f'不用第二部 no2{no2}')
|
||||||
|
else:
|
||||||
|
print(f'要第二部 no2{no2} 先搞第一步')
|
||||||
thigh_visible = is_thigh_visible(f"/home/szlc/code/ComfyUI/input/{human_name}")
|
thigh_visible = is_thigh_visible(f"/home/szlc/code/ComfyUI/input/{human_name}")
|
||||||
if thigh_visible:
|
if thigh_visible:
|
||||||
#脱衣服
|
#脱衣服
|
||||||
takeoff_file_name = takeoff_cloth_first(human_name)
|
takeoff_file_name = takeoff_cloth_first(human_name)
|
||||||
if takeoff_file_name == None:
|
if takeoff_file_name == None:
|
||||||
return None, f"takeoff_cloth_first error {human_name}"
|
return None, None, sex_girl, f"takeoff_cloth_first error {human_name}"
|
||||||
else:
|
else:
|
||||||
human_name = takeoff_file_name
|
human_name = takeoff_file_name
|
||||||
takeoff_file_path_name = os.path.join('/home/szlc/code/ComfyUI/output', takeoff_file_name)
|
takeoff_file_path_name = os.path.join('/home/szlc/code/ComfyUI/output', takeoff_file_name)
|
||||||
@@ -227,9 +265,9 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, is_generated):
|
|||||||
shutil.copy(takeoff_file_path_name, takeoff_file_path_name_input)
|
shutil.copy(takeoff_file_path_name, takeoff_file_path_name_input)
|
||||||
else:
|
else:
|
||||||
#生成写真
|
#生成写真
|
||||||
generate_name = generate_from_face(human_name)
|
generate_name = generate_from_face(human_name, sex_girl)
|
||||||
if generate_name == None:
|
if generate_name == None:
|
||||||
return None, f"takeoff_cloth_first error {human_name}"
|
return None, None, sex_girl, f"xiezhen error {human_name}"
|
||||||
else:
|
else:
|
||||||
human_name = generate_name
|
human_name = generate_name
|
||||||
generate_name_file_path_name = os.path.join('/home/szlc/code/ComfyUI/output', generate_name)
|
generate_name_file_path_name = os.path.join('/home/szlc/code/ComfyUI/output', generate_name)
|
||||||
@@ -238,7 +276,7 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, is_generated):
|
|||||||
|
|
||||||
queue = requests.get("http://localhost:8188/queue").json()
|
queue = requests.get("http://localhost:8188/queue").json()
|
||||||
if queue["queue_running"] or queue["queue_pending"]:
|
if queue["queue_running"] or queue["queue_pending"]:
|
||||||
return None, "cur gpu is busy"
|
return None, None, sex_girl, "cur gpu is busy, Shou not happen"
|
||||||
|
|
||||||
print('开始换衣服')
|
print('开始换衣服')
|
||||||
with open('/home/szlc/code/ComfyUI/change_cloth/change_new.json', 'r', encoding='utf-8') as file:
|
with open('/home/szlc/code/ComfyUI/change_cloth/change_new.json', 'r', encoding='utf-8') as file:
|
||||||
@@ -287,8 +325,8 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, is_generated):
|
|||||||
if 'filename' in out_img:
|
if 'filename' in out_img:
|
||||||
out_img_file_name = out_img['filename']
|
out_img_file_name = out_img['filename']
|
||||||
if out_img_name in out_img_file_name:
|
if out_img_name in out_img_file_name:
|
||||||
return out_img_file_name, "success"
|
return out_img_file_name, human_name, sex_girl,"success"
|
||||||
return None, "can not find output image"
|
return None, human_name, sex_girl, "can not find output image"
|
||||||
|
|
||||||
def save_base64_image(base64_str, prefix):
|
def save_base64_image(base64_str, prefix):
|
||||||
"""
|
"""
|
||||||
@@ -396,14 +434,26 @@ def upload_to_oss(image_path, object_name=None):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def process_change_cloth(human_filename, cloth_filename, output_format, img_url, is_generated):
|
def process_change_cloth(human_filename, cloth_filename, output_format, img_url, human_url, no2):
|
||||||
w,h = get_image_dimensions(f'/home/szlc/code/ComfyUI/input/{human_filename}')
|
w,h = get_image_dimensions(f'/home/szlc/code/ComfyUI/input/{human_filename}')
|
||||||
|
|
||||||
out_put_name, msg = change(human_filename, cloth_filename, w, h, img_url, is_generated)
|
out_put_name, out_human_name, is_girl, msg = change(human_filename, cloth_filename, w, h, img_url, human_url, no2)
|
||||||
if out_put_name == None:
|
if out_put_name == None:
|
||||||
print(f'Failed to change cloth {msg}')
|
print(f'Failed to change cloth {msg}')
|
||||||
return jsonify({"ret":-1, 'msg': f'Failed to change cloth {msg}'}), 200
|
return jsonify({"ret":-1, 'msg': f'Failed to change cloth {msg}'}), 200
|
||||||
|
|
||||||
|
if no2:
|
||||||
|
out_human_https_url = human_url
|
||||||
|
else:
|
||||||
|
out_human_image = Image.open(f'/home/szlc/code/ComfyUI/output/{out_human_name}')
|
||||||
|
out_human_jpg_name = out_human_name.replace(".png", ".jpg")
|
||||||
|
out_human_jpg_path_name = f'/home/szlc/code/ComfyUI/change_cloth/static/imgs/{out_human_jpg_name}'
|
||||||
|
out_human_image.save(out_human_jpg_path_name, quality=95)
|
||||||
|
upload_to_oss(out_human_jpg_path_name, out_human_jpg_name) # 第二个参数可选,指定OSS上的路径
|
||||||
|
out_human_https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/{out_human_jpg_name}'
|
||||||
|
print(f"生成的第一步图片 HTTPS URL: {out_human_https_url}")
|
||||||
|
|
||||||
|
|
||||||
image = Image.open(f'/home/szlc/code/ComfyUI/output/{out_put_name}')
|
image = Image.open(f'/home/szlc/code/ComfyUI/output/{out_put_name}')
|
||||||
jpg_name = out_put_name.replace(".png", ".jpg")
|
jpg_name = out_put_name.replace(".png", ".jpg")
|
||||||
jpg_path_name = f'/home/szlc/code/ComfyUI/change_cloth/static/imgs/{jpg_name}'
|
jpg_path_name = f'/home/szlc/code/ComfyUI/change_cloth/static/imgs/{jpg_name}'
|
||||||
@@ -419,6 +469,8 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
|
|||||||
"ret":0,
|
"ret":0,
|
||||||
"state": 0,
|
"state": 0,
|
||||||
"msg":"success",
|
"msg":"success",
|
||||||
|
"first_step_data":image_to_base64(out_human_jpg_path_name),
|
||||||
|
"is_girl":is_girl,
|
||||||
"data":image_to_base64(jpg_path_name)
|
"data":image_to_base64(jpg_path_name)
|
||||||
})
|
})
|
||||||
else:
|
else:
|
||||||
@@ -426,6 +478,8 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
|
|||||||
"ret":0,
|
"ret":0,
|
||||||
"state": 0,
|
"state": 0,
|
||||||
"msg":"success",
|
"msg":"success",
|
||||||
|
"first_url":out_human_https_url,
|
||||||
|
"is_girl":is_girl,
|
||||||
"url":https_url
|
"url":https_url
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -485,7 +539,16 @@ def do_change_cloth():
|
|||||||
|
|
||||||
output_format = data.get('output_format')
|
output_format = data.get('output_format')
|
||||||
|
|
||||||
return process_change_cloth(human_filename, cloth_filename, output_format, cloth_url, False)
|
no2 = data['no2']
|
||||||
|
|
||||||
|
try:
|
||||||
|
return process_change_cloth(human_filename, cloth_filename, output_format, cloth_url, human_url, no2)
|
||||||
|
except:
|
||||||
|
return jsonify({
|
||||||
|
"ret":-1,
|
||||||
|
"state": -1,
|
||||||
|
"msg":"process_change_cloth error"
|
||||||
|
})
|
||||||
|
|
||||||
get_redis_conn().set(QUEUE_NAME, "[]")
|
get_redis_conn().set(QUEUE_NAME, "[]")
|
||||||
|
|
||||||
@@ -550,6 +613,10 @@ def change_cloth():
|
|||||||
if not output_format:
|
if not output_format:
|
||||||
return jsonify({"state":-1, "error": "Missing 'output_format' parameter"}), 500
|
return jsonify({"state":-1, "error": "Missing 'output_format' parameter"}), 500
|
||||||
|
|
||||||
|
no2 = data.get('no2')
|
||||||
|
if not no2:
|
||||||
|
data['no2'] = False
|
||||||
|
|
||||||
return queueCall(data)
|
return queueCall(data)
|
||||||
|
|
||||||
@app.route('/change_cloth_base64', methods=['POST'])
|
@app.route('/change_cloth_base64', methods=['POST'])
|
||||||
@@ -571,6 +638,7 @@ def change_cloth_base64():
|
|||||||
human_filename = save_base64_image(human_img, 'human')
|
human_filename = save_base64_image(human_img, 'human')
|
||||||
if not human_filename:
|
if not human_filename:
|
||||||
return jsonify({"ret":-1, 'msg': 'Failed to save human image'}), 500
|
return jsonify({"ret":-1, 'msg': 'Failed to save human image'}), 500
|
||||||
|
data['human_img'] = None
|
||||||
|
|
||||||
human_url = f"http://112.126.94.241:18888/static/imgs/{human_filename}"
|
human_url = f"http://112.126.94.241:18888/static/imgs/{human_filename}"
|
||||||
|
|
||||||
@@ -578,11 +646,17 @@ def change_cloth_base64():
|
|||||||
cloth_filename = save_base64_image(cloth_img, 'cloth')
|
cloth_filename = save_base64_image(cloth_img, 'cloth')
|
||||||
if not cloth_filename:
|
if not cloth_filename:
|
||||||
return jsonify({"ret":-1, 'msg': 'Failed to save cloth image'}), 500
|
return jsonify({"ret":-1, 'msg': 'Failed to save cloth image'}), 500
|
||||||
|
data['cloth_img'] = None
|
||||||
|
|
||||||
cloth_url = f"http://112.126.94.241:18888/static/imgs/{cloth_filename}"
|
cloth_url = f"http://112.126.94.241:18888/static/imgs/{cloth_filename}"
|
||||||
|
|
||||||
data["human_url"] = human_url
|
data["human_url"] = human_url
|
||||||
data["cloth_url"] = cloth_url
|
data["cloth_url"] = cloth_url
|
||||||
|
|
||||||
|
no2 = data.get('no2')
|
||||||
|
if not no2:
|
||||||
|
data['no2'] = False
|
||||||
|
|
||||||
return queueCall(data)
|
return queueCall(data)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -7,11 +7,11 @@ QUEUE_NAME = 'task_queue'
|
|||||||
REDIS_HOST = '127.0.0.1'
|
REDIS_HOST = '127.0.0.1'
|
||||||
REDIS_PORT = 6379
|
REDIS_PORT = 6379
|
||||||
REDIS_DB = 0
|
REDIS_DB = 0
|
||||||
DEFAULT_TIMEOUT = (60*10)
|
DEFAULT_TIMEOUT = (60*20)
|
||||||
GPU_SERVER_TIME_OUT = 180
|
GPU_SERVER_TIME_OUT = 180
|
||||||
GPU_SERVER_LIST = 'gpu_server_list_key'
|
GPU_SERVER_LIST = 'gpu_server_list_key'
|
||||||
SERVER_LOG_ = "server_log"
|
SERVER_LOG_ = "server_log"
|
||||||
SERVER_LOG_EVENT_LEN = 20
|
SERVER_LOG_EVENT_LEN = 30
|
||||||
KEY_QUEUE_LOCK_NAME = 'KEY_QUEUE_LOCK_NAME'
|
KEY_QUEUE_LOCK_NAME = 'KEY_QUEUE_LOCK_NAME'
|
||||||
SERVER_LIST_LOCK_NAME = 'SERVER_LIST_LOCK_NAME'
|
SERVER_LIST_LOCK_NAME = 'SERVER_LIST_LOCK_NAME'
|
||||||
SERVER_LIST_LOG_LOCK_NAME = 'SERVER_LIST_LOG_LOCK_NAME'
|
SERVER_LIST_LOG_LOCK_NAME = 'SERVER_LIST_LOG_LOCK_NAME'
|
||||||
|
|||||||
+9
-1
@@ -96,6 +96,11 @@
|
|||||||
<input type="file" id="clothInput" accept="image/*">
|
<input type="file" id="clothInput" accept="image/*">
|
||||||
<img id="clothPreview" class="image-preview" alt="衣服图片预览">
|
<img id="clothPreview" class="image-preview" alt="衣服图片预览">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="option-box">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" id="no2Checkbox"> 设置 no2 不要两步(一步完成)
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button id="submitBtn">提交处理</button>
|
<button id="submitBtn">提交处理</button>
|
||||||
@@ -139,6 +144,7 @@
|
|||||||
document.getElementById('submitBtn').addEventListener('click', function() {
|
document.getElementById('submitBtn').addEventListener('click', function() {
|
||||||
const humanFile = document.getElementById('humanInput').files[0];
|
const humanFile = document.getElementById('humanInput').files[0];
|
||||||
const clothFile = document.getElementById('clothInput').files[0];
|
const clothFile = document.getElementById('clothInput').files[0];
|
||||||
|
const no2 = document.getElementById("no2Checkbox").checked;
|
||||||
|
|
||||||
if (!humanFile || !clothFile) {
|
if (!humanFile || !clothFile) {
|
||||||
alert('请同时选择人体图片和衣服图片!');
|
alert('请同时选择人体图片和衣服图片!');
|
||||||
@@ -159,7 +165,7 @@
|
|||||||
human_img: humanDataURL, // 包含完整前缀的Base64
|
human_img: humanDataURL, // 包含完整前缀的Base64
|
||||||
cloth_img: clothDataURL, // 包含完整前缀的Base64
|
cloth_img: clothDataURL, // 包含完整前缀的Base64
|
||||||
output_format: "url",
|
output_format: "url",
|
||||||
is_generated: false,
|
no2: no2,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("准备发送的数据:", data); // 调试用
|
console.log("准备发送的数据:", data); // 调试用
|
||||||
@@ -190,6 +196,8 @@
|
|||||||
<p>处理成功!点击查看结果:</p>
|
<p>处理成功!点击查看结果:</p>
|
||||||
<a href="${data.url}" target="_blank">${data.url}</a>
|
<a href="${data.url}" target="_blank">${data.url}</a>
|
||||||
<p><img src="${data.url}" style="max-width: 100%; margin-top: 10px;"></p>
|
<p><img src="${data.url}" style="max-width: 100%; margin-top: 10px;"></p>
|
||||||
|
<a href="${data.first_url}" target="_blank">${data.url}</a>
|
||||||
|
<p><img src="${data.first_url}" style="max-width: 100%; margin-top: 10px;"></p>
|
||||||
`;
|
`;
|
||||||
} else {
|
} else {
|
||||||
resultDiv.innerHTML = `
|
resultDiv.innerHTML = `
|
||||||
|
|||||||
@@ -182,6 +182,7 @@ def call_remote_gpu_server(task_data_str, server=None):
|
|||||||
data = {
|
data = {
|
||||||
"human_url": task_data['request']['human_url'],
|
"human_url": task_data['request']['human_url'],
|
||||||
"cloth_url": task_data['request']["cloth_url"],
|
"cloth_url": task_data['request']["cloth_url"],
|
||||||
|
"no2":task_data['request']['no2'],
|
||||||
"output_format":task_data['request']['output_format']
|
"output_format":task_data['request']['output_format']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user