Equalize image boxes and fix reference clipboard paste
Browse filesMatch Base/Reference/Output heights, keep empty gallery source controls
more visible, and add a dedicated clipboard paste box that appends into
the multi-image reference gallery.
Co-Authored-By: Oz <oz-agent@warp.dev>
app.py
CHANGED
|
@@ -420,11 +420,42 @@ def update_custom_prompt_display(selected_names, prompts_state):
|
|
| 420 |
|
| 421 |
# ββ UI βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 422 |
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
"""
|
| 429 |
|
| 430 |
# Gradio 6.0: theme/css go on launch(), not Blocks()
|
|
@@ -446,22 +477,40 @@ with gr.Blocks() as demo:
|
|
| 446 |
with gr.Tabs() as main_tabs:
|
| 447 |
# ββ Generate tab βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 448 |
with gr.Tab("π¨ Generate", id="tab_generate"):
|
| 449 |
-
with gr.Row(equal_height=
|
| 450 |
with gr.Column(scale=1):
|
| 451 |
base_image = gr.Image(
|
| 452 |
label="Base Image", type="pil",
|
| 453 |
-
sources=["upload", "clipboard"],
|
|
|
|
|
|
|
| 454 |
)
|
| 455 |
size_info = gr.Markdown("*No image uploaded yet*")
|
| 456 |
|
| 457 |
reference_images = gr.Gallery(
|
| 458 |
label="Reference Image(s) β optional", type="filepath",
|
| 459 |
-
columns=2, rows=1,
|
|
|
|
|
|
|
|
|
|
| 460 |
sources=["upload", "clipboard"],
|
|
|
|
| 461 |
elem_id="reference_gallery",
|
| 462 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 463 |
reference_info = gr.Markdown("π· No reference images")
|
| 464 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
| 465 |
|
| 466 |
prompt = gr.Text(label="Prompt", max_lines=3,
|
| 467 |
placeholder="Describe the edit, or leave blank for style-only LoRAs")
|
|
@@ -523,8 +572,10 @@ with gr.Blocks() as demo:
|
|
| 523 |
with gr.Column(scale=1):
|
| 524 |
output_gallery = gr.Gallery(
|
| 525 |
label="Output", type="filepath", columns=2, rows=2,
|
| 526 |
-
height=
|
|
|
|
| 527 |
object_fit="contain", show_label=True,
|
|
|
|
| 528 |
)
|
| 529 |
used_seed = gr.Textbox(
|
| 530 |
label="π± Seed used (last run)",
|
|
@@ -846,9 +897,25 @@ with gr.Blocks() as demo:
|
|
| 846 |
# (LoRA weight sliders, canvas size text) until another event flushes UI.
|
| 847 |
_ui = dict(show_progress="hidden")
|
| 848 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 849 |
base_image.upload(fn=reencode_upload, inputs=[base_image], outputs=[base_image], **_ui)
|
| 850 |
base_image.change(fn=on_base_image_change, inputs=[base_image], outputs=[size_info], **_ui)
|
| 851 |
reference_images.change(fn=on_reference_change, inputs=[reference_images], outputs=[reference_info], **_ui)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 852 |
|
| 853 |
# Every browser open re-reads the bucket JSON and refreshes selector choices.
|
| 854 |
# Without this, choices stay frozen at process start and newly saved LoRAs
|
|
|
|
| 420 |
|
| 421 |
# ββ UI βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 422 |
|
| 423 |
+
# Shared viewport height so Base / Reference / Output feel the same size.
|
| 424 |
+
_IMAGE_BOX_H = 360
|
| 425 |
+
|
| 426 |
+
css = f"""
|
| 427 |
+
#col-container {{ margin: 0 auto; max-width: 1100px; }}
|
| 428 |
+
#main-title h1 {{ font-size: 2.4em !important; }}
|
| 429 |
+
.lora-weight-row {{ background: var(--block-background-fill); border-radius: 8px; padding: 4px 12px; margin-bottom: 4px; }}
|
| 430 |
+
|
| 431 |
+
/* Equal image stage heights */
|
| 432 |
+
#base_image,
|
| 433 |
+
#reference_gallery,
|
| 434 |
+
#output_gallery {{
|
| 435 |
+
min-height: {_IMAGE_BOX_H}px !important;
|
| 436 |
+
}}
|
| 437 |
+
#base_image .image-container,
|
| 438 |
+
#base_image img,
|
| 439 |
+
#reference_gallery .grid-wrap,
|
| 440 |
+
#output_gallery .grid-wrap {{
|
| 441 |
+
min-height: {_IMAGE_BOX_H - 48}px !important;
|
| 442 |
+
}}
|
| 443 |
+
|
| 444 |
+
/* Empty Gallery often hides source/clipboard controls until an item exists.
|
| 445 |
+
Force the empty-state toolbar/buttons to stay visible. */
|
| 446 |
+
#reference_gallery button,
|
| 447 |
+
#reference_gallery .icon-button,
|
| 448 |
+
#reference_gallery [class*="source"],
|
| 449 |
+
#reference_gallery [class*="upload"],
|
| 450 |
+
#reference_gallery .empty,
|
| 451 |
+
#reference_gallery .wrap {{
|
| 452 |
+
opacity: 1 !important;
|
| 453 |
+
visibility: visible !important;
|
| 454 |
+
pointer-events: auto !important;
|
| 455 |
+
}}
|
| 456 |
+
#reference_clipboard .image-container {{
|
| 457 |
+
min-height: 72px !important;
|
| 458 |
+
}}
|
| 459 |
"""
|
| 460 |
|
| 461 |
# Gradio 6.0: theme/css go on launch(), not Blocks()
|
|
|
|
| 477 |
with gr.Tabs() as main_tabs:
|
| 478 |
# ββ Generate tab βββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 479 |
with gr.Tab("π¨ Generate", id="tab_generate"):
|
| 480 |
+
with gr.Row(equal_height=True):
|
| 481 |
with gr.Column(scale=1):
|
| 482 |
base_image = gr.Image(
|
| 483 |
label="Base Image", type="pil",
|
| 484 |
+
sources=["upload", "clipboard"],
|
| 485 |
+
height=_IMAGE_BOX_H,
|
| 486 |
+
elem_id="base_image",
|
| 487 |
)
|
| 488 |
size_info = gr.Markdown("*No image uploaded yet*")
|
| 489 |
|
| 490 |
reference_images = gr.Gallery(
|
| 491 |
label="Reference Image(s) β optional", type="filepath",
|
| 492 |
+
columns=2, rows=1,
|
| 493 |
+
height=_IMAGE_BOX_H,
|
| 494 |
+
allow_preview=True,
|
| 495 |
+
object_fit="contain",
|
| 496 |
sources=["upload", "clipboard"],
|
| 497 |
+
interactive=True,
|
| 498 |
elem_id="reference_gallery",
|
| 499 |
)
|
| 500 |
+
# Empty Gallery often hides the clipboard icon; this always-visible
|
| 501 |
+
# paste target appends into the reference gallery.
|
| 502 |
+
reference_clipboard = gr.Image(
|
| 503 |
+
label="π Paste reference from clipboard (appends)",
|
| 504 |
+
type="filepath",
|
| 505 |
+
sources=["clipboard"],
|
| 506 |
+
height=90,
|
| 507 |
+
elem_id="reference_clipboard",
|
| 508 |
+
)
|
| 509 |
reference_info = gr.Markdown("π· No reference images")
|
| 510 |
+
gr.Markdown(
|
| 511 |
+
"*For Face Swap, the first Reference image is used as the face source. "
|
| 512 |
+
"Use the gallery upload, or the clipboard paste box below it.*"
|
| 513 |
+
)
|
| 514 |
|
| 515 |
prompt = gr.Text(label="Prompt", max_lines=3,
|
| 516 |
placeholder="Describe the edit, or leave blank for style-only LoRAs")
|
|
|
|
| 572 |
with gr.Column(scale=1):
|
| 573 |
output_gallery = gr.Gallery(
|
| 574 |
label="Output", type="filepath", columns=2, rows=2,
|
| 575 |
+
height=_IMAGE_BOX_H,
|
| 576 |
+
allow_preview=True, preview=True,
|
| 577 |
object_fit="contain", show_label=True,
|
| 578 |
+
elem_id="output_gallery",
|
| 579 |
)
|
| 580 |
used_seed = gr.Textbox(
|
| 581 |
label="π± Seed used (last run)",
|
|
|
|
| 897 |
# (LoRA weight sliders, canvas size text) until another event flushes UI.
|
| 898 |
_ui = dict(show_progress="hidden")
|
| 899 |
|
| 900 |
+
def append_reference_from_clipboard(img, gallery):
|
| 901 |
+
"""Append a clipboard paste into the multi-image reference gallery."""
|
| 902 |
+
if img is None:
|
| 903 |
+
return gr.update(), gr.update(), gr.update()
|
| 904 |
+
current = list(gallery or [])
|
| 905 |
+
current.append(img)
|
| 906 |
+
info = on_reference_change(current)
|
| 907 |
+
# Clear the paste box so the next clipboard paste is accepted cleanly.
|
| 908 |
+
return current, gr.update(value=None), info
|
| 909 |
+
|
| 910 |
base_image.upload(fn=reencode_upload, inputs=[base_image], outputs=[base_image], **_ui)
|
| 911 |
base_image.change(fn=on_base_image_change, inputs=[base_image], outputs=[size_info], **_ui)
|
| 912 |
reference_images.change(fn=on_reference_change, inputs=[reference_images], outputs=[reference_info], **_ui)
|
| 913 |
+
reference_clipboard.change(
|
| 914 |
+
fn=append_reference_from_clipboard,
|
| 915 |
+
inputs=[reference_clipboard, reference_images],
|
| 916 |
+
outputs=[reference_images, reference_clipboard, reference_info],
|
| 917 |
+
show_progress="hidden",
|
| 918 |
+
)
|
| 919 |
|
| 920 |
# Every browser open re-reads the bucket JSON and refreshes selector choices.
|
| 921 |
# Without this, choices stay frozen at process start and newly saved LoRAs
|