|
|
@@ -1,7 +1,7 @@
|
|
|
import json
|
|
|
import threading
|
|
|
from concurrent.futures import ThreadPoolExecutor
|
|
|
-from api.img2img import img_2_img
|
|
|
+from api.img2img import img_2_img, img_2_furry
|
|
|
from api.segment import get_segment_mask
|
|
|
from utils.config_io import load_config_from_json, save_config_to_json
|
|
|
from utils.image_io import get_img_file, get_img_key_from_input_images
|
|
|
@@ -16,6 +16,7 @@ ACTION_TO_TITLE = {
|
|
|
}
|
|
|
|
|
|
clothes_lock = threading.Lock()
|
|
|
+furry_lock = threading.Lock()
|
|
|
|
|
|
def handle_card(card_data):
|
|
|
reply_message_id = card_data['open_message_id']
|
|
|
@@ -33,11 +34,17 @@ def handle_card(card_data):
|
|
|
# TODO: 保存任务状态实现断点继续
|
|
|
if action['value']['key'] == 'start':
|
|
|
config_data = load_config_from_json(reply_message_id)
|
|
|
+ logger.info('用户点击了开始按钮')
|
|
|
if config_data['action'] != "" and config_data['lora'] != "":
|
|
|
response_data = waiting_card(reply_message_id, config_data)
|
|
|
executor = ThreadPoolExecutor()
|
|
|
executor.submit(start_sd_process, reply_message_id, config_data)
|
|
|
return response_data
|
|
|
+ if config_data['action'] != "" and config_data['animal'] != "":
|
|
|
+ response_data = waiting_card(reply_message_id, config_data)
|
|
|
+ executor = ThreadPoolExecutor()
|
|
|
+ executor.submit(start_sd_process, reply_message_id, config_data)
|
|
|
+ return response_data
|
|
|
else:
|
|
|
logger.info('用户点击了上传中按钮')
|
|
|
|
|
|
@@ -47,8 +54,29 @@ def start_sd_process(reply_message_id, config_data):
|
|
|
# 获取segment mask
|
|
|
start_clothes_img_theards(reply_message_id)
|
|
|
else:
|
|
|
+ start_furry_img_theards(reply_message_id)
|
|
|
pass
|
|
|
|
|
|
+# 开始furry的每个图片的线程
|
|
|
+def start_furry_img_theards(reply_message_id):
|
|
|
+ img_keys = get_img_key_from_input_images(reply_message_id)
|
|
|
+
|
|
|
+ config_data = load_config_from_json(reply_message_id)
|
|
|
+ config_data["img_missions"] = {}
|
|
|
+ for key in img_keys:
|
|
|
+ config_data["img_missions"][key] = "doing"
|
|
|
+ save_config_to_json(config_data, reply_message_id)
|
|
|
+
|
|
|
+ threads = []
|
|
|
+ for img_key in img_keys:
|
|
|
+ logger.info("开始furry处理线程: "+img_key)
|
|
|
+ with furry_lock:
|
|
|
+ # 在锁的上下文中启动线程,确保一次只启动一个
|
|
|
+ t = threading.Thread(target=img_furry, args=(reply_message_id, img_key))
|
|
|
+ threads.append(t)
|
|
|
+ t.start()
|
|
|
+ t.join() # 等待当前线程完成再启动下一个
|
|
|
+
|
|
|
# 开始换装的每个图片的线程
|
|
|
def start_clothes_img_theards(reply_message_id):
|
|
|
img_keys = get_img_key_from_input_images(reply_message_id)
|
|
|
@@ -122,11 +150,36 @@ def img_clothes(reply_message_id, img_key):
|
|
|
else:
|
|
|
mark_img_fail(reply_message_id, img_key)
|
|
|
|
|
|
+# 对单个图片做furry操作
|
|
|
+def img_furry(reply_message_id, img_key):
|
|
|
+ img_path = f"data/input_images/{reply_message_id}/{img_key}/{img_key}.jpg"
|
|
|
+ output_directory = f"data/input_images/{reply_message_id}/{img_key}"
|
|
|
+ # 开始furry
|
|
|
+ img_output_path = img_2_furry(get_prompt(reply_message_id), img_key, img_path, output_directory)
|
|
|
+ # 获取img失败则上传失败图片
|
|
|
+ if not img_output_path:
|
|
|
+ img_output_path = "asset/img_fail.png"
|
|
|
+ mark_img_fail(reply_message_id, img_key)
|
|
|
+ # 上传图片
|
|
|
+ output_img = get_img_file(img_output_path)
|
|
|
+ upload_output_img_res = upload_image(img_key, output_img, "output_img")
|
|
|
+ if upload_output_img_res:
|
|
|
+ mark_img_done(reply_message_id, img_key)
|
|
|
+ upload_output_img_key = upload_output_img_res.json()['data']['image_key']
|
|
|
+ # 更新card
|
|
|
+ upload_output_img_card ={
|
|
|
+ "msg_type": "interactive",
|
|
|
+ "content": json.dumps(update_process_card(reply_message_id, img_key, upload_output_img_key))
|
|
|
+ }
|
|
|
+ update_message(reply_message_id, upload_output_img_card)
|
|
|
+ else:
|
|
|
+ mark_img_fail(reply_message_id, img_key)
|
|
|
+
|
|
|
|
|
|
# 配置prompt
|
|
|
def get_prompt(reply_message_id):
|
|
|
config = load_config_from_json(reply_message_id)
|
|
|
- return "1girl, masterpiece, best quality, " + config['lora']
|
|
|
+ return "niji_style,1girl,simple background,furry," + config['animal'] + ",Disney style,movie lighting,vhibi,benhance,Octane Render,cute anime,chinoiserie painting,8K,3D,C4D,super details,best quality,"
|
|
|
|
|
|
# 用户选择卡片
|
|
|
def choose_updated_card(message_id, config_data):
|