Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +26 -4
- image_utils.py +17 -7
app.py
CHANGED
|
@@ -628,7 +628,7 @@ with gr.Blocks() as demo:
|
|
| 628 |
"#FF0000", "#00FF00", "#0000FF"],
|
| 629 |
color_mode="fixed"),
|
| 630 |
eraser=gr.Eraser(default_size=20),
|
| 631 |
-
layers=
|
| 632 |
sources=["upload", "clipboard"],
|
| 633 |
height=420,
|
| 634 |
)
|
|
@@ -810,7 +810,21 @@ with gr.Blocks() as demo:
|
|
| 810 |
|
| 811 |
output_gallery.select(fn=on_gallery_select, inputs=[output_gallery],
|
| 812 |
outputs=[selected_output_state])
|
|
|
|
|
|
|
|
|
|
|
|
|
| 813 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 814 |
run_event = run_button.click(
|
| 815 |
fn=infer,
|
| 816 |
inputs=[base_image, reference_images, prompt, lora_prompt_display, custom_prompt_display,
|
|
@@ -867,10 +881,18 @@ with gr.Blocks() as demo:
|
|
| 867 |
for _c in (ext_up, ext_down, ext_left, ext_right, ext_fill):
|
| 868 |
_c.change(fn=_update_extend_preview,
|
| 869 |
inputs=_extend_preview_inputs, outputs=_extend_preview_outputs)
|
| 870 |
-
#
|
| 871 |
-
#
|
| 872 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 873 |
inputs=_extend_preview_inputs, outputs=_extend_preview_outputs)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 874 |
|
| 875 |
# Run: extend, then hand the new PIL back to the editor. `render_extend_
|
| 876 |
# schematic` re-runs via editor.change once the new image lands, so no
|
|
|
|
| 628 |
"#FF0000", "#00FF00", "#0000FF"],
|
| 629 |
color_mode="fixed"),
|
| 630 |
eraser=gr.Eraser(default_size=20),
|
| 631 |
+
layers=False,
|
| 632 |
sources=["upload", "clipboard"],
|
| 633 |
height=420,
|
| 634 |
)
|
|
|
|
| 810 |
|
| 811 |
output_gallery.select(fn=on_gallery_select, inputs=[output_gallery],
|
| 812 |
outputs=[selected_output_state])
|
| 813 |
+
# Reset any stale gallery selection before a new run starts, so Send→Base
|
| 814 |
+
# / Send→Ref after this run can't accidentally reuse a path from the
|
| 815 |
+
# previous run's gallery contents.
|
| 816 |
+
run_button.click(fn=lambda: None, outputs=[selected_output_state])
|
| 817 |
|
| 818 |
+
run_event = run_button.click(
|
| 819 |
+
fn=infer,
|
| 820 |
+
inputs=[base_image, reference_images, prompt, lora_prompt_display, custom_prompt_display,
|
| 821 |
+
lora_selector, seed, randomize_seed, guidance_scale, steps, upscale_factor,
|
| 822 |
+
canvas_mode, custom_width, custom_height, canvas_fit_mode, pad_color,
|
| 823 |
+
batch_count, batch_vary, sweep_min, sweep_max,
|
| 824 |
+
dynamic_loras_state] + weight_sliders,
|
| 825 |
+
outputs=[output_gallery, used_seed],
|
| 826 |
+
)
|
| 827 |
+
|
| 828 |
run_event = run_button.click(
|
| 829 |
fn=infer,
|
| 830 |
inputs=[base_image, reference_images, prompt, lora_prompt_display, custom_prompt_display,
|
|
|
|
| 881 |
for _c in (ext_up, ext_down, ext_left, ext_right, ext_fill):
|
| 882 |
_c.change(fn=_update_extend_preview,
|
| 883 |
inputs=_extend_preview_inputs, outputs=_extend_preview_outputs)
|
| 884 |
+
# Refresh the schematic when a NEW image lands in the editor — not on every
|
| 885 |
+
# `change` event. `editor.change` fires very frequently on iOS Safari/Chrome
|
| 886 |
+
# (once per stroke/layer/crop-preview) and the round-trips OOM'd the tab
|
| 887 |
+
# even for small uploads. `.upload` fires only when a new image comes in
|
| 888 |
+
# via the upload/clipboard sources, which is the case the preview actually
|
| 889 |
+
# cares about (image dimensions changed → schematic scale needs redrawing).
|
| 890 |
+
editor.upload(fn=_update_extend_preview,
|
| 891 |
inputs=_extend_preview_inputs, outputs=_extend_preview_outputs)
|
| 892 |
+
# HEIC uploads bypass the editor's own upload event because they come from
|
| 893 |
+
# the separate File component, so wire that path in explicitly too.
|
| 894 |
+
heic_uploader.upload(fn=_update_extend_preview,
|
| 895 |
+
inputs=_extend_preview_inputs, outputs=_extend_preview_outputs)
|
| 896 |
|
| 897 |
# Run: extend, then hand the new PIL back to the editor. `render_extend_
|
| 898 |
# schematic` re-runs via editor.change once the new image lands, so no
|
image_utils.py
CHANGED
|
@@ -221,16 +221,26 @@ def load_heic_to_editor(path):
|
|
| 221 |
def _resolve_gallery_path(selected_path, gallery_value):
|
| 222 |
"""Pick the path the Send-to-* buttons should use.
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
"""
|
| 228 |
-
if selected_path:
|
| 229 |
-
return selected_path
|
| 230 |
if not gallery_value:
|
| 231 |
return None
|
| 232 |
-
|
| 233 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 234 |
|
| 235 |
|
| 236 |
def send_output_to_base(selected_path, gallery_value):
|
|
|
|
| 221 |
def _resolve_gallery_path(selected_path, gallery_value):
|
| 222 |
"""Pick the path the Send-to-* buttons should use.
|
| 223 |
|
| 224 |
+
Bug we're guarding against: `selected_path` comes from a gr.State that
|
| 225 |
+
persists across generation runs, so after a new batch has replaced the
|
| 226 |
+
gallery it can still hold a stale path from a previous run — or even a
|
| 227 |
+
path from the *first* image of the current batch, because some Gradio
|
| 228 |
+
builds auto-fire .select(index=0) right after the gallery repopulates.
|
| 229 |
+
|
| 230 |
+
Rule: only honour the selection if it's actually still one of the paths
|
| 231 |
+
currently in the gallery. Otherwise use the *last* (most recent) item.
|
| 232 |
"""
|
|
|
|
|
|
|
| 233 |
if not gallery_value:
|
| 234 |
return None
|
| 235 |
+
|
| 236 |
+
current_paths = []
|
| 237 |
+
for item in gallery_value:
|
| 238 |
+
p = item[0] if isinstance(item, (list, tuple)) else item
|
| 239 |
+
current_paths.append(p)
|
| 240 |
+
|
| 241 |
+
if selected_path and selected_path in current_paths:
|
| 242 |
+
return selected_path
|
| 243 |
+
return current_paths[-1]
|
| 244 |
|
| 245 |
|
| 246 |
def send_output_to_base(selected_path, gallery_value):
|