Add solid-color base image for t2i-style LoRA runs
Browse filesColorPicker + button fills Base with a unicolor canvas (Custom W×H or
1024×1024) so workflows that require a base image still work without a photo.
Co-Authored-By: Oz <oz-agent@warp.dev>
- app.py +28 -0
- image_utils.py +25 -0
app.py
CHANGED
|
@@ -41,6 +41,7 @@ from image_utils import (
|
|
| 41 |
compute_canvas_dimensions,
|
| 42 |
fit_to_canvas,
|
| 43 |
on_base_image_change,
|
|
|
|
| 44 |
collect_reference_images,
|
| 45 |
reference_info_text,
|
| 46 |
compact_reference_slots,
|
|
@@ -724,6 +725,25 @@ with gr.Blocks() as demo:
|
|
| 724 |
)
|
| 725 |
with gr.Row(elem_classes="slot-move-row"):
|
| 726 |
base_down_btn = gr.Button("↓ Base → Ref1", size="sm")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 727 |
size_info = gr.Markdown("*No image uploaded yet*")
|
| 728 |
run_button_top = gr.Button(
|
| 729 |
"▶ Generate", variant="primary", size="lg",
|
|
@@ -1210,6 +1230,14 @@ with gr.Blocks() as demo:
|
|
| 1210 |
|
| 1211 |
base_image.upload(fn=reencode_upload, inputs=[base_image], outputs=[base_image], **_ui)
|
| 1212 |
base_image.change(fn=on_base_image_change, inputs=[base_image], outputs=[size_info], **_ui)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1213 |
|
| 1214 |
# Progressive ref slots: pack non-empty images upward on any change so
|
| 1215 |
# deleting Ref1 shifts Ref2/3 up instead of wiping them.
|
|
|
|
| 41 |
compute_canvas_dimensions,
|
| 42 |
fit_to_canvas,
|
| 43 |
on_base_image_change,
|
| 44 |
+
make_solid_base_image,
|
| 45 |
collect_reference_images,
|
| 46 |
reference_info_text,
|
| 47 |
compact_reference_slots,
|
|
|
|
| 725 |
)
|
| 726 |
with gr.Row(elem_classes="slot-move-row"):
|
| 727 |
base_down_btn = gr.Button("↓ Base → Ref1", size="sm")
|
| 728 |
+
# t2i-style workflows still need a base image; solid colour
|
| 729 |
+
# often becomes the background for i2i LoRAs used as t2i.
|
| 730 |
+
with gr.Row():
|
| 731 |
+
base_solid_color = gr.ColorPicker(
|
| 732 |
+
label="Solid base colour",
|
| 733 |
+
value="#FFFFFF",
|
| 734 |
+
scale=1,
|
| 735 |
+
elem_id="base_solid_color",
|
| 736 |
+
)
|
| 737 |
+
make_solid_base_btn = gr.Button(
|
| 738 |
+
"⬜ Use solid base",
|
| 739 |
+
size="sm",
|
| 740 |
+
scale=1,
|
| 741 |
+
elem_id="make_solid_base_btn",
|
| 742 |
+
)
|
| 743 |
+
gr.Markdown(
|
| 744 |
+
"*No photo? Use a solid base for t2i-style runs. "
|
| 745 |
+
"Size follows Custom canvas W×H if set, else 1024×1024.*",
|
| 746 |
+
)
|
| 747 |
size_info = gr.Markdown("*No image uploaded yet*")
|
| 748 |
run_button_top = gr.Button(
|
| 749 |
"▶ Generate", variant="primary", size="lg",
|
|
|
|
| 1230 |
|
| 1231 |
base_image.upload(fn=reencode_upload, inputs=[base_image], outputs=[base_image], **_ui)
|
| 1232 |
base_image.change(fn=on_base_image_change, inputs=[base_image], outputs=[size_info], **_ui)
|
| 1233 |
+
make_solid_base_btn.click(
|
| 1234 |
+
fn=make_solid_base_image,
|
| 1235 |
+
inputs=[base_solid_color, canvas_mode, custom_width, custom_height],
|
| 1236 |
+
outputs=[base_image],
|
| 1237 |
+
show_progress="hidden",
|
| 1238 |
+
).then(
|
| 1239 |
+
fn=on_base_image_change, inputs=[base_image], outputs=[size_info], **_ui,
|
| 1240 |
+
)
|
| 1241 |
|
| 1242 |
# Progressive ref slots: pack non-empty images upward on any change so
|
| 1243 |
# deleting Ref1 shifts Ref2/3 up instead of wiping them.
|
image_utils.py
CHANGED
|
@@ -135,6 +135,31 @@ def on_base_image_change(img) -> str:
|
|
| 135 |
return f"*Could not read dimensions: {e}*"
|
| 136 |
|
| 137 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
MAX_REFERENCE_IMAGES = 3
|
| 139 |
# base + 3 refs — used by reorder helpers
|
| 140 |
MAX_IMAGE_SLOTS = 1 + MAX_REFERENCE_IMAGES
|
|
|
|
| 135 |
return f"*Could not read dimensions: {e}*"
|
| 136 |
|
| 137 |
|
| 138 |
+
def make_solid_base_image(
|
| 139 |
+
color: str = "#FFFFFF",
|
| 140 |
+
canvas_mode: str = "Auto (from base image)",
|
| 141 |
+
custom_width: int = 1024,
|
| 142 |
+
custom_height: int = 1024,
|
| 143 |
+
) -> Image.Image:
|
| 144 |
+
"""Unicolor base PNG for t2i-style runs that still require a base image.
|
| 145 |
+
|
| 146 |
+
Uses Custom canvas W×H when canvas mode is Custom; otherwise 1024×1024
|
| 147 |
+
(matches Auto longest-side target). Colour often becomes the background.
|
| 148 |
+
"""
|
| 149 |
+
if canvas_mode == "Custom":
|
| 150 |
+
w, h = _snap16(custom_width or 1024), _snap16(custom_height or 1024)
|
| 151 |
+
else:
|
| 152 |
+
w, h = 1024, 1024
|
| 153 |
+
try:
|
| 154 |
+
fill = ImageColor.getrgb(color or "#FFFFFF")
|
| 155 |
+
except Exception:
|
| 156 |
+
fill = (255, 255, 255)
|
| 157 |
+
gr.Warning(f"Could not parse colour {color!r} — using white.")
|
| 158 |
+
img = Image.new("RGB", (w, h), fill)
|
| 159 |
+
gr.Info(f"Solid base {w}×{h} ({color or '#FFFFFF'})")
|
| 160 |
+
return img
|
| 161 |
+
|
| 162 |
+
|
| 163 |
MAX_REFERENCE_IMAGES = 3
|
| 164 |
# base + 3 refs — used by reorder helpers
|
| 165 |
MAX_IMAGE_SLOTS = 1 + MAX_REFERENCE_IMAGES
|