|
@@ -37,6 +37,7 @@ import concurrent.futures
|
|
|
from sockets.message_handler import handlerFolderDelete
|
|
from sockets.message_handler import handlerFolderDelete
|
|
|
from service.remove_bg_ali import RemoveBgALi
|
|
from service.remove_bg_ali import RemoveBgALi
|
|
|
import uuid as mine_uuid
|
|
import uuid as mine_uuid
|
|
|
|
|
+from utils import common
|
|
|
def log_exception_with_context(context_message=""):
|
|
def log_exception_with_context(context_message=""):
|
|
|
"""装饰器:为函数添加异常日志上下文"""
|
|
"""装饰器:为函数添加异常日志上下文"""
|
|
|
|
|
|
|
@@ -94,6 +95,7 @@ async def sendAsyncMessage(msg="", goods_arts=[], status="", msg_type="", data=N
|
|
|
"msg_type": msg_type,
|
|
"msg_type": msg_type,
|
|
|
}
|
|
}
|
|
|
await message_queue.put(data)
|
|
await message_queue.put(data)
|
|
|
|
|
+ # message_queue.put_nowait(data)
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.get("/")
|
|
@app.get("/")
|
|
@@ -291,7 +293,11 @@ async def process_handle_detail(request: Request, params: HandlerDetail):
|
|
|
run_main, config_data, goods_art_no_arrays, move_folder_array
|
|
run_main, config_data, goods_art_no_arrays, move_folder_array
|
|
|
)
|
|
)
|
|
|
# 处理场景图和模特图
|
|
# 处理场景图和模特图
|
|
|
- return_data_check_before_detail = run_main.check_before_detail(config_data,is_detail)
|
|
|
|
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
|
|
+ return_data_check_before_detail = await loop.run_in_executor(
|
|
|
|
|
+ None,
|
|
|
|
|
+ partial(run_main.check_before_detail, config_data, is_detail)
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
# 检查处理结果
|
|
# 检查处理结果
|
|
|
success_handler = return_data_check_before_detail.get("data", {}).get("config_data", {}).get("success_handler", [])
|
|
success_handler = return_data_check_before_detail.get("data", {}).get("config_data", {}).get("success_handler", [])
|
|
@@ -542,8 +548,19 @@ async def _process_cutout(run_main, config_data, goods_art_no_arrays, move_folde
|
|
|
msg_type="segment_progress",
|
|
msg_type="segment_progress",
|
|
|
progress=progress
|
|
progress=progress
|
|
|
)
|
|
)
|
|
|
- return_data = run_main.check_before_cutout(config_data)
|
|
|
|
|
- cutout_res = run_main.check_for_cutout_image_first_call_back(return_data)
|
|
|
|
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
|
|
+
|
|
|
|
|
+ # 【修复】将同步耗时操作放入线程池
|
|
|
|
|
+ # 注意:check_before_cutout 和 check_for_cutout_image_first_call_back 必须是线程安全的
|
|
|
|
|
+ return_data = await loop.run_in_executor(
|
|
|
|
|
+ None,
|
|
|
|
|
+ partial(run_main.check_before_cutout, config_data)
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ cutout_res = await loop.run_in_executor(
|
|
|
|
|
+ None,
|
|
|
|
|
+ partial(run_main.check_for_cutout_image_first_call_back, return_data)
|
|
|
|
|
+ )
|
|
|
if cutout_res:
|
|
if cutout_res:
|
|
|
# sys_path = format(os.getcwd()).replace("\\", "/")
|
|
# sys_path = format(os.getcwd()).replace("\\", "/")
|
|
|
handler_result_folder = f"{config_data['image_dir']}"
|
|
handler_result_folder = f"{config_data['image_dir']}"
|
|
@@ -554,7 +571,7 @@ async def _process_cutout(run_main, config_data, goods_art_no_arrays, move_folde
|
|
|
"success": True,
|
|
"success": True,
|
|
|
"info": "处理成功",
|
|
"info": "处理成功",
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
|
|
+ print("抠图是否完成",len(have_handler_keys) == len(goods_art_no_arrays) or (len(have_handler_keys) == 0 and cutout_res),handler_result)
|
|
|
if len(have_handler_keys) == len(goods_art_no_arrays) or (len(have_handler_keys) == 0 and cutout_res):
|
|
if len(have_handler_keys) == len(goods_art_no_arrays) or (len(have_handler_keys) == 0 and cutout_res):
|
|
|
handler_result_folder = handler_result_folder.replace("\\", "/")
|
|
handler_result_folder = handler_result_folder.replace("\\", "/")
|
|
|
success_items = [item for item in handler_result if item.get('success') == True]
|
|
success_items = [item for item in handler_result if item.get('success') == True]
|
|
@@ -574,7 +591,25 @@ async def _process_cutout(run_main, config_data, goods_art_no_arrays, move_folde
|
|
|
progress=progress
|
|
progress=progress
|
|
|
)
|
|
)
|
|
|
return handler_result_folder, handler_result
|
|
return handler_result_folder, handler_result
|
|
|
|
|
+async def _process_single_scene_item(aigc_clazz, goods_art_dict_info_item, product_scene_prompt, save_root_path):
|
|
|
|
|
+ """将单个货号的场景图生成逻辑提取出来,放在线程池中运行"""
|
|
|
|
|
+ def sync_generate():
|
|
|
|
|
+ ceshi_image_path = goods_art_dict_info_item.get("pics").get("侧视-抠图")
|
|
|
|
|
+ save_image_path = f"{save_root_path}场景图.jpg"
|
|
|
|
|
+
|
|
|
|
|
+ if os.path.isfile(save_image_path):
|
|
|
|
|
+ return save_image_path
|
|
|
|
|
+
|
|
|
|
|
+ aigc_clazz.center_paste_image(ceshi_image_path, save_image_path)
|
|
|
|
|
+ image_path = aigc_clazz.generateProductScene(save_image_path, product_scene_prompt, save_image_path)
|
|
|
|
|
+ return image_path
|
|
|
|
|
|
|
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
|
|
+ try:
|
|
|
|
|
+ image_path = await loop.run_in_executor(None, sync_generate)
|
|
|
|
|
+ return {"success": True, "path": image_path}
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ return {"success": False, "error": str(e)}
|
|
|
async def _process_scene_images(aigc_clazz, run_main, return_data_check_before_detail, product_scene_prompt):
|
|
async def _process_scene_images(aigc_clazz, run_main, return_data_check_before_detail, product_scene_prompt):
|
|
|
"""处理场景图生成"""
|
|
"""处理场景图生成"""
|
|
|
# 参数验证
|
|
# 参数验证
|
|
@@ -602,13 +637,13 @@ async def _process_scene_images(aigc_clazz, run_main, return_data_check_before_d
|
|
|
msg_type="scene_progress",
|
|
msg_type="scene_progress",
|
|
|
progress=product_scene_progress
|
|
progress=product_scene_progress
|
|
|
)
|
|
)
|
|
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
for goods_art_no_info in goods_dict.keys():
|
|
for goods_art_no_info in goods_dict.keys():
|
|
|
goods_art_dict_info = goods_dict.get(goods_art_no_info,None)
|
|
goods_art_dict_info = goods_dict.get(goods_art_no_info,None)
|
|
|
new_goods_dict.setdefault(goods_art_no_info,goods_art_dict_info)
|
|
new_goods_dict.setdefault(goods_art_no_info,goods_art_dict_info)
|
|
|
if goods_art_dict_info is None: continue
|
|
if goods_art_dict_info is None: continue
|
|
|
for idx_key,goods_art_dict_info_item in enumerate(goods_art_dict_info.get("货号资料", [])):
|
|
for idx_key,goods_art_dict_info_item in enumerate(goods_art_dict_info.get("货号资料", [])):
|
|
|
- goods_art_no = goods_art_dict_info_item.get("货号")
|
|
|
|
|
- try:
|
|
|
|
|
|
|
+ goods_art_no = goods_art_dict_info_item.get("货号")
|
|
|
product_scene_finish_progress += 1
|
|
product_scene_finish_progress += 1
|
|
|
folder = ""
|
|
folder = ""
|
|
|
product_scene_progress = {
|
|
product_scene_progress = {
|
|
@@ -631,8 +666,26 @@ async def _process_scene_images(aigc_clazz, run_main, return_data_check_before_d
|
|
|
ceshi_image_path = first_pics.get("侧视-抠图")
|
|
ceshi_image_path = first_pics.get("侧视-抠图")
|
|
|
save_root_path = ceshi_image_path.split("阴影图处理")[0]
|
|
save_root_path = ceshi_image_path.split("阴影图处理")[0]
|
|
|
save_image_path = f"{save_root_path}场景图.jpg"
|
|
save_image_path = f"{save_root_path}场景图.jpg"
|
|
|
- if os.path.isfile(save_image_path):
|
|
|
|
|
- goods_art_dict_info_item["场景图"] = save_image_path
|
|
|
|
|
|
|
+ # 【修复】异步等待单个货号的 AI 处理完成
|
|
|
|
|
+ # 这样在处理一个货号时,事件循环可以去发送其他货号的消息
|
|
|
|
|
+ result = await _process_single_scene_item(aigc_clazz, goods_art_dict_info_item, product_scene_prompt, save_root_path)
|
|
|
|
|
+
|
|
|
|
|
+ if result["success"]:
|
|
|
|
|
+ goods_art_dict_info_item["场景图"] = result["path"]
|
|
|
|
|
+ new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
|
|
|
+ product_scene_progress["folder"] = save_image_path.replace("场景图.jpg", "")
|
|
|
|
|
+ await sendAsyncMessage(
|
|
|
|
|
+ msg="场景图处理完成",
|
|
|
|
|
+ goods_arts=[goods_art_no],
|
|
|
|
|
+ status="场景图处理完成",
|
|
|
|
|
+ msg_type="scene_progress",
|
|
|
|
|
+ progress=product_scene_progress
|
|
|
|
|
+ )
|
|
|
|
|
+ aigc_clazz.center_paste_image(ceshi_image_path, save_image_path)
|
|
|
|
|
+ image_path = aigc_clazz.generateProductScene(
|
|
|
|
|
+ save_image_path, product_scene_prompt, save_image_path
|
|
|
|
|
+ )
|
|
|
|
|
+ goods_art_dict_info_item["场景图"] = image_path
|
|
|
new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
|
product_scene_progress["folder"] = save_image_path.replace("场景图.jpg", "")
|
|
product_scene_progress["folder"] = save_image_path.replace("场景图.jpg", "")
|
|
|
await sendAsyncMessage(
|
|
await sendAsyncMessage(
|
|
@@ -642,48 +695,31 @@ async def _process_scene_images(aigc_clazz, run_main, return_data_check_before_d
|
|
|
msg_type="scene_progress",
|
|
msg_type="scene_progress",
|
|
|
progress=product_scene_progress
|
|
progress=product_scene_progress
|
|
|
)
|
|
)
|
|
|
- continue
|
|
|
|
|
|
|
+ else:
|
|
|
|
|
+ goods_art_dict_info_item["场景图"] = ""
|
|
|
|
|
+ new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
|
|
|
+ print("场景图处理异常",e)
|
|
|
|
|
+ os.remove(save_image_path)
|
|
|
|
|
+ # product_scene_finish_progress -= 1
|
|
|
|
|
+ product_scene_error_progress += 1
|
|
|
|
|
|
|
|
- aigc_clazz.center_paste_image(ceshi_image_path, save_image_path)
|
|
|
|
|
- image_path = aigc_clazz.generateProductScene(
|
|
|
|
|
- save_image_path, product_scene_prompt, save_image_path
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- goods_art_dict_info_item["场景图"] = image_path
|
|
|
|
|
- new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
|
|
|
- product_scene_progress["folder"] = save_image_path.replace("场景图.jpg", "")
|
|
|
|
|
- await sendAsyncMessage(
|
|
|
|
|
- msg="场景图处理完成",
|
|
|
|
|
- goods_arts=[goods_art_no],
|
|
|
|
|
- status="场景图处理完成",
|
|
|
|
|
- msg_type="scene_progress",
|
|
|
|
|
- progress=product_scene_progress
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- except Exception as e:
|
|
|
|
|
- goods_art_dict_info_item["场景图"] = ""
|
|
|
|
|
- new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
|
|
|
- print("场景图处理异常",e)
|
|
|
|
|
- os.remove(save_image_path)
|
|
|
|
|
- # product_scene_finish_progress -= 1
|
|
|
|
|
- product_scene_error_progress += 1
|
|
|
|
|
-
|
|
|
|
|
- product_scene_progress = {
|
|
|
|
|
- "status": "处理失败",
|
|
|
|
|
- "goods_art_no": goods_art_no,
|
|
|
|
|
- "current": product_scene_finish_progress,
|
|
|
|
|
- "total": product_scene_total_progress,
|
|
|
|
|
- "error": product_scene_error_progress,
|
|
|
|
|
- "folder":""
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ product_scene_progress = {
|
|
|
|
|
+ "status": "处理失败",
|
|
|
|
|
+ "goods_art_no": goods_art_no,
|
|
|
|
|
+ "current": product_scene_finish_progress,
|
|
|
|
|
+ "total": product_scene_total_progress,
|
|
|
|
|
+ "error": product_scene_error_progress,
|
|
|
|
|
+ "folder":""
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ await sendAsyncMessage(
|
|
|
|
|
+ msg="场景图处理失败",
|
|
|
|
|
+ goods_arts=[goods_art_no],
|
|
|
|
|
+ status="场景图处理失败",
|
|
|
|
|
+ msg_type="scene_progress",
|
|
|
|
|
+ progress=product_scene_progress
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
- await sendAsyncMessage(
|
|
|
|
|
- msg="场景图处理失败",
|
|
|
|
|
- goods_arts=[goods_art_no],
|
|
|
|
|
- status="场景图处理失败",
|
|
|
|
|
- msg_type="scene_progress",
|
|
|
|
|
- progress=product_scene_progress
|
|
|
|
|
- )
|
|
|
|
|
status_text = "处理完成" if product_scene_finish_progress > 0 else "处理失败"
|
|
status_text = "处理完成" if product_scene_finish_progress > 0 else "处理失败"
|
|
|
product_scene_progress = {
|
|
product_scene_progress = {
|
|
|
"status": status_text,
|
|
"status": status_text,
|
|
@@ -704,7 +740,70 @@ async def _process_scene_images(aigc_clazz, run_main, return_data_check_before_d
|
|
|
return_data_check_before_detail["data"]["goods_no_dict"] = new_goods_dict
|
|
return_data_check_before_detail["data"]["goods_no_dict"] = new_goods_dict
|
|
|
|
|
|
|
|
return return_data_check_before_detail
|
|
return return_data_check_before_detail
|
|
|
-
|
|
|
|
|
|
|
+def _sync_model_gen_logic(aigc_clazz, goods_art_dict_info_item, man_id, women_id, save_root_path):
|
|
|
|
|
+ """纯同步逻辑,用于在线程池中执行"""
|
|
|
|
|
+ ceshi_image_path = goods_art_dict_info_item.get("pics").get("侧视-抠图")
|
|
|
|
|
+ save_image_path = f"{save_root_path}模特图.jpg"
|
|
|
|
|
+
|
|
|
|
|
+ if os.path.isfile(save_image_path):
|
|
|
|
|
+ return {"success": True, "path": save_image_path}
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ shutil.copy(ceshi_image_path, save_image_path)
|
|
|
|
|
+ # 假设性别信息在货号资料里,或者需要从外部传入。这里参考原代码逻辑:
|
|
|
|
|
+ # 原代码: gender = goods_art_dict_info.get("性别","女") -> 这里的 goods_art_dict_info 是款号级别的
|
|
|
|
|
+ # 为了在线程池中运行,我们需要把 model_id 算好传进来,或者把整个款号信息传进来
|
|
|
|
|
+ # 这里简化处理,假设我们只处理生成步骤,model_id 由调用方决定
|
|
|
|
|
+
|
|
|
|
|
+ # 由于线程池函数无法轻松访问闭包变量,最稳妥的方式是将所有依赖项作为参数传入
|
|
|
|
|
+ # 但为了保持代码简洁,我们直接在主异步函数中计算 model_id,然后传给一个只负责“复制+生成”的同步函数
|
|
|
|
|
+
|
|
|
|
|
+ # 重新设计:
|
|
|
|
|
+ gender = "女" # 默认,实际应从数据源获取
|
|
|
|
|
+ # 由于 _process_single_model_item 签名限制,我们直接在下面主函数中内联线程池调用更清晰
|
|
|
|
|
+
|
|
|
|
|
+ image_path = aigc_clazz.generateUpperShoes(save_image_path, man_id if "男" in gender else women_id, save_image_path)
|
|
|
|
|
+ return {"success": True, "path": image_path}
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ if os.path.exists(save_image_path):
|
|
|
|
|
+ try: os.remove(save_image_path)
|
|
|
|
|
+ except: pass
|
|
|
|
|
+ return {"success": False, "error": str(e)}
|
|
|
|
|
+async def _process_single_model_item(aigc_clazz, goods_art_dict_info_item, man_id, women_id, save_root_path):
|
|
|
|
|
+ """将单个货号的模特图生成逻辑提取出来,放在线程池中运行"""
|
|
|
|
|
+ def sync_generate():
|
|
|
|
|
+ ceshi_image_path = goods_art_dict_info_item.get("pics").get("侧视-抠图")
|
|
|
|
|
+ save_image_path = f"{save_root_path}模特图.jpg"
|
|
|
|
|
+
|
|
|
|
|
+ # 如果已存在则直接返回
|
|
|
|
|
+ if os.path.isfile(save_image_path):
|
|
|
|
|
+ return {"success": True, "path": save_image_path}
|
|
|
|
|
+
|
|
|
|
|
+ try:
|
|
|
|
|
+ # 同步文件复制
|
|
|
|
|
+ shutil.copy(ceshi_image_path, save_image_path)
|
|
|
|
|
+
|
|
|
|
|
+ gender = goods_art_dict_info_item.get("性别", "女") # 注意:这里可能需要从外层传入性别,或者从 goods_art_dict_info 获取
|
|
|
|
|
+ # 修正:性别通常在 goods_art_dict_info (款号级别) 而不是货号级别,需根据实际数据结构调整
|
|
|
|
|
+ # 假设我们在外层已经确定了 model_id,这里只负责生成
|
|
|
|
|
+ # 为了简化,我们假设 model_id 已经由外层确定并传入,或者在这里重新判断
|
|
|
|
|
+
|
|
|
|
|
+ # 注意:原代码中 gender 是从 goods_art_dict_info (款号信息) 获取的
|
|
|
|
|
+ # 这里我们需要确保能访问到正确的性别信息。
|
|
|
|
|
+ # 由于函数签名限制,建议在外层处理好 model_id 后传入
|
|
|
|
|
+
|
|
|
|
|
+ # 这里暂时保留原逻辑的简化版,实际使用时请确保 model_id 正确传递
|
|
|
|
|
+ # 由于无法直接访问外层的 gender 变量,建议修改函数签名传入 model_id
|
|
|
|
|
+ raise Exception("请使用带 model_id 的版本")
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ if os.path.exists(save_image_path):
|
|
|
|
|
+ try: os.remove(save_image_path)
|
|
|
|
|
+ except: pass
|
|
|
|
|
+ return {"success": False, "error": str(e)}
|
|
|
|
|
+
|
|
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
|
|
+ # 注意:由于需要访问 gender 来决定 model_id,建议重构为传入 model_id
|
|
|
|
|
+ return await loop.run_in_executor(None, lambda: _sync_model_gen_logic(aigc_clazz, goods_art_dict_info_item, man_id, women_id, save_root_path))
|
|
|
async def _process_model_images(aigc_clazz, run_main, return_data_check_before_detail, upper_footer_params):
|
|
async def _process_model_images(aigc_clazz, run_main, return_data_check_before_detail, upper_footer_params):
|
|
|
"""处理模特图生成"""
|
|
"""处理模特图生成"""
|
|
|
# 参数验证
|
|
# 参数验证
|
|
@@ -741,15 +840,21 @@ async def _process_model_images(aigc_clazz, run_main, return_data_check_before_d
|
|
|
progress=upper_footer_progress
|
|
progress=upper_footer_progress
|
|
|
)
|
|
)
|
|
|
print("上脚图=====>>>>",goods_dict,return_data_check_before_detail)
|
|
print("上脚图=====>>>>",goods_dict,return_data_check_before_detail)
|
|
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
|
|
+
|
|
|
for goods_art_no_info in goods_dict.keys():
|
|
for goods_art_no_info in goods_dict.keys():
|
|
|
- goods_art_dict_info = goods_dict.get(goods_art_no_info,None)
|
|
|
|
|
- new_goods_dict.setdefault(goods_art_no_info,goods_art_dict_info)
|
|
|
|
|
|
|
+ goods_art_dict_info = goods_dict.get(goods_art_no_info, None)
|
|
|
|
|
+ new_goods_dict.setdefault(goods_art_no_info, goods_art_dict_info)
|
|
|
if goods_art_dict_info is None: continue
|
|
if goods_art_dict_info is None: continue
|
|
|
- for idx_key,goods_art_dict_info_item in enumerate(goods_art_dict_info.get("货号资料", [])):
|
|
|
|
|
- goods_art_no = goods_art_dict_info_item.get("货号")
|
|
|
|
|
- upper_footer_finish_progress += 1
|
|
|
|
|
- folder = ""
|
|
|
|
|
- try:
|
|
|
|
|
|
|
+
|
|
|
|
|
+ # 获取该款号的性别,用于选择模特
|
|
|
|
|
+ gender = goods_art_dict_info.get("性别", "女")
|
|
|
|
|
+ model_id = man_id if "男" in gender else women_id
|
|
|
|
|
+
|
|
|
|
|
+ for idx_key, goods_art_dict_info_item in enumerate(goods_art_dict_info.get("货号资料", [])):
|
|
|
|
|
+ goods_art_no = goods_art_dict_info_item.get("货号")
|
|
|
|
|
+ upper_footer_finish_progress += 1
|
|
|
|
|
+ folder = ""
|
|
|
upper_footer_progress = {
|
|
upper_footer_progress = {
|
|
|
"status": "正在处理",
|
|
"status": "正在处理",
|
|
|
"goods_art_no": goods_art_no,
|
|
"goods_art_no": goods_art_no,
|
|
@@ -766,16 +871,32 @@ async def _process_model_images(aigc_clazz, run_main, return_data_check_before_d
|
|
|
msg_type="upper_footer_progress",
|
|
msg_type="upper_footer_progress",
|
|
|
progress=upper_footer_progress
|
|
progress=upper_footer_progress
|
|
|
)
|
|
)
|
|
|
- first_pics = goods_art_dict_info_item.get("pics")
|
|
|
|
|
- ceshi_image_path = first_pics.get("侧视-抠图")
|
|
|
|
|
gender = goods_art_dict_info.get("性别","女")
|
|
gender = goods_art_dict_info.get("性别","女")
|
|
|
model_id = man_id if "男" in gender else women_id
|
|
model_id = man_id if "男" in gender else women_id
|
|
|
|
|
+ first_pics = goods_art_dict_info_item.get("pics")
|
|
|
ceshi_image_path = first_pics.get("侧视-抠图")
|
|
ceshi_image_path = first_pics.get("侧视-抠图")
|
|
|
save_root_path = ceshi_image_path.split("阴影图处理")[0]
|
|
save_root_path = ceshi_image_path.split("阴影图处理")[0]
|
|
|
save_image_path = f"{save_root_path}模特图.jpg"
|
|
save_image_path = f"{save_root_path}模特图.jpg"
|
|
|
|
|
|
|
|
- if os.path.isfile(save_image_path):
|
|
|
|
|
- goods_art_dict_info_item["模特图"] = save_image_path
|
|
|
|
|
|
|
+ # 2. 【核心修复】将耗时的 复制+AI生成 放入线程池
|
|
|
|
|
+ def sync_model_task():
|
|
|
|
|
+ if os.path.isfile(save_image_path):
|
|
|
|
|
+ return {"success": True, "path": save_image_path}
|
|
|
|
|
+ try:
|
|
|
|
|
+ shutil.copy(ceshi_image_path, save_image_path)
|
|
|
|
|
+ image_path = aigc_clazz.generateUpperShoes(save_image_path, model_id, save_image_path)
|
|
|
|
|
+ return {"success": True, "path": image_path}
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ if os.path.exists(save_image_path):
|
|
|
|
|
+ try: os.remove(save_image_path)
|
|
|
|
|
+ except: pass
|
|
|
|
|
+ return {"success": False, "error": str(e)}
|
|
|
|
|
+
|
|
|
|
|
+ result = await loop.run_in_executor(None, sync_model_task)
|
|
|
|
|
+
|
|
|
|
|
+ # 3. 处理结果并发送消息
|
|
|
|
|
+ if result["success"]:
|
|
|
|
|
+ goods_art_dict_info_item["模特图"] = result["path"]
|
|
|
new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
|
upper_footer_progress["folder"] = save_image_path.replace("模特图.jpg", "")
|
|
upper_footer_progress["folder"] = save_image_path.replace("模特图.jpg", "")
|
|
|
await sendAsyncMessage(
|
|
await sendAsyncMessage(
|
|
@@ -785,45 +906,19 @@ async def _process_model_images(aigc_clazz, run_main, return_data_check_before_d
|
|
|
msg_type="upper_footer_progress",
|
|
msg_type="upper_footer_progress",
|
|
|
progress=upper_footer_progress
|
|
progress=upper_footer_progress
|
|
|
)
|
|
)
|
|
|
- continue
|
|
|
|
|
-
|
|
|
|
|
- shutil.copy(ceshi_image_path, save_image_path)
|
|
|
|
|
- image_path = aigc_clazz.generateUpperShoes(save_image_path, model_id, save_image_path)
|
|
|
|
|
-
|
|
|
|
|
- goods_art_dict_info_item["模特图"] = image_path
|
|
|
|
|
- new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
|
|
|
- upper_footer_progress["folder"] = save_image_path.replace("模特图.jpg", "")
|
|
|
|
|
- await sendAsyncMessage(
|
|
|
|
|
- msg="模特图处理成功",
|
|
|
|
|
- goods_arts=[goods_art_no],
|
|
|
|
|
- status="模特图处理成功",
|
|
|
|
|
- msg_type="upper_footer_progress",
|
|
|
|
|
- progress=upper_footer_progress
|
|
|
|
|
- )
|
|
|
|
|
-
|
|
|
|
|
- except (concurrent.futures.TimeoutError, Exception) as e:
|
|
|
|
|
- print("模特图处理异常信息",e)
|
|
|
|
|
- os.remove(save_image_path)
|
|
|
|
|
- # upper_footer_finish_progress-=1
|
|
|
|
|
- upper_footer_error_progress += 1
|
|
|
|
|
- goods_art_dict_info_item["模特图"] = ""
|
|
|
|
|
- new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
|
|
|
- upper_footer_progress = {
|
|
|
|
|
- "status": "处理失败",
|
|
|
|
|
- "goods_art_no": goods_art_no,
|
|
|
|
|
- "current": upper_footer_finish_progress,
|
|
|
|
|
- "total": upper_footer_total_progress,
|
|
|
|
|
- "error": upper_footer_error_progress,
|
|
|
|
|
- "folder":""
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- await sendAsyncMessage(
|
|
|
|
|
- msg="模特图处理失败",
|
|
|
|
|
- goods_arts=[goods_art_no],
|
|
|
|
|
- status="模特图处理失败",
|
|
|
|
|
- msg_type="upper_footer_progress",
|
|
|
|
|
- progress=upper_footer_progress
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ else:
|
|
|
|
|
+ upper_footer_error_progress += 1
|
|
|
|
|
+ goods_art_dict_info_item["模特图"] = ""
|
|
|
|
|
+ new_goods_dict[goods_art_no_info]["货号资料"][idx_key] = goods_art_dict_info_item
|
|
|
|
|
+ upper_footer_progress["status"] = "处理失败"
|
|
|
|
|
+ upper_footer_progress["error"] = upper_footer_error_progress
|
|
|
|
|
+ await sendAsyncMessage(
|
|
|
|
|
+ msg="模特图处理失败",
|
|
|
|
|
+ goods_arts=[goods_art_no],
|
|
|
|
|
+ status="模特图处理失败",
|
|
|
|
|
+ msg_type="upper_footer_progress",
|
|
|
|
|
+ progress=upper_footer_progress
|
|
|
|
|
+ )
|
|
|
status_text = "处理完成" if upper_footer_finish_progress > 0 else "处理失败"
|
|
status_text = "处理完成" if upper_footer_finish_progress > 0 else "处理失败"
|
|
|
upper_footer_progress = {
|
|
upper_footer_progress = {
|
|
|
"status": status_text,
|
|
"status": status_text,
|
|
@@ -848,8 +943,17 @@ async def _process_model_images(aigc_clazz, run_main, return_data_check_before_d
|
|
|
async def _process_detail_pages(run_main, return_data_check_before_detail, onlineData,
|
|
async def _process_detail_pages(run_main, return_data_check_before_detail, onlineData,
|
|
|
online_stores, goods_art_no_arrays, handler_result_folder,request_params):
|
|
online_stores, goods_art_no_arrays, handler_result_folder,request_params):
|
|
|
"""处理详情页生成和上传"""
|
|
"""处理详情页生成和上传"""
|
|
|
- check_for_detail_first_res = run_main.check_for_detail_first_call_back(
|
|
|
|
|
- return_data_check_before_detail,request_params
|
|
|
|
|
|
|
+ # check_for_detail_first_res = run_main.check_for_detail_first_call_back(
|
|
|
|
|
+ # return_data_check_before_detail,request_params
|
|
|
|
|
+ # )
|
|
|
|
|
+ loop = asyncio.get_event_loop()
|
|
|
|
|
+ # 将整个 detail_run_by_thread 放入线程池执行
|
|
|
|
|
+ check_for_detail_first_res = await loop.run_in_executor(
|
|
|
|
|
+ None,
|
|
|
|
|
+ run_main.check_for_detail_first_call_back,
|
|
|
|
|
+ return_data_check_before_detail,
|
|
|
|
|
+ request_params,
|
|
|
|
|
+ # ... 其他参数
|
|
|
)
|
|
)
|
|
|
print("<======>check_for_detail_first_res<======>",check_for_detail_first_res)
|
|
print("<======>check_for_detail_first_res<======>",check_for_detail_first_res)
|
|
|
if isinstance(check_for_detail_first_res, partial):
|
|
if isinstance(check_for_detail_first_res, partial):
|