ekhatskevich commited on
Commit
114a69f
·
1 Parent(s): 371bdca

check for empty image

Browse files
Files changed (1) hide show
  1. app.py +7 -16
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
- Swaps the face in the target image using the provided face image via ACE++.
52
 
53
- Parameters:
54
- target_img: The image in which you want to swap a face.
55
- face_img: The reference face image to insert.
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, # No manual mask provided; let ACE++ handle it
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 # Use a random seed if not specified
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