Spaces:
Paused
Paused
ekhatskevich commited on
Commit ·
114a69f
1
Parent(s): 371bdca
check for empty image
Browse files
app.py
CHANGED
|
@@ -47,33 +47,24 @@ cfg = Config(load=True, cfg_file=config_path)
|
|
| 47 |
ace_infer = ACEInference(cfg)
|
| 48 |
|
| 49 |
def face_swap_app(target_img, face_img):
|
| 50 |
-
|
| 51 |
-
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
|
| 57 |
-
Returns:
|
| 58 |
-
The output image after applying ACE++ face swapping.
|
| 59 |
-
"""
|
| 60 |
-
# For ACEInference, we pass:
|
| 61 |
-
# - reference_image: the target image,
|
| 62 |
-
# - edit_image: the new face image,
|
| 63 |
-
# - edit_mask: set to None so the image processor will create it,
|
| 64 |
-
# - prompt: "Face swap" instructs the model to perform face swapping.
|
| 65 |
-
# Other parameters (output dimensions, sampler, etc.) are set here as desired.
|
| 66 |
output_img, edit_image, change_image, mask, seed = ace_infer(
|
| 67 |
reference_image=target_img,
|
| 68 |
edit_image=face_img,
|
| 69 |
-
edit_mask=None, #
|
| 70 |
prompt="Face swap",
|
| 71 |
output_height=1024,
|
| 72 |
output_width=1024,
|
| 73 |
sampler='flow_euler',
|
| 74 |
sample_steps=28,
|
| 75 |
guide_scale=50,
|
| 76 |
-
seed=-1 #
|
| 77 |
)
|
| 78 |
return output_img
|
| 79 |
|
|
|
|
| 47 |
ace_infer = ACEInference(cfg)
|
| 48 |
|
| 49 |
def face_swap_app(target_img, face_img):
|
| 50 |
+
if target_img is None or face_img is None:
|
| 51 |
+
raise ValueError("Both a target image and a face image must be provided.")
|
| 52 |
|
| 53 |
+
# (Optional) Ensure images are in RGB
|
| 54 |
+
target_img = target_img.convert("RGB")
|
| 55 |
+
face_img = face_img.convert("RGB")
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
output_img, edit_image, change_image, mask, seed = ace_infer(
|
| 58 |
reference_image=target_img,
|
| 59 |
edit_image=face_img,
|
| 60 |
+
edit_mask=None, # Let ACE++ generate the mask automatically
|
| 61 |
prompt="Face swap",
|
| 62 |
output_height=1024,
|
| 63 |
output_width=1024,
|
| 64 |
sampler='flow_euler',
|
| 65 |
sample_steps=28,
|
| 66 |
guide_scale=50,
|
| 67 |
+
seed=-1 # Random seed if not provided
|
| 68 |
)
|
| 69 |
return output_img
|
| 70 |
|