Skip to content

Commit

Permalink
Remove prefix if present
Browse files Browse the repository at this point in the history
  • Loading branch information
entmike authored and martinobettucci committed Jun 20, 2023
1 parent 6afeeab commit 1ae6905
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions scripts/swapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,20 @@ 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
if 'base64,' in source_img: # check if the base64 string has a data URL scheme
# split the base64 string to get the actual base64 encoded image data
base64_data = source_img.split('base64,')[-1]
# decode base64 string to bytes
img_bytes = base64.b64decode(base64_data)
else:
# if no data URL scheme, just decode
img_bytes = base64.b64decode(source_img)

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)
Expand Down

0 comments on commit 1ae6905

Please sign in to comment.