Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -9,6 +9,8 @@ from huggingface_hub import hf_hub_download
|
|
9 |
from controlnet_union import ControlNetModel_Union
|
10 |
from pipeline_fill_sd_xl import StableDiffusionXLFillPipeline
|
11 |
|
|
|
|
|
12 |
MODELS = {
|
13 |
"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",
|
14 |
}
|
@@ -55,13 +57,31 @@ prompt = "high quality"
|
|
55 |
|
56 |
@spaces.GPU
|
57 |
def fill_image(image, model_selection):
|
58 |
-
source = image["background"]
|
59 |
-
mask = image["layers"][0]
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
for image in pipe(
|
67 |
prompt_embeds=prompt_embeds,
|
@@ -73,9 +93,9 @@ def fill_image(image, model_selection):
|
|
73 |
yield image, cnet_image
|
74 |
|
75 |
image = image.convert("RGBA")
|
76 |
-
cnet_image.paste(image, (0, 0),
|
77 |
|
78 |
-
yield
|
79 |
|
80 |
|
81 |
def clear_result():
|
|
|
9 |
from controlnet_union import ControlNetModel_Union
|
10 |
from pipeline_fill_sd_xl import StableDiffusionXLFillPipeline
|
11 |
|
12 |
+
from PIL import Image, ImageDraw
|
13 |
+
|
14 |
MODELS = {
|
15 |
"RealVisXL V5.0 Lightning": "SG161222/RealVisXL_V5.0_Lightning",
|
16 |
}
|
|
|
57 |
|
58 |
@spaces.GPU
|
59 |
def fill_image(image, model_selection):
|
|
|
|
|
60 |
|
61 |
+
margin = 100
|
62 |
+
# Open the original image
|
63 |
+
source = image["image"] # Changed from image["background"] to match new input format
|
64 |
+
|
65 |
+
# Calculate new output size
|
66 |
+
output_size = (source.width + 2*margin, source.height + 2*margin)
|
67 |
+
|
68 |
+
# Create a white background
|
69 |
+
background = Image.new('RGB', output_size, (255, 255, 255))
|
70 |
+
|
71 |
+
# Calculate position to paste the original image
|
72 |
+
position = (margin, margin)
|
73 |
+
|
74 |
+
# Paste the original image onto the white background
|
75 |
+
background.paste(source, position)
|
76 |
+
|
77 |
+
# Create the mask
|
78 |
+
mask = Image.new('L', output_size, 255) # Start with all white
|
79 |
+
mask_draw = ImageDraw.Draw(mask)
|
80 |
+
mask_draw.rectangle([position, (position[0] + source.width, position[1] + source.height)], fill=0)
|
81 |
+
|
82 |
+
# Prepare the image for ControlNet
|
83 |
+
cnet_image = background.copy()
|
84 |
+
cnet_image.paste(0, (0, 0), mask)
|
85 |
|
86 |
for image in pipe(
|
87 |
prompt_embeds=prompt_embeds,
|
|
|
93 |
yield image, cnet_image
|
94 |
|
95 |
image = image.convert("RGBA")
|
96 |
+
cnet_image.paste(image, (0, 0), mask)
|
97 |
|
98 |
+
yield background, cnet_image
|
99 |
|
100 |
|
101 |
def clear_result():
|