Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -24,6 +24,25 @@ 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 |
@spaces.GPU()
|
| 28 |
def inpaintGen(
|
| 29 |
imgMask,
|
|
@@ -47,7 +66,9 @@ def inpaintGen(
|
|
| 47 |
raise gr.Error("Please draw a mask on the image.")
|
| 48 |
|
| 49 |
source_img = load_image(source_path)
|
| 50 |
-
mask_img = load_image(mask_path)
|
|
|
|
|
|
|
| 51 |
|
| 52 |
width, height = source_img.size
|
| 53 |
|
|
|
|
| 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,
|
|
|
|
| 66 |
raise gr.Error("Please draw a mask on the image.")
|
| 67 |
|
| 68 |
source_img = load_image(source_path)
|
| 69 |
+
mask_img = load_image(mask_path)
|
| 70 |
+
|
| 71 |
+
mask_img = create_mask_image(mask)
|
| 72 |
|
| 73 |
width, height = source_img.size
|
| 74 |
|