Spaces:
Running
on
Zero
Running
on
Zero
gradio MCP mode readiness
Browse files
app.py
CHANGED
@@ -169,9 +169,55 @@ def preview_image_and_mask(image, width, height, overlap_percentage, resize_opti
|
|
169 |
return preview
|
170 |
|
171 |
@spaces.GPU(duration=24)
|
172 |
-
def infer(
|
173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
175 |
if not can_expand(background.width, background.height, width, height, alignment):
|
176 |
alignment = "Middle"
|
177 |
|
@@ -202,6 +248,7 @@ def infer(image, width, height, overlap_percentage, num_inference_steps, resize_
|
|
202 |
|
203 |
yield background, cnet_image
|
204 |
|
|
|
205 |
def clear_result():
|
206 |
"""Clears the result ImageSlider."""
|
207 |
return gr.update(value=None)
|
@@ -453,4 +500,4 @@ with gr.Blocks(css=css) as demo:
|
|
453 |
queue=False
|
454 |
)
|
455 |
|
456 |
-
demo.queue(max_size=12).launch(share=False, show_error=True)
|
|
|
169 |
return preview
|
170 |
|
171 |
@spaces.GPU(duration=24)
|
172 |
+
def infer(
|
173 |
+
image,
|
174 |
+
width,
|
175 |
+
height,
|
176 |
+
overlap_percentage,
|
177 |
+
num_inference_steps,
|
178 |
+
resize_option,
|
179 |
+
custom_resize_percentage,
|
180 |
+
prompt_input,
|
181 |
+
alignment,
|
182 |
+
overlap_left,
|
183 |
+
overlap_right,
|
184 |
+
overlap_top,
|
185 |
+
overlap_bottom
|
186 |
+
):
|
187 |
+
"""
|
188 |
+
Generate an outpainted image using Stable Diffusion XL with ControlNet guidance.
|
189 |
|
190 |
+
This function performs intelligent image outpainting by expanding the input image
|
191 |
+
according to the specified target dimensions and alignment, generating new content
|
192 |
+
guided by a textual prompt. It uses a ControlNet-enabled diffusion pipeline to ensure
|
193 |
+
coherent image extension.
|
194 |
+
|
195 |
+
Args:
|
196 |
+
image (PIL.Image): The input image to be outpainted.
|
197 |
+
width (int): The target width of the output image.
|
198 |
+
height (int): The target height of the output image.
|
199 |
+
overlap_percentage (int): Percentage of overlap between original and outpainted regions for seamless blending.
|
200 |
+
num_inference_steps (int): Number of inference steps for image generation. Higher values yield better results.
|
201 |
+
resize_option (str): Predefined or custom percentage to resize the input image ("Full", "50%", "33%", "25%", or "Custom").
|
202 |
+
custom_resize_percentage (int): Custom resize percentage if resize_option is "Custom".
|
203 |
+
prompt_input (str): A text prompt describing desired content for the generated region.
|
204 |
+
alignment (str): Alignment of the original image within the canvas ("Middle", "Left", "Right", "Top", "Bottom").
|
205 |
+
overlap_left (bool): Whether to allow blending on the left edge.
|
206 |
+
overlap_right (bool): Whether to allow blending on the right edge.
|
207 |
+
overlap_top (bool): Whether to allow blending on the top edge.
|
208 |
+
overlap_bottom (bool): Whether to allow blending on the bottom edge.
|
209 |
+
|
210 |
+
Yields:
|
211 |
+
Tuple[PIL.Image, PIL.Image]:
|
212 |
+
- The intermediate ControlNet input image (showing the masked area).
|
213 |
+
- The final generated image with the inpainted region.
|
214 |
+
"""
|
215 |
+
background, mask = prepare_image_and_mask(
|
216 |
+
image, width, height, overlap_percentage,
|
217 |
+
resize_option, custom_resize_percentage, alignment,
|
218 |
+
overlap_left, overlap_right, overlap_top, overlap_bottom
|
219 |
+
)
|
220 |
+
|
221 |
if not can_expand(background.width, background.height, width, height, alignment):
|
222 |
alignment = "Middle"
|
223 |
|
|
|
248 |
|
249 |
yield background, cnet_image
|
250 |
|
251 |
+
|
252 |
def clear_result():
|
253 |
"""Clears the result ImageSlider."""
|
254 |
return gr.update(value=None)
|
|
|
500 |
queue=False
|
501 |
)
|
502 |
|
503 |
+
demo.queue(max_size=12).launch(share=False, show_error=True, mcp_server=True)
|