Maxim Kruglikov Claude Opus 4.7 (1M context) commited on
Commit
c0a71d7
·
1 Parent(s): bdf41b9

Replace Gallery-as-input with File picker + Gallery preview

Browse files

The interactive Gallery was ignoring preview=False for single-image
layout and letterboxing a lone reference across the full panel width
with large blank space above. Switch to a clean two-component pattern:
gr.File for upload (compact file list) + a non-interactive gr.Gallery
below it driven by a change handler for thumbnails. Deterministic tile
sizing, proper aspect ratios.

compare_styles already accepted filepath strings via _coerce_to_pil, so
the inference path needs no change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -158,20 +158,33 @@ with gr.Blocks(title="MegaStyle Style Comparison", theme=gr.themes.Soft()) as de
158
  )
159
  with gr.Column(scale=1):
160
  gr.Markdown(f"### 2. Reference images (up to {MAX_REFERENCES})")
161
- refs_in = gr.Gallery(
 
 
 
 
 
 
162
  show_label=False,
163
- height=360,
164
  columns=4,
165
  rows=2,
 
166
  object_fit="contain",
167
  preview=False,
168
  allow_preview=False,
169
  show_fullscreen_button=False,
170
  show_share_button=False,
171
  show_download_button=False,
172
- interactive=True,
173
  )
174
 
 
 
 
 
 
 
 
175
  with gr.Row():
176
  compare_btn = gr.Button("Compare styles", variant="primary", size="lg")
177
 
 
158
  )
159
  with gr.Column(scale=1):
160
  gr.Markdown(f"### 2. Reference images (up to {MAX_REFERENCES})")
161
+ refs_in = gr.File(
162
+ file_count="multiple",
163
+ file_types=["image"],
164
+ show_label=False,
165
+ height=140,
166
+ )
167
+ refs_preview = gr.Gallery(
168
  show_label=False,
 
169
  columns=4,
170
  rows=2,
171
+ height=220,
172
  object_fit="contain",
173
  preview=False,
174
  allow_preview=False,
175
  show_fullscreen_button=False,
176
  show_share_button=False,
177
  show_download_button=False,
178
+ interactive=False,
179
  )
180
 
181
+ def _files_to_gallery(files: list | None) -> list[str]:
182
+ if not files:
183
+ return []
184
+ return [getattr(f, "name", f) for f in files]
185
+
186
+ refs_in.change(fn=_files_to_gallery, inputs=refs_in, outputs=refs_preview)
187
+
188
  with gr.Row():
189
  compare_btn = gr.Button("Compare styles", variant="primary", size="lg")
190