Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
6bfc071
1
Parent(s):
072d8d2
parameterize guidance scale and blur mask
Browse files
app.py
CHANGED
|
@@ -30,6 +30,7 @@ This Space appears to be running on a CPU; it will take hours to get results. Y
|
|
| 30 |
|
| 31 |
xlp_kwargs['torch_dtype'] = device_dtype
|
| 32 |
|
|
|
|
| 33 |
def merge_images(original, new_image, offset, direction):
|
| 34 |
if direction in ["left", "right"]:
|
| 35 |
merged_image = np.zeros(
|
|
@@ -50,7 +51,7 @@ def merge_images(original, new_image, offset, direction):
|
|
| 50 |
merged_image[: new_image.shape[0], :] = new_image
|
| 51 |
elif direction == "bottom":
|
| 52 |
merged_image[: original.shape[0], :] = original
|
| 53 |
-
merged_image[original.shape[0] + offset - new_image.shape[0]:
|
| 54 |
|
| 55 |
return merged_image
|
| 56 |
|
|
@@ -182,8 +183,9 @@ def image_resize(image, new_size=1024):
|
|
| 182 |
|
| 183 |
return image
|
| 184 |
|
|
|
|
| 185 |
@spaces.GPU
|
| 186 |
-
def outpaint(pil_image, direction='right', times_to_expand=4):
|
| 187 |
if torch.cuda.is_available():
|
| 188 |
torch.cuda.empty_cache()
|
| 189 |
|
|
@@ -215,7 +217,7 @@ def outpaint(pil_image, direction='right', times_to_expand=4):
|
|
| 215 |
negative_prompt=negative_prompt,
|
| 216 |
width=1024,
|
| 217 |
height=1024,
|
| 218 |
-
guidance_scale=
|
| 219 |
num_inference_steps=25,
|
| 220 |
original_image=image,
|
| 221 |
image=image,
|
|
@@ -231,7 +233,6 @@ def outpaint(pil_image, direction='right', times_to_expand=4):
|
|
| 231 |
|
| 232 |
return image
|
| 233 |
|
| 234 |
-
|
| 235 |
prompt = ""
|
| 236 |
negative_prompt = ""
|
| 237 |
inpaint_mask_color = 50 # lighter use more of the Telea inpainting
|
|
@@ -243,7 +244,7 @@ def outpaint(pil_image, direction='right', times_to_expand=4):
|
|
| 243 |
# image.shape[1] for horizontal, image.shape[0] for vertical
|
| 244 |
expand_pixels_to_square = 1024 - image.shape[1]
|
| 245 |
image, mask = process_image(
|
| 246 |
-
image, expand_pixels=expand_pixels_to_square, direction=direction, inpaint_mask_color=inpaint_mask_color
|
| 247 |
)
|
| 248 |
|
| 249 |
ip_adapter_image = []
|
|
@@ -256,7 +257,7 @@ def outpaint(pil_image, direction='right', times_to_expand=4):
|
|
| 256 |
|
| 257 |
for i in range(times_to_expand):
|
| 258 |
image, mask = process_image(
|
| 259 |
-
final_image, direction=direction, expand_pixels=expand_pixels, inpaint_mask_color=inpaint_mask_color
|
| 260 |
)
|
| 261 |
|
| 262 |
ip_adapter_image = []
|
|
@@ -280,6 +281,10 @@ gradio_app = gr.Interface(
|
|
| 280 |
info="Outward from which edge to paint?", value='right'),
|
| 281 |
gr.Slider(2, 4, step=1, value=4, label="Times to expand",
|
| 282 |
info="Choose between 2 and 4"),
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
],
|
| 284 |
outputs=[gr.Image(label="Processed Image")],
|
| 285 |
title="Outpainting with differential diffusion demo",
|
|
|
|
| 30 |
|
| 31 |
xlp_kwargs['torch_dtype'] = device_dtype
|
| 32 |
|
| 33 |
+
|
| 34 |
def merge_images(original, new_image, offset, direction):
|
| 35 |
if direction in ["left", "right"]:
|
| 36 |
merged_image = np.zeros(
|
|
|
|
| 51 |
merged_image[: new_image.shape[0], :] = new_image
|
| 52 |
elif direction == "bottom":
|
| 53 |
merged_image[: original.shape[0], :] = original
|
| 54 |
+
merged_image[original.shape[0] + offset - new_image.shape[0]:original.shape[0] + offset, :] = new_image
|
| 55 |
|
| 56 |
return merged_image
|
| 57 |
|
|
|
|
| 183 |
|
| 184 |
return image
|
| 185 |
|
| 186 |
+
|
| 187 |
@spaces.GPU
|
| 188 |
+
def outpaint(pil_image, direction='right', times_to_expand=4, guidance_scale=4.0, blur_radius=500):
|
| 189 |
if torch.cuda.is_available():
|
| 190 |
torch.cuda.empty_cache()
|
| 191 |
|
|
|
|
| 217 |
negative_prompt=negative_prompt,
|
| 218 |
width=1024,
|
| 219 |
height=1024,
|
| 220 |
+
guidance_scale=guidance_scale,
|
| 221 |
num_inference_steps=25,
|
| 222 |
original_image=image,
|
| 223 |
image=image,
|
|
|
|
| 233 |
|
| 234 |
return image
|
| 235 |
|
|
|
|
| 236 |
prompt = ""
|
| 237 |
negative_prompt = ""
|
| 238 |
inpaint_mask_color = 50 # lighter use more of the Telea inpainting
|
|
|
|
| 244 |
# image.shape[1] for horizontal, image.shape[0] for vertical
|
| 245 |
expand_pixels_to_square = 1024 - image.shape[1]
|
| 246 |
image, mask = process_image(
|
| 247 |
+
image, expand_pixels=expand_pixels_to_square, direction=direction, inpaint_mask_color=inpaint_mask_color, blur_radius=blur_radius
|
| 248 |
)
|
| 249 |
|
| 250 |
ip_adapter_image = []
|
|
|
|
| 257 |
|
| 258 |
for i in range(times_to_expand):
|
| 259 |
image, mask = process_image(
|
| 260 |
+
final_image, direction=direction, expand_pixels=expand_pixels, inpaint_mask_color=inpaint_mask_color, blur_radius=blur_radius
|
| 261 |
)
|
| 262 |
|
| 263 |
ip_adapter_image = []
|
|
|
|
| 281 |
info="Outward from which edge to paint?", value='right'),
|
| 282 |
gr.Slider(2, 4, step=1, value=4, label="Times to expand",
|
| 283 |
info="Choose between 2 and 4"),
|
| 284 |
+
gr.Slider(1, 12, step=0.1, value=4, label="Guidance scale",
|
| 285 |
+
info="Choose between 1 and 12"),
|
| 286 |
+
gr.Slider(250, 500, step=1, value=500, label="Mask blur radius",
|
| 287 |
+
info="Choose between 250 and 500"),
|
| 288 |
],
|
| 289 |
outputs=[gr.Image(label="Processed Image")],
|
| 290 |
title="Outpainting with differential diffusion demo",
|