Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,25 +24,6 @@ repo_id = "black-forest-labs/FLUX.1-Fill-dev"
|
|
| 24 |
if torch.cuda.is_available():
|
| 25 |
pipe = FluxFillPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16).to("cuda")
|
| 26 |
|
| 27 |
-
|
| 28 |
-
def create_mask_image(mask_array):
|
| 29 |
-
# Convert the mask to a numpy array if it's not already
|
| 30 |
-
if not isinstance(mask_array, np.ndarray):
|
| 31 |
-
mask_array = np.array(mask_array)
|
| 32 |
-
|
| 33 |
-
# Create a new array with the same shape as the mask, but only for RGB channels
|
| 34 |
-
processed_mask = np.zeros((mask_array.shape[0], mask_array.shape[1], 3), dtype=np.uint8)
|
| 35 |
-
|
| 36 |
-
# Set transparent parts (alpha=0) to black (0, 0, 0)
|
| 37 |
-
transparent_mask = mask_array[:, :, 3] == 0
|
| 38 |
-
processed_mask[transparent_mask] = [0, 0, 0]
|
| 39 |
-
|
| 40 |
-
# Set black parts (RGB=0, 0, 0 and alpha=255) to white (255, 255, 255)
|
| 41 |
-
black_mask = (mask_array[:, :, :3] == [0, 0, 0]).all(axis=2) & (mask_array[:, :, 3] == 255)
|
| 42 |
-
processed_mask[black_mask] = [255, 255, 255]
|
| 43 |
-
|
| 44 |
-
return Image.fromarray(processed_mask)
|
| 45 |
-
|
| 46 |
@spaces.GPU()
|
| 47 |
def inpaintGen(
|
| 48 |
imgMask,
|
|
@@ -67,11 +48,8 @@ def inpaintGen(
|
|
| 67 |
|
| 68 |
source_img = Image.open(source_path).convert("RGB")
|
| 69 |
mask_img = Image.open(mask_path)
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
mask_img = ImageOps.invert(mask_img)
|
| 73 |
-
|
| 74 |
-
#mask_img = create_mask_image(mask_img)
|
| 75 |
|
| 76 |
width, height = source_img.size
|
| 77 |
|
|
@@ -82,7 +60,7 @@ def inpaintGen(
|
|
| 82 |
result = pipe(
|
| 83 |
prompt=inpaint_prompt,
|
| 84 |
image=source_img,
|
| 85 |
-
mask_image=
|
| 86 |
width=width,
|
| 87 |
height=height,
|
| 88 |
num_inference_steps=num_steps,
|
|
|
|
| 24 |
if torch.cuda.is_available():
|
| 25 |
pipe = FluxFillPipeline.from_pretrained(repo_id, torch_dtype=torch.bfloat16).to("cuda")
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
@spaces.GPU()
|
| 28 |
def inpaintGen(
|
| 29 |
imgMask,
|
|
|
|
| 48 |
|
| 49 |
source_img = Image.open(source_path).convert("RGB")
|
| 50 |
mask_img = Image.open(mask_path)
|
| 51 |
+
alpha_channel=mask_img.split()[3]
|
| 52 |
+
binary_mask = alpha_channel.point(lambda p: p > 0 and 255)
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
width, height = source_img.size
|
| 55 |
|
|
|
|
| 60 |
result = pipe(
|
| 61 |
prompt=inpaint_prompt,
|
| 62 |
image=source_img,
|
| 63 |
+
mask_image=binary_mask,
|
| 64 |
width=width,
|
| 65 |
height=height,
|
| 66 |
num_inference_steps=num_steps,
|