Spaces:
Runtime error
Runtime error
inflation and mask blur sliders
Browse files
app.py
CHANGED
|
@@ -103,6 +103,8 @@ def process(
|
|
| 103 |
input_image_editor: dict,
|
| 104 |
inpainting_prompt_text: str,
|
| 105 |
masking_prompt_text: str,
|
|
|
|
|
|
|
| 106 |
seed_slicer: int,
|
| 107 |
randomize_seed_checkbox: bool,
|
| 108 |
strength_slider: float,
|
|
@@ -138,11 +140,13 @@ def process(
|
|
| 138 |
api_name="/process_image")
|
| 139 |
mask = Image.open(mask)
|
| 140 |
|
| 141 |
-
mask = ImageOps.expand(mask, border=5, fill=255)
|
| 142 |
-
mask = mask.filter(ImageFilter.GaussianBlur(radius=5))
|
| 143 |
width, height = resize_image_dimensions(original_resolution_wh=image.size)
|
| 144 |
image = image.resize((width, height), Image.LANCZOS)
|
| 145 |
mask = mask.resize((width, height), Image.LANCZOS)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
if randomize_seed_checkbox:
|
| 148 |
seed_slicer = random.randint(0, MAX_SEED)
|
|
@@ -192,6 +196,28 @@ with gr.Blocks() as demo:
|
|
| 192 |
placeholder="Enter text to generate masking",
|
| 193 |
container=False,
|
| 194 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
seed_slicer_component = gr.Slider(
|
| 196 |
label="Seed",
|
| 197 |
minimum=0,
|
|
@@ -257,6 +283,8 @@ with gr.Blocks() as demo:
|
|
| 257 |
input_image_editor_component,
|
| 258 |
inpainting_prompt_text_component,
|
| 259 |
masking_prompt_text_component,
|
|
|
|
|
|
|
| 260 |
seed_slicer_component,
|
| 261 |
randomize_seed_checkbox_component,
|
| 262 |
strength_slider_component,
|
|
|
|
| 103 |
input_image_editor: dict,
|
| 104 |
inpainting_prompt_text: str,
|
| 105 |
masking_prompt_text: str,
|
| 106 |
+
mask_inflation_slider: int,
|
| 107 |
+
mask_blur_slider: int,
|
| 108 |
seed_slicer: int,
|
| 109 |
randomize_seed_checkbox: bool,
|
| 110 |
strength_slider: float,
|
|
|
|
| 140 |
api_name="/process_image")
|
| 141 |
mask = Image.open(mask)
|
| 142 |
|
|
|
|
|
|
|
| 143 |
width, height = resize_image_dimensions(original_resolution_wh=image.size)
|
| 144 |
image = image.resize((width, height), Image.LANCZOS)
|
| 145 |
mask = mask.resize((width, height), Image.LANCZOS)
|
| 146 |
+
if mask_inflation_slider:
|
| 147 |
+
mask = ImageOps.expand(mask, border=mask_inflation_slider, fill=255)
|
| 148 |
+
if mask_blur_slider:
|
| 149 |
+
mask = mask.filter(ImageFilter.GaussianBlur(radius=mask_blur_slider))
|
| 150 |
|
| 151 |
if randomize_seed_checkbox:
|
| 152 |
seed_slicer = random.randint(0, MAX_SEED)
|
|
|
|
| 196 |
placeholder="Enter text to generate masking",
|
| 197 |
container=False,
|
| 198 |
)
|
| 199 |
+
|
| 200 |
+
with gr.Row():
|
| 201 |
+
mask_inflation_slider_component = gr.Slider(
|
| 202 |
+
label="Mask inflation",
|
| 203 |
+
info="Adjusts the amount of mask edge expansion before "
|
| 204 |
+
"inpainting.",
|
| 205 |
+
minimum=0,
|
| 206 |
+
maximum=20,
|
| 207 |
+
step=1,
|
| 208 |
+
value=5,
|
| 209 |
+
)
|
| 210 |
+
|
| 211 |
+
mask_blur_slider_component = gr.Slider(
|
| 212 |
+
label="Mask blur",
|
| 213 |
+
info="Controls the intensity of the Gaussian blur applied to "
|
| 214 |
+
"the mask edges.",
|
| 215 |
+
minimum=0,
|
| 216 |
+
maximum=20,
|
| 217 |
+
step=1,
|
| 218 |
+
value=5,
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
seed_slicer_component = gr.Slider(
|
| 222 |
label="Seed",
|
| 223 |
minimum=0,
|
|
|
|
| 283 |
input_image_editor_component,
|
| 284 |
inpainting_prompt_text_component,
|
| 285 |
masking_prompt_text_component,
|
| 286 |
+
mask_inflation_slider_component,
|
| 287 |
+
mask_blur_slider_component,
|
| 288 |
seed_slicer_component,
|
| 289 |
randomize_seed_checkbox_component,
|
| 290 |
strength_slider_component,
|