Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,8 +13,8 @@ from diffusers import AutoPipelineForInpainting, LCMScheduler, AutoencoderTiny
|
|
| 13 |
|
| 14 |
|
| 15 |
MODEL_CHOICES = {
|
| 16 |
-
"Official SD1.5 Inpainting": "stable-diffusion-v1-5/stable-diffusion-inpainting",
|
| 17 |
"DreamShaper 8 Inpainting": "Lykon/dreamshaper-8-inpainting",
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
DEFAULT_MODEL_LABEL = "DreamShaper 8 Inpainting"
|
|
@@ -328,9 +328,9 @@ def run_inpaint(
|
|
| 328 |
editor_value,
|
| 329 |
model_label: str,
|
| 330 |
prompt: str,
|
| 331 |
-
work_mode: str,
|
| 332 |
crop_padding: int,
|
| 333 |
-
|
|
|
|
| 334 |
steps: int,
|
| 335 |
guidance_scale: float,
|
| 336 |
strength: float,
|
|
@@ -361,7 +361,7 @@ def run_inpaint(
|
|
| 361 |
original_image,
|
| 362 |
generation_mask_source,
|
| 363 |
crop_padding=int(crop_padding),
|
| 364 |
-
min_crop_side=int(
|
| 365 |
)
|
| 366 |
|
| 367 |
gen_image = crop_info["padded_image"]
|
|
@@ -410,7 +410,7 @@ def run_inpaint(
|
|
| 410 |
|
| 411 |
if paste_whole_crop:
|
| 412 |
final_result.paste(generated, (left, top))
|
| 413 |
-
paste_mode = "whole crop"
|
| 414 |
else:
|
| 415 |
final_mask = original_mask.crop(crop_bbox)
|
| 416 |
|
|
@@ -424,8 +424,8 @@ def run_inpaint(
|
|
| 424 |
|
| 425 |
crop_report = (
|
| 426 |
f"- raw mask bbox: `{crop_info['raw_bbox']}`\n"
|
| 427 |
-
f"- crop bbox: `{crop_bbox}`\n"
|
| 428 |
-
f"- crop size: `{crop_size[0]}x{crop_size[1]}`\n"
|
| 429 |
f"- generation size: `{padded_size[0]}x{padded_size[1]}`\n"
|
| 430 |
f"- paste mode: `{paste_mode}`"
|
| 431 |
)
|
|
@@ -433,7 +433,7 @@ def run_inpaint(
|
|
| 433 |
else:
|
| 434 |
if paste_whole_crop:
|
| 435 |
final_result = generated
|
| 436 |
-
paste_mode = "whole image"
|
| 437 |
else:
|
| 438 |
final_mask = original_mask
|
| 439 |
|
|
@@ -446,7 +446,7 @@ def run_inpaint(
|
|
| 446 |
paste_mode = "masked area only"
|
| 447 |
|
| 448 |
crop_report = (
|
| 449 |
-
"- crop: `none`\n"
|
| 450 |
f"- original size: `{original_image.size[0]}x{original_image.size[1]}`\n"
|
| 451 |
f"- generation size: `{padded_size[0]}x{padded_size[1]}`\n"
|
| 452 |
f"- paste mode: `{paste_mode}`"
|
|
@@ -463,6 +463,8 @@ def run_inpaint(
|
|
| 463 |
"- vae: `TAESD`\n"
|
| 464 |
f"- work mode: `{work_mode}`\n"
|
| 465 |
"- resize: `none`\n"
|
|
|
|
|
|
|
| 466 |
f"- padding to multiple of 8: `{padding_used}`\n"
|
| 467 |
f"{crop_report}\n"
|
| 468 |
f"- steps: `{steps}`\n"
|
|
@@ -472,26 +474,25 @@ def run_inpaint(
|
|
| 472 |
f"- seed: `{seed}`\n"
|
| 473 |
f"- time: `{elapsed:.1f}s`\n\n"
|
| 474 |
"This version does not downscale or upscale. "
|
| 475 |
-
"In crop mode it
|
| 476 |
-
"then pastes the result back."
|
| 477 |
)
|
| 478 |
|
| 479 |
return final_result, info
|
| 480 |
|
| 481 |
|
| 482 |
-
with gr.Blocks(title="SD15 Light Inpaint CPU
|
| 483 |
gr.Markdown(
|
| 484 |
-
"# SD15 Light Inpaint CPU
|
| 485 |
-
"
|
| 486 |
-
"
|
| 487 |
-
"
|
| 488 |
-
"This keeps the model working at the local visual scale instead of seeing the whole image as a tiny thumbnail."
|
| 489 |
)
|
| 490 |
|
| 491 |
with gr.Row():
|
| 492 |
with gr.Column():
|
| 493 |
editor = gr.ImageEditor(
|
| 494 |
-
label="Image + mask
|
| 495 |
type="pil",
|
| 496 |
)
|
| 497 |
|
|
@@ -507,7 +508,15 @@ with gr.Blocks(title="SD15 Light Inpaint CPU - Crop Test") as demo:
|
|
| 507 |
lines=3,
|
| 508 |
)
|
| 509 |
|
| 510 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 511 |
work_mode = gr.Radio(
|
| 512 |
label="Work mode",
|
| 513 |
choices=[
|
|
@@ -517,16 +526,8 @@ with gr.Blocks(title="SD15 Light Inpaint CPU - Crop Test") as demo:
|
|
| 517 |
value="Crop around mask",
|
| 518 |
)
|
| 519 |
|
| 520 |
-
|
| 521 |
-
label="
|
| 522 |
-
minimum=32,
|
| 523 |
-
maximum=384,
|
| 524 |
-
step=32,
|
| 525 |
-
value=128,
|
| 526 |
-
)
|
| 527 |
-
|
| 528 |
-
min_crop_side = gr.Slider(
|
| 529 |
-
label="Minimum crop side",
|
| 530 |
minimum=128,
|
| 531 |
maximum=768,
|
| 532 |
step=64,
|
|
@@ -534,11 +535,10 @@ with gr.Blocks(title="SD15 Light Inpaint CPU - Crop Test") as demo:
|
|
| 534 |
)
|
| 535 |
|
| 536 |
paste_whole_crop = gr.Checkbox(
|
| 537 |
-
label="Paste whole generated crop back
|
| 538 |
value=False,
|
| 539 |
)
|
| 540 |
|
| 541 |
-
with gr.Accordion("Generation settings", open=True):
|
| 542 |
steps = gr.Slider(
|
| 543 |
label="Steps",
|
| 544 |
minimum=2,
|
|
@@ -548,7 +548,7 @@ with gr.Blocks(title="SD15 Light Inpaint CPU - Crop Test") as demo:
|
|
| 548 |
)
|
| 549 |
|
| 550 |
guidance_scale = gr.Slider(
|
| 551 |
-
label="Guidance scale / CFG. LCM usually works best around 1.0
|
| 552 |
minimum=1.0,
|
| 553 |
maximum=8.0,
|
| 554 |
step=0.1,
|
|
@@ -594,9 +594,9 @@ with gr.Blocks(title="SD15 Light Inpaint CPU - Crop Test") as demo:
|
|
| 594 |
editor,
|
| 595 |
model_label,
|
| 596 |
prompt,
|
| 597 |
-
work_mode,
|
| 598 |
crop_padding,
|
| 599 |
-
|
|
|
|
| 600 |
steps,
|
| 601 |
guidance_scale,
|
| 602 |
strength,
|
|
|
|
| 13 |
|
| 14 |
|
| 15 |
MODEL_CHOICES = {
|
|
|
|
| 16 |
"DreamShaper 8 Inpainting": "Lykon/dreamshaper-8-inpainting",
|
| 17 |
+
"Official SD1.5 Inpainting": "stable-diffusion-v1-5/stable-diffusion-inpainting",
|
| 18 |
}
|
| 19 |
|
| 20 |
DEFAULT_MODEL_LABEL = "DreamShaper 8 Inpainting"
|
|
|
|
| 328 |
editor_value,
|
| 329 |
model_label: str,
|
| 330 |
prompt: str,
|
|
|
|
| 331 |
crop_padding: int,
|
| 332 |
+
work_mode: str,
|
| 333 |
+
min_working_window: int,
|
| 334 |
steps: int,
|
| 335 |
guidance_scale: float,
|
| 336 |
strength: float,
|
|
|
|
| 361 |
original_image,
|
| 362 |
generation_mask_source,
|
| 363 |
crop_padding=int(crop_padding),
|
| 364 |
+
min_crop_side=int(min_working_window),
|
| 365 |
)
|
| 366 |
|
| 367 |
gen_image = crop_info["padded_image"]
|
|
|
|
| 410 |
|
| 411 |
if paste_whole_crop:
|
| 412 |
final_result.paste(generated, (left, top))
|
| 413 |
+
paste_mode = "whole generated crop"
|
| 414 |
else:
|
| 415 |
final_mask = original_mask.crop(crop_bbox)
|
| 416 |
|
|
|
|
| 424 |
|
| 425 |
crop_report = (
|
| 426 |
f"- raw mask bbox: `{crop_info['raw_bbox']}`\n"
|
| 427 |
+
f"- working crop bbox: `{crop_bbox}`\n"
|
| 428 |
+
f"- working crop size: `{crop_size[0]}x{crop_size[1]}`\n"
|
| 429 |
f"- generation size: `{padded_size[0]}x{padded_size[1]}`\n"
|
| 430 |
f"- paste mode: `{paste_mode}`"
|
| 431 |
)
|
|
|
|
| 433 |
else:
|
| 434 |
if paste_whole_crop:
|
| 435 |
final_result = generated
|
| 436 |
+
paste_mode = "whole generated image"
|
| 437 |
else:
|
| 438 |
final_mask = original_mask
|
| 439 |
|
|
|
|
| 446 |
paste_mode = "masked area only"
|
| 447 |
|
| 448 |
crop_report = (
|
| 449 |
+
"- working crop: `none`\n"
|
| 450 |
f"- original size: `{original_image.size[0]}x{original_image.size[1]}`\n"
|
| 451 |
f"- generation size: `{padded_size[0]}x{padded_size[1]}`\n"
|
| 452 |
f"- paste mode: `{paste_mode}`"
|
|
|
|
| 463 |
"- vae: `TAESD`\n"
|
| 464 |
f"- work mode: `{work_mode}`\n"
|
| 465 |
"- resize: `none`\n"
|
| 466 |
+
f"- context around mask: `{crop_padding}` px\n"
|
| 467 |
+
f"- minimum working window: `{min_working_window}` px\n"
|
| 468 |
f"- padding to multiple of 8: `{padding_used}`\n"
|
| 469 |
f"{crop_report}\n"
|
| 470 |
f"- steps: `{steps}`\n"
|
|
|
|
| 474 |
f"- seed: `{seed}`\n"
|
| 475 |
f"- time: `{elapsed:.1f}s`\n\n"
|
| 476 |
"This version does not downscale or upscale. "
|
| 477 |
+
"In crop mode it sends the mask bbox plus surrounding context to the model, "
|
| 478 |
+
"then pastes the result back into the original image."
|
| 479 |
)
|
| 480 |
|
| 481 |
return final_result, info
|
| 482 |
|
| 483 |
|
| 484 |
+
with gr.Blocks(title="SD15 Light Inpaint CPU") as demo:
|
| 485 |
gr.Markdown(
|
| 486 |
+
"# SD15 Light Inpaint CPU\n\n"
|
| 487 |
+
"Upload an image, draw over the area you want to repaint, and describe what should appear there.\n\n"
|
| 488 |
+
"Default mode uses a local crop around the mask instead of resizing the whole image. "
|
| 489 |
+
"This keeps the model working at the original local visual scale while still reducing the amount of image sent to the model."
|
|
|
|
| 490 |
)
|
| 491 |
|
| 492 |
with gr.Row():
|
| 493 |
with gr.Column():
|
| 494 |
editor = gr.ImageEditor(
|
| 495 |
+
label="Image + mask",
|
| 496 |
type="pil",
|
| 497 |
)
|
| 498 |
|
|
|
|
| 508 |
lines=3,
|
| 509 |
)
|
| 510 |
|
| 511 |
+
crop_padding = gr.Slider(
|
| 512 |
+
label="Context around mask",
|
| 513 |
+
minimum=32,
|
| 514 |
+
maximum=384,
|
| 515 |
+
step=32,
|
| 516 |
+
value=128,
|
| 517 |
+
)
|
| 518 |
+
|
| 519 |
+
with gr.Accordion("Advanced", open=False):
|
| 520 |
work_mode = gr.Radio(
|
| 521 |
label="Work mode",
|
| 522 |
choices=[
|
|
|
|
| 526 |
value="Crop around mask",
|
| 527 |
)
|
| 528 |
|
| 529 |
+
min_working_window = gr.Slider(
|
| 530 |
+
label="Minimum working window size",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
minimum=128,
|
| 532 |
maximum=768,
|
| 533 |
step=64,
|
|
|
|
| 535 |
)
|
| 536 |
|
| 537 |
paste_whole_crop = gr.Checkbox(
|
| 538 |
+
label="Paste whole generated crop back, diagnostic",
|
| 539 |
value=False,
|
| 540 |
)
|
| 541 |
|
|
|
|
| 542 |
steps = gr.Slider(
|
| 543 |
label="Steps",
|
| 544 |
minimum=2,
|
|
|
|
| 548 |
)
|
| 549 |
|
| 550 |
guidance_scale = gr.Slider(
|
| 551 |
+
label="Guidance scale / CFG. LCM usually works best around 1.0-2.0",
|
| 552 |
minimum=1.0,
|
| 553 |
maximum=8.0,
|
| 554 |
step=0.1,
|
|
|
|
| 594 |
editor,
|
| 595 |
model_label,
|
| 596 |
prompt,
|
|
|
|
| 597 |
crop_padding,
|
| 598 |
+
work_mode,
|
| 599 |
+
min_working_window,
|
| 600 |
steps,
|
| 601 |
guidance_scale,
|
| 602 |
strength,
|