Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -243,14 +243,21 @@ def outpaint(image, width, height, overlap_percentage, num_inference_steps, resi
|
|
| 243 |
|
| 244 |
# Extract original alpha from the input image
|
| 245 |
original_alpha = background.split()[3] if background.mode == "RGBA" else Image.new("L", background.size, 255)
|
| 246 |
-
|
| 247 |
-
|
| 248 |
# Combine original and generated mask
|
| 249 |
-
combined_mask = ImageChops.logical_or(original_alpha_mask, mask) # 0 where to fill
|
| 250 |
-
|
| 251 |
-
# Use the combined_mask in the pipeline
|
| 252 |
cnet_image = background.copy()
|
| 253 |
-
cnet_image.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
final_prompt = f"score_9, score_8_up, score_7_up, {prompt_input} , high quality, 4k"
|
| 256 |
print(f"Outpainting using SDXL model: {pipe.config.model_name}")
|
|
@@ -271,9 +278,10 @@ def outpaint(image, width, height, overlap_percentage, num_inference_steps, resi
|
|
| 271 |
yield cnet_image, image
|
| 272 |
# Invert the combined_mask and paste the generated image back
|
| 273 |
filled_mask = combined_mask.point(lambda p: 255 - p)
|
|
|
|
|
|
|
| 274 |
image = image.convert("RGBA")
|
| 275 |
-
cnet_image.paste(image, (0, 0),
|
| 276 |
-
|
| 277 |
yield background, cnet_image
|
| 278 |
|
| 279 |
@spaces.GPU(duration=7)
|
|
|
|
| 243 |
|
| 244 |
# Extract original alpha from the input image
|
| 245 |
original_alpha = background.split()[3] if background.mode == "RGBA" else Image.new("L", background.size, 255)
|
| 246 |
+
combined_mask = ImageChops.logical_or(original_alpha, mask) # 0 where to paint
|
|
|
|
| 247 |
# Combine original and generated mask
|
| 248 |
+
# combined_mask = ImageChops.logical_or(original_alpha_mask, mask) # 0 where to fill
|
|
|
|
|
|
|
| 249 |
cnet_image = background.copy()
|
| 250 |
+
if cnet_image.mode == "RGBA":
|
| 251 |
+
# Extract the alpha channel and apply the combined mask
|
| 252 |
+
alpha = combined_mask.convert("L")
|
| 253 |
+
cnet_image = cnet_image.convert("RGBA")
|
| 254 |
+
cnet_image.putalpha(alpha) # Replace the alpha channel
|
| 255 |
+
else:
|
| 256 |
+
# If no alpha, just use the background
|
| 257 |
+
cnet_image = background
|
| 258 |
+
# Use the combined_mask in the pipeline
|
| 259 |
+
#cnet_image = background.copy()
|
| 260 |
+
# cnet_image.paste(0, (0, 0), combined_mask) # Overlay black on combined_mask area
|
| 261 |
|
| 262 |
final_prompt = f"score_9, score_8_up, score_7_up, {prompt_input} , high quality, 4k"
|
| 263 |
print(f"Outpainting using SDXL model: {pipe.config.model_name}")
|
|
|
|
| 278 |
yield cnet_image, image
|
| 279 |
# Invert the combined_mask and paste the generated image back
|
| 280 |
filled_mask = combined_mask.point(lambda p: 255 - p)
|
| 281 |
+
# image = image.convert("RGBA")
|
| 282 |
+
# cnet_image.paste(image, (0, 0), filled_mask)
|
| 283 |
image = image.convert("RGBA")
|
| 284 |
+
cnet_image.paste(image, (0, 0), combined_mask)
|
|
|
|
| 285 |
yield background, cnet_image
|
| 286 |
|
| 287 |
@spaces.GPU(duration=7)
|