save code
This commit is contained in:
+56
-33
@@ -236,7 +236,7 @@ def generate_from_face(human_name, sex_girl):
|
||||
return out_img_file_name
|
||||
return None
|
||||
|
||||
def change(human_name, cloth_name, c_width, c_height, cloth_url, human_url, no2, tuodi):
|
||||
def change(human_name, cloth_name, c_width, c_height, cloth_url, human_url, no2, tuodi, kuzi):
|
||||
human_json_str = GetHumanDesDesc(human_url)
|
||||
print(f"human_json_str {human_json_str}")
|
||||
human_json_data = json.loads(human_json_str)
|
||||
@@ -247,54 +247,66 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, human_url, no2,
|
||||
|
||||
sgwzd = human_json_data['身高完整度']
|
||||
|
||||
json_str = GetPicDesc(cloth_url)
|
||||
json_data = json.loads(json_str)
|
||||
cloth_len = json_data['服装长度']
|
||||
cloth_short = True
|
||||
if '长袖' in json_data['衣袖']:
|
||||
if kuzi:
|
||||
cloth_len = "裤子"
|
||||
cloth_short = False
|
||||
print(f"GetPicDesc:{json_str}")
|
||||
else:
|
||||
json_str = GetPicDesc(cloth_url)
|
||||
json_data = json.loads(json_str)
|
||||
cloth_len = json_data['服装长度']
|
||||
cloth_short = True
|
||||
if '长袖' in json_data['衣袖']:
|
||||
cloth_short = False
|
||||
print(f"GetPicDesc:{json_str}")
|
||||
|
||||
print(f"tuodi:{tuodi}")
|
||||
print(f"kuzi:{kuzi}")
|
||||
|
||||
if tuodi == True or tuodi == "true":
|
||||
cloth_len = '拖地'
|
||||
|
||||
if kuzi == True:
|
||||
cloth_len = "裤子"
|
||||
|
||||
if no2 == True:
|
||||
print(f'不用第二部 no2{no2}')
|
||||
else:
|
||||
print(f'要第二部 no2{no2} 先搞第一步')
|
||||
if sgwzd >= 0.55:
|
||||
#脱衣服
|
||||
takeoff_file_name = takeoff_cloth_first(human_name, sex_girl)
|
||||
print(f"takeoff_file_name:{takeoff_file_name} human_name:{human_name} sex_girl:{sex_girl}")
|
||||
if takeoff_file_name == None:
|
||||
return None, None, sex_girl, f"takeoff_cloth_first error {human_name}"
|
||||
else:
|
||||
human_name = takeoff_file_name
|
||||
takeoff_file_path_name = os.path.join(f'{APP_ROOT}/../output', takeoff_file_name)
|
||||
takeoff_file_path_name_input = os.path.join(f'{APP_ROOT}/../input', takeoff_file_name)
|
||||
shutil.copy(takeoff_file_path_name, takeoff_file_path_name_input)
|
||||
if kuzi == True:
|
||||
print(f'有裤子,也不用写真 kuzi{kuzi}')
|
||||
else:
|
||||
#生成写真
|
||||
generate_name = generate_from_face(human_name, sex_girl)
|
||||
if generate_name == None:
|
||||
return None, None, sex_girl, f"xiezhen error {human_name}"
|
||||
print(f'要第二部 no2{no2} 先搞第一步')
|
||||
if sgwzd >= 0.55:
|
||||
#脱衣服
|
||||
takeoff_file_name = takeoff_cloth_first(human_name, sex_girl)
|
||||
print(f"takeoff_file_name:{takeoff_file_name} human_name:{human_name} sex_girl:{sex_girl}")
|
||||
if takeoff_file_name == None:
|
||||
return None, None, sex_girl, f"takeoff_cloth_first error {human_name}"
|
||||
else:
|
||||
human_name = takeoff_file_name
|
||||
takeoff_file_path_name = os.path.join(f'{APP_ROOT}/../output', takeoff_file_name)
|
||||
takeoff_file_path_name_input = os.path.join(f'{APP_ROOT}/../input', takeoff_file_name)
|
||||
shutil.copy(takeoff_file_path_name, takeoff_file_path_name_input)
|
||||
else:
|
||||
human_name = generate_name
|
||||
generate_name_file_path_name = os.path.join(f'{APP_ROOT}/../output', generate_name)
|
||||
generate_name_file_path_name_input = os.path.join(f'{APP_ROOT}/../input', generate_name)
|
||||
shutil.copy(generate_name_file_path_name, generate_name_file_path_name_input)
|
||||
|
||||
#生成写真
|
||||
generate_name = generate_from_face(human_name, sex_girl)
|
||||
if generate_name == None:
|
||||
return None, None, sex_girl, f"xiezhen error {human_name}"
|
||||
else:
|
||||
human_name = generate_name
|
||||
generate_name_file_path_name = os.path.join(f'{APP_ROOT}/../output', generate_name)
|
||||
generate_name_file_path_name_input = os.path.join(f'{APP_ROOT}/../input', generate_name)
|
||||
shutil.copy(generate_name_file_path_name, generate_name_file_path_name_input)
|
||||
|
||||
queue = requests.get("http://localhost:8188/queue").json()
|
||||
if queue["queue_running"] or queue["queue_pending"]:
|
||||
return None, None, sex_girl, "cur gpu is busy, Shou not happen"
|
||||
|
||||
if tuodi:
|
||||
print(f'开始换衣服 {change_tuodi_input} cloth_len:{cloth_len} cloth_short:{cloth_short}')
|
||||
print(f'开始换衣服 {change_tuodi_input} cloth_len:{cloth_len} cloth_short:{cloth_short} kuzi:{kuzi}')
|
||||
with open(f'{APP_ROOT}/{change_tuodi_input}', 'r', encoding='utf-8') as file:
|
||||
prompt_text = file.read()
|
||||
else:
|
||||
print(f'开始换衣服 {change_only_name} cloth_len:{cloth_len} cloth_short:{cloth_short}')
|
||||
print(f'开始换衣服 {change_only_name} cloth_len:{cloth_len} cloth_short:{cloth_short} kuzi:{kuzi}')
|
||||
with open(f'{APP_ROOT}/{change_only_name}', 'r', encoding='utf-8') as file:
|
||||
prompt_text = file.read()
|
||||
|
||||
@@ -517,10 +529,10 @@ def upload_to_oss(image_path, object_name=None):
|
||||
return None
|
||||
|
||||
|
||||
def process_change_cloth(human_filename, cloth_filename, output_format, img_url, human_url, no2, tuodi):
|
||||
def process_change_cloth(human_filename, cloth_filename, output_format, img_url, human_url, no2, tuodi, kuzi):
|
||||
w,h = get_image_dimensions(f'{APP_ROOT}/../input/{human_filename}')
|
||||
|
||||
out_put_name, out_human_name, is_girl, msg = change(human_filename, cloth_filename, w, h, img_url, human_url, no2, tuodi)
|
||||
out_put_name, out_human_name, is_girl, msg = change(human_filename, cloth_filename, w, h, img_url, human_url, no2, tuodi, kuzi)
|
||||
if out_put_name == None:
|
||||
print(f'Failed to change cloth {msg}')
|
||||
return jsonify({"ret":-1, 'msg': f'Failed to change cloth {msg}'}), 200
|
||||
@@ -636,8 +648,11 @@ def do_change_cloth():
|
||||
tuodi = data['tuodi']
|
||||
print(f"tuodi:{tuodi}")
|
||||
|
||||
kuzi = data['kuzi']
|
||||
print(f"kuzi:{kuzi}")
|
||||
|
||||
try:
|
||||
return process_change_cloth(human_filename, cloth_filename, output_format, cloth_url, human_url, no2, tuodi)
|
||||
return process_change_cloth(human_filename, cloth_filename, output_format, cloth_url, human_url, no2, tuodi, kuzi)
|
||||
except Exception as e:
|
||||
traceback.print_exc()
|
||||
print(f"错误详情:{e}")
|
||||
@@ -718,6 +733,10 @@ def change_cloth():
|
||||
if not tuodi:
|
||||
data['tuodi'] = False
|
||||
|
||||
kuzi = data.get('kuzi')
|
||||
if not kuzi:
|
||||
data['kuzi'] = False
|
||||
|
||||
print(f"change_cloth input data:{data}")
|
||||
|
||||
return queueCall(data)
|
||||
@@ -764,6 +783,10 @@ def change_cloth_base64():
|
||||
if not tuodi:
|
||||
data['tuodi'] = False
|
||||
|
||||
kuzi = data.get('kuzi')
|
||||
if not kuzi:
|
||||
data['kuzi'] = False
|
||||
|
||||
# 在内部调用第二个HTTP请求
|
||||
try:
|
||||
# 调用第二个API(可以是外部服务或自己的另一个端点)
|
||||
|
||||
+7
-1
@@ -103,6 +103,10 @@
|
||||
<label>
|
||||
<input type="checkbox" id="tuodiCheckbox"> 设置 tuodi(拖地)
|
||||
</label>
|
||||
|
||||
<label>
|
||||
<input type="checkbox" id="kuziCheckbox"> 设置 kuzi(裤子)
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -149,6 +153,7 @@
|
||||
const clothFile = document.getElementById('clothInput').files[0];
|
||||
const no2 = document.getElementById("no2Checkbox").checked;
|
||||
const tuodi = document.getElementById("tuodiCheckbox").checked;
|
||||
const kuzi = document.getElementById("kuziCheckbox").checked;
|
||||
|
||||
if (!humanFile || !clothFile) {
|
||||
alert('请同时选择人体图片和衣服图片!');
|
||||
@@ -170,7 +175,8 @@
|
||||
cloth_img: clothDataURL, // 包含完整前缀的Base64
|
||||
output_format: "url",
|
||||
no2: no2,
|
||||
tuodi:tuodi
|
||||
tuodi:tuodi,
|
||||
kuzi:kuzi
|
||||
};
|
||||
|
||||
console.log("准备发送的数据:", data); // 调试用
|
||||
|
||||
@@ -184,6 +184,7 @@ def call_remote_gpu_server(task_data_str, server=None):
|
||||
"cloth_url": task_data['request']["cloth_url"],
|
||||
"no2":task_data['request']['no2'],
|
||||
"tuodi":task_data['request']['tuodi'],
|
||||
"kuzi":task_data['request']['kuzi'],
|
||||
"output_format":task_data['request']['output_format']
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user