Update face_swapper.py

Update:
- Support the opacity of the face swap in the UI
pull/883/head
Makaru 2025-01-11 16:55:01 +08:00 committed by GitHub
parent ee19c5158a
commit 33ed4b89fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 5 deletions

View File

@ -21,10 +21,7 @@ THREAD_LOCK = threading.Lock()
NAME = "DLC.FACE-SWAPPER"
abs_dir = os.path.dirname(os.path.abspath(__file__))
models_dir = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(abs_dir))), "models"
)
models_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(abs_dir))), 'models')
def pre_check() -> bool:
download_directory_path = abs_dir
@ -59,7 +56,7 @@ def get_face_swapper() -> Any:
with THREAD_LOCK:
if FACE_SWAPPER is None:
model_path = os.path.join(models_dir, "inswapper_128_fp16.onnx")
model_path = os.path.join(models_dir, 'inswapper_128_fp16.onnx')
FACE_SWAPPER = insightface.model_zoo.get_model(
model_path, providers=modules.globals.execution_providers
)
@ -93,6 +90,9 @@ def swap_face(source_face: Face, target_face: Face, temp_frame: Frame) -> Frame:
swapped_frame = draw_mouth_mask_visualization(
swapped_frame, target_face, mouth_mask_data
)
opacity = getattr(modules.globals, "opacity", 1.0)
swapped_frame = cv2.addWeighted(temp_frame, 1 - opacity, swapped_frame, opacity, 0)
return swapped_frame