diff --git a/basic_api_example.py b/basic_api_example.py index 8566cce..cf7f326 100644 --- a/basic_api_example.py +++ b/basic_api_example.py @@ -26,7 +26,7 @@ def queue_prompt(prompt): request.urlopen(req) -with open('/home/szlc/code/ComfyUI/change_cloth/basic_api.json', 'r', encoding='utf-8') as file: +with open('/home/xsl/code/ComfyUI/change_cloth/basic_api.json', 'r', encoding='utf-8') as file: prompt_text = file.read() prompt = json.loads(prompt_text) diff --git a/change_app.py b/change_app.py index 15aca89..0868781 100644 --- a/change_app.py +++ b/change_app.py @@ -1,7 +1,7 @@ import os import uuid import requests -from flask import Flask, request, jsonify +from flask import Flask, request, jsonify, Response from urllib.parse import urlparse import json import base64 @@ -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('/home/szlc/code/ComfyUI/change_cloth/change_new.json', 'r', encoding='utf-8') as file: + with open('/home/xsl/code/ComfyUI/change_cloth/change_new.json', 'r', encoding='utf-8') as file: prompt_text = file.read() prompt = json.loads(prompt_text) @@ -186,7 +186,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('/home/szlc/code/ComfyUI/change_cloth/xiezhen_girl.json', 'r', encoding='utf-8') as file: + with open('/home/xsl/code/ComfyUI/change_cloth/xiezhen_girl.json', 'r', encoding='utf-8') as file: prompt_text = file.read() prompt = json.loads(prompt_text) @@ -256,16 +256,15 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, human_url, no2) print(f'不用第二部 no2{no2}') else: print(f'要第二部 no2{no2} 先搞第一步') - # thigh_visible = is_thigh_visible(f"/home/szlc/code/ComfyUI/input/{human_name}") - if sgwzd >= 0.5: + if sgwzd >= 0.55: #脱衣服 takeoff_file_name = takeoff_cloth_first(human_name, 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('/home/szlc/code/ComfyUI/output', takeoff_file_name) - takeoff_file_path_name_input = os.path.join('/home/szlc/code/ComfyUI/input', takeoff_file_name) + takeoff_file_path_name = os.path.join('/home/xsl/code/ComfyUI/output', takeoff_file_name) + takeoff_file_path_name_input = os.path.join('/home/xsl/code/ComfyUI/input', takeoff_file_name) shutil.copy(takeoff_file_path_name, takeoff_file_path_name_input) else: #生成写真 @@ -274,8 +273,8 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, human_url, no2) return None, None, sex_girl, f"xiezhen error {human_name}" else: human_name = generate_name - generate_name_file_path_name = os.path.join('/home/szlc/code/ComfyUI/output', generate_name) - generate_name_file_path_name_input = os.path.join('/home/szlc/code/ComfyUI/input', generate_name) + generate_name_file_path_name = os.path.join('/home/xsl/code/ComfyUI/output', generate_name) + generate_name_file_path_name_input = os.path.join('/home/xsl/code/ComfyUI/input', generate_name) shutil.copy(generate_name_file_path_name, generate_name_file_path_name_input) queue = requests.get("http://localhost:8188/queue").json() @@ -283,7 +282,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('/home/szlc/code/ComfyUI/change_cloth/change_new.json', 'r', encoding='utf-8') as file: + with open('/home/xsl/code/ComfyUI/change_cloth/change_new.json', 'r', encoding='utf-8') as file: prompt_text = file.read() prompt = json.loads(prompt_text) @@ -360,13 +359,13 @@ def save_base64_image(base64_str, prefix): timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") unique_id = str(uuid.uuid4())[:8] filename = f"{prefix}_{timestamp}_{unique_id}{file_ext}" - filepath = os.path.join('/home/szlc/code/ComfyUI/change_cloth/static/imgs', filename) + filepath = os.path.join('/home/xsl/code/ComfyUI/change_cloth/static/imgs', filename) # 解码并保存图片 with open(filepath, 'wb') as f: f.write(base64.b64decode(data)) - input_filepath = os.path.join('/home/szlc/code/ComfyUI/input', filename) + input_filepath = os.path.join('/home/xsl/code/ComfyUI/input', filename) # 解码并保存图片 with open(input_filepath, 'wb') as f: f.write(base64.b64decode(data)) @@ -439,7 +438,7 @@ def upload_to_oss(image_path, object_name=None): 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/xsl/code/ComfyUI/input/{human_filename}') 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: @@ -449,18 +448,18 @@ def process_change_cloth(human_filename, cloth_filename, output_format, img_url, 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_image = Image.open(f'/home/xsl/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_jpg_path_name = f'/home/xsl/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/xsl/code/ComfyUI/output/{out_put_name}') 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/xsl/code/ComfyUI/change_cloth/static/imgs/{jpg_name}' image.save(jpg_path_name, quality=95) @@ -510,13 +509,13 @@ def save_image_from_url(image_url): # 获取原始图片格式 ext = get_file_extension(image_url) filename = f"{uuid.uuid4()}{ext}" - filepath = os.path.join('/home/szlc/code/ComfyUI/change_cloth/static/imgs', filename) + filepath = os.path.join('/home/xsl/code/ComfyUI/change_cloth/static/imgs', filename) with open(filepath, "wb") as f: for chunk in response.iter_content(1024): f.write(chunk) - input_filepath = os.path.join('/home/szlc/code/ComfyUI/input', filename) + input_filepath = os.path.join('/home/xsl/code/ComfyUI/input', filename) shutil.copy(filepath, input_filepath) return filename @@ -655,7 +654,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:18888/static/imgs/{human_filename}" + human_url = f"http://112.126.94.241:28888/static/imgs/{human_filename}" # 保存服装图片 cloth_filename = save_base64_image(cloth_img, 'cloth') @@ -663,7 +662,7 @@ def change_cloth_base64(): 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:28888/static/imgs/{cloth_filename}" data["human_url"] = human_url data["cloth_url"] = cloth_url @@ -672,7 +671,20 @@ def change_cloth_base64(): if not no2: data['no2'] = False - return queueCall(data) + # 在内部调用第二个HTTP请求 + try: + # 调用第二个API(可以是外部服务或自己的另一个端点) + response = requests.post('http://112.126.94.241:28888/do_change_cloth', json=data) + + return Response( + response=response.content, + status=response.status_code, + headers=dict(response.headers) + ) + except requests.exceptions.RequestException as e: + data['second_api_error'] = str(e) + + return jsonify("error"), 500 if __name__ == '__main__': diff --git a/check_img_body.py b/check_img_body.py index 815c210..4bf8d90 100644 --- a/check_img_body.py +++ b/check_img_body.py @@ -36,4 +36,4 @@ import mediapipe as mp # return left_thigh_visible and right_thigh_visible -# print(is_thigh_visible("/home/szlc/code/ComfyUI/change_cloth/static/imgs/fc74eded_00001_.jpg")) \ No newline at end of file +# print(is_thigh_visible("/home/xsl/code/ComfyUI/change_cloth/static/imgs/fc74eded_00001_.jpg")) \ No newline at end of file diff --git a/config.py b/config.py index d13bedf..d020b08 100644 --- a/config.py +++ b/config.py @@ -4,7 +4,7 @@ import logging QUEUE_NAME = 'task_queue' # 配置 -REDIS_HOST = '127.0.0.1' +REDIS_HOST = '192.168.101.118' REDIS_PORT = 6379 REDIS_DB = 0 DEFAULT_TIMEOUT = (60*20) diff --git a/http_app.py b/http_app.py index bb89a7f..4989280 100644 --- a/http_app.py +++ b/http_app.py @@ -56,7 +56,7 @@ def takeoff_cloth_first(human_name): if queue["queue_running"] or queue["queue_pending"]: return None, "cur gpu is busy" - with open('/home/szlc/code/ComfyUI/change_cloth/change_new.json', 'r', encoding='utf-8') as file: + with open('/home/xsl/code/ComfyUI/change_cloth/change_new.json', 'r', encoding='utf-8') as file: prompt_text = file.read() prompt = json.loads(prompt_text) @@ -122,15 +122,15 @@ def change(human_name, cloth_name, c_width, c_height, cloth_url, is_generated): return None, f"takeoff_cloth_first error {human_name}" else: human_name = takeoff_file_name - takeoff_file_path_name = os.path.join('/home/szlc/code/ComfyUI/output', takeoff_file_name) - takeoff_file_path_name_input = os.path.join('/home/szlc/code/ComfyUI/input', takeoff_file_name) + takeoff_file_path_name = os.path.join('/home/xsl/code/ComfyUI/output', takeoff_file_name) + takeoff_file_path_name_input = os.path.join('/home/xsl/code/ComfyUI/input', takeoff_file_name) shutil.copy(takeoff_file_path_name, takeoff_file_path_name_input) queue = requests.get("http://localhost:8188/queue").json() if queue["queue_running"] or queue["queue_pending"]: return None, "cur gpu is busy" - with open('/home/szlc/code/ComfyUI/change_cloth/change_new.json', 'r', encoding='utf-8') as file: + with open('/home/xsl/code/ComfyUI/change_cloth/change_new.json', 'r', encoding='utf-8') as file: prompt_text = file.read() prompt = json.loads(prompt_text) @@ -207,13 +207,13 @@ def save_base64_image(base64_str, prefix): timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") unique_id = str(uuid.uuid4())[:8] filename = f"{prefix}_{timestamp}_{unique_id}{file_ext}" - filepath = os.path.join('/home/szlc/code/ComfyUI/change_cloth/static/imgs', filename) + filepath = os.path.join('/home/xsl/code/ComfyUI/change_cloth/static/imgs', filename) # 解码并保存图片 with open(filepath, 'wb') as f: f.write(base64.b64decode(data)) - input_filepath = os.path.join('/home/szlc/code/ComfyUI/input', filename) + input_filepath = os.path.join('/home/xsl/code/ComfyUI/input', filename) # 解码并保存图片 with open(input_filepath, 'wb') as f: f.write(base64.b64decode(data)) @@ -286,16 +286,16 @@ def upload_to_oss(image_path, object_name=None): def process_change_cloth(human_filename, cloth_filename, output_format, img_url, is_generated): - w,h = get_image_dimensions(f'/home/szlc/code/ComfyUI/input/{human_filename}') + w,h = get_image_dimensions(f'/home/xsl/code/ComfyUI/input/{human_filename}') out_put_name, msg = change(human_filename, cloth_filename, w, h, img_url, is_generated) if out_put_name == None: print(f'Failed to change cloth {msg}') return jsonify({"ret":-1, 'msg': f'Failed to change cloth {msg}'}), 200 - image = Image.open(f'/home/szlc/code/ComfyUI/output/{out_put_name}') + image = Image.open(f'/home/xsl/code/ComfyUI/output/{out_put_name}') 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/xsl/code/ComfyUI/change_cloth/static/imgs/{jpg_name}' image.save(jpg_path_name, quality=95) @@ -376,13 +376,13 @@ def save_image_from_url(image_url): # 获取原始图片格式 ext = get_file_extension(image_url) filename = f"{uuid.uuid4()}{ext}" - filepath = os.path.join('/home/szlc/code/ComfyUI/change_cloth/static/imgs', filename) + filepath = os.path.join('/home/xsl/code/ComfyUI/change_cloth/static/imgs', filename) with open(filepath, "wb") as f: for chunk in response.iter_content(1024): f.write(chunk) - input_filepath = os.path.join('/home/szlc/code/ComfyUI/input', filename) + input_filepath = os.path.join('/home/xsl/code/ComfyUI/input', filename) shutil.copy(filepath, input_filepath) return filename diff --git a/oss_test.py b/oss_test.py index bfb6a14..a250506 100644 --- a/oss_test.py +++ b/oss_test.py @@ -32,7 +32,7 @@ def upload_to_oss(image_path, object_name=None): return None # 使用示例 -image_path = '/home/szlc/code/ComfyUI/change_cloth/girl8010.jpg' # 本地图片路径 +image_path = '/home/xsl/code/ComfyUI/change_cloth/girl8010.jpg' # 本地图片路径 upload_to_oss(image_path, 'girl8011.jpg') # 第二个参数可选,指定OSS上的路径 https_url = f'https://llyz.oss-cn-beijing.aliyuncs.com/girl8011.jpg' print(f"生成的HTTPS URL: {https_url}") diff --git a/static/index.html b/static/index.html index b3619a5..76029db 100644 --- a/static/index.html +++ b/static/index.html @@ -171,7 +171,7 @@ console.log("准备发送的数据:", data); // 调试用 // 调用API - fetch('http://112.126.94.241:18888/change_cloth_base64', { + fetch('http://112.126.94.241:28888/change_cloth_base64', { method: 'POST', headers: { 'Content-Type': 'application/json' diff --git a/task_test.py b/task_test.py index 6f065b7..7a53a19 100644 --- a/task_test.py +++ b/task_test.py @@ -4,7 +4,7 @@ import json # 1. 提交任务 -with open('/home/szlc/code/ComfyUI/change_cloth/basic_api.json', 'r', encoding='utf-8') as file: +with open('/home/xsl/code/ComfyUI/change_cloth/basic_api.json', 'r', encoding='utf-8') as file: prompt_text = file.read() prompt = json.loads(prompt_text) diff --git a/test_change_cloth_http.py b/test_change_cloth_http.py index 6d575b8..1b9d732 100644 --- a/test_change_cloth_http.py +++ b/test_change_cloth_http.py @@ -29,11 +29,11 @@ def image_to_base64(file_path, mime_type=None): if __name__ == '__main__': url = 'http://112.126.94.241:18018/change_cloth_base64' headers = {'Content-Type': 'application/json'} - img64_human_str = image_to_base64("/home/szlc/code/ComfyUI/input/girl_full.jpg") + img64_human_str = image_to_base64("/home/xsl/code/ComfyUI/input/girl_full.jpg") data = {} data['human_img'] = img64_human_str - img64_cloth_str = image_to_base64("/home/szlc/code/ComfyUI/input/cloth_short.jpg") + img64_cloth_str = image_to_base64("/home/xsl/code/ComfyUI/input/cloth_short.jpg") data['cloth_img'] = img64_cloth_str data['output_format'] = "url"