save code

This commit is contained in:
xsl
2025-08-10 20:37:27 +08:00
parent 9dad88f8be
commit 7a08f7eca8
2 changed files with 24 additions and 9 deletions
+9 -9
View File
@@ -14,7 +14,7 @@ import oss2
import redis
# from check_img_body import is_thigh_visible
import logging
from config import QUEUE_NAME, DEFAULT_TIMEOUT, KEY_QUEUE_LOCK_NAME, acquire_lock
from config import *
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
@@ -128,7 +128,7 @@ def takeoff_cloth_first(human_name, is_girl):
if queue["queue_running"] or queue["queue_pending"]:
return None, "cur gpu is busy"
with open(f'{APP_ROOT}/change_new_debug.json', 'r', encoding='utf-8') as file:
with open(f'{APP_ROOT}/{change_with_add_cloth}', 'r', encoding='utf-8') as file:
prompt_text = file.read()
prompt = json.loads(prompt_text)
@@ -142,7 +142,8 @@ def takeoff_cloth_first(human_name, is_girl):
if is_girl:
prompt["22"]["inputs"]["image"] = 'girl_cloth.jpg'
else:
prompt["22"]["inputs"]["image"] = 'man_cloth.jpg'
prompt["22"]["inputs"]["image"] = 'man_cloth_new.jpg'
# prompt["22"]["inputs"]["image"] = 'man_cloth.jpg'
#input human img
prompt["61"]["inputs"]["image"] = human_name
@@ -186,7 +187,7 @@ def generate_from_face(human_name, sex_girl):
if queue["queue_running"] or queue["queue_pending"]:
return None, "cur gpu is busy"
with open(f'{APP_ROOT}/xiezhen_girl.json', 'r', encoding='utf-8') as file:
with open(f'{APP_ROOT}/{xiezhen_name}', 'r', encoding='utf-8') as file:
prompt_text = file.read()
prompt = json.loads(prompt_text)
@@ -282,7 +283,7 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, human_url, no2)
return None, None, sex_girl, "cur gpu is busy, Shou not happen"
print('开始换衣服')
with open(f'{APP_ROOT}/change_new_only_change.json', 'r', encoding='utf-8') as file:
with open(f'{APP_ROOT}/{change_only_name}', 'r', encoding='utf-8') as file:
prompt_text = file.read()
prompt = json.loads(prompt_text)
@@ -451,7 +452,7 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
out_human_image = Image.open(f'{APP_ROOT}/../output/{out_human_name}')
out_human_jpg_name = out_human_name.replace(".png", ".jpg")
out_human_jpg_path_name = f'{APP_ROOT}/static/imgs/{out_human_jpg_name}'
out_human_image.save(out_human_jpg_path_name, quality=95)
out_human_image.save(out_human_jpg_path_name, quality=90)
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}")
@@ -460,7 +461,7 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url,
image = Image.open(f'{APP_ROOT}/../output/{out_put_name}')
jpg_name = out_put_name.replace(".png", ".jpg")
jpg_path_name = f'{APP_ROOT}/static/imgs/{jpg_name}'
image.save(jpg_path_name, quality=95)
image.save(jpg_path_name, quality=90)
upload_to_oss(jpg_path_name, jpg_name) # 第二个参数可选,指定OSS上的路径
@@ -635,7 +636,6 @@ def change_cloth():
@app.route('/change_cloth_base64', methods=['POST'])
def change_cloth_base64():
remote_port = 28888
# 获取参数
data = request.get_json()
if not data:
@@ -655,7 +655,7 @@ def change_cloth_base64():
return jsonify({"ret":-1, 'msg': 'Failed to save human image'}), 500
data['human_img'] = None
human_url = f"http://112.126.94.241:{remote_port}/static/imgs/{human_filename}"
human_url = f"http://112.126.94.241:{base64_test_port}/static/imgs/{human_filename}"
# 保存服装图片
cloth_filename = save_base64_image(cloth_img, 'cloth')