From 7a08f7eca88b595c38cde7174994ded9ba96cf09 Mon Sep 17 00:00:00 2001 From: xsl Date: Sun, 10 Aug 2025 20:37:27 +0800 Subject: [PATCH] save code --- change_app.py | 18 +++++++++--------- config.py | 15 +++++++++++++++ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/change_app.py b/change_app.py index eecf2ca..b3042fb 100644 --- a/change_app.py +++ b/change_app.py @@ -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') diff --git a/config.py b/config.py index d020b08..86f1a15 100644 --- a/config.py +++ b/config.py @@ -37,6 +37,21 @@ console_handler.setFormatter(console_formatter) logger.addHandler(file_handler) logger.addHandler(console_handler) +selfComputer = "5090" + +if selfComputer == "5090": + change_only_name = "change_new_only_change.json" + change_with_add_cloth = "change_new_debug.json" + xiezhen_name = "xiezhen_girl.json" + base64_test_port = 28888 +else: + change_only_name = "change_new_only_3090.json" + change_with_add_cloth = "change_new_3090.json" + xiezhen_name = "xiezhen_girl.json" + base64_test_port = 18888 + + + def acquire_lock(redis_client, lock_name): lock = Lock( redis_client,