From 6afeeab8d813aab04fde42d8814cc43044e56f2a Mon Sep 17 00:00:00 2001 From: Mike Howles Date: Mon, 19 Jun 2023 14:22:48 -0500 Subject: [PATCH] Add check for when source_image is passed via API --- scripts/swapper.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/swapper.py b/scripts/swapper.py index 2a3e79e..ccce59b 100644 --- a/scripts/swapper.py +++ b/scripts/swapper.py @@ -111,6 +111,12 @@ def swap_face( converted = convert_to_sd(target_img) scale, fn = converted[0], converted[1] if model is not None and not scale: + if isinstance(source_img, str): # source_img is a base64 string + import base64, io + # decode base64 string to bytes + img_bytes = base64.b64decode(source_img) + # convert bytes to a PIL Image + source_img = Image.open(io.BytesIO(img_bytes)) source_img = cv2.cvtColor(np.array(source_img), cv2.COLOR_RGB2BGR) target_img = cv2.cvtColor(np.array(target_img), cv2.COLOR_RGB2BGR) source_face = get_face_single(source_img, face_index=0)