Fix stuck UI spinners on LoRA select and light handlers
Browse filesHide Gradio progress on lightweight update handlers and collapse rapid
checkbox changes with always_last so weight sliders / size labels no
longer spin until a second interaction.
Co-Authored-By: Oz <oz-agent@warp.dev>
Files changed (2)
- app.py+27-7
- lora_registry.py+19-9
770 unmodified lines77177277377477577677777877910 unmodified lines7907917927937947957967977987998008018028038048058068078083 unmodified lines8128138148158168178188198208218228232 unmodified lines8268278288298308318328338348358368371 unmodified line839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876770 unmodified lines# ── Event wiring ─────────────────────────────────────────────────────────base_image.upload(fn=reencode_upload, inputs=[base_image], outputs=[base_image])base_image.change(fn=on_base_image_change, inputs=[base_image], outputs=[size_info])reference_images.change(fn=on_reference_change, inputs=[reference_images], outputs=[reference_info])# Every browser open re-reads the bucket JSON and refreshes selector choices.# Without this, choices stay frozen at process start and newly saved LoRAs10 unmodified linesinputs=[dynamic_loras_state, lora_selector],outputs=[lora_selector, catalog_save_select, catalog_remove_select,dynamic_loras_state, catalog_load_status],)reload_catalog_btn.click(fn=_on_page_load,inputs=[dynamic_loras_state, lora_selector],outputs=[lora_selector, catalog_save_select, catalog_remove_select,dynamic_loras_state, catalog_load_status],)# update_weight_sliders is the one imported from lora_registry now.lora_selector.change(fn=update_weight_sliders,inputs=[lora_selector, dynamic_loras_state],outputs=weight_sliders + [lora_prompt_display, selected_lora_details],)# add_custom_lora is also imported from lora_registry.3 unmodified linesinputs=[lora_repo_id, lora_weight_name, lora_adapter_name, dynamic_loras_state],outputs=[lora_status, lora_selector, dynamic_loras_state,catalog_save_select, catalog_remove_select],)catalog_save_select.change(fn=fill_catalog_save_form,inputs=[catalog_save_select, dynamic_loras_state],outputs=[catalog_save_title, catalog_save_weight, catalog_save_prompt,catalog_save_triggers, catalog_save_notes],)catalog_save_btn.click(fn=save_session_lora_to_catalog,2 unmodified linescatalog_save_triggers, catalog_save_notes],outputs=[catalog_save_status, lora_selector, catalog_save_select,catalog_remove_select, dynamic_loras_state],)catalog_remove_btn.click(fn=remove_lora,inputs=[catalog_remove_select, dynamic_loras_state, lora_selector],outputs=[catalog_remove_status, lora_selector, catalog_save_select,catalog_remove_select, dynamic_loras_state],)add_prompt_btn.click(1 unmodified lineinputs=[prompt_name_input, prompt_text_input, custom_prompts_state, custom_prompt_counter_state],outputs=[prompt_status, custom_prompts_state, custom_prompt_counter_state,custom_prompt_selector, delete_prompt_name, prompt_name_input],)delete_prompt_btn.click(fn=delete_custom_prompt,inputs=[delete_prompt_name, custom_prompt_selector, custom_prompts_state],outputs=[prompt_status, custom_prompts_state, custom_prompt_selector, delete_prompt_name],)custom_prompt_selector.change(fn=update_custom_prompt_display,inputs=[custom_prompt_selector, custom_prompts_state],outputs=[custom_prompt_display],)canvas_mode.change(fn=on_canvas_mode_change, inputs=[canvas_mode],outputs=[custom_width, custom_height])canvas_fit_mode.change(fn=on_fit_mode_change, inputs=[canvas_fit_mode],outputs=[pad_color])batch_vary.change(fn=on_batch_vary_change, inputs=[batch_vary],outputs=[sweep_min, sweep_max])output_gallery.select(fn=on_gallery_select, inputs=[output_gallery],outputs=[selected_output_state])# Keep the large Download button pointed at the selected gallery item# (or the latest item when nothing valid is selected).selected_output_state.change(fn=resolve_output_download_path,inputs=[selected_output_state, output_gallery],outputs=[download_output_btn],)output_gallery.change(fn=resolve_output_download_path,inputs=[selected_output_state, output_gallery],outputs=[download_output_btn],)# Native DownloadButton still saves the file; also open the served image# URL in a new browser tab so it can be viewed immediately.770 unmodified lines77177277377477577677777877978078178278378410 unmodified lines7957967977987998008018028038048058068078088098108118128138148158168178183 unmodified lines8228238248258268278288298308318328338348352 unmodified lines8388398408418428438448458468478488498508511 unmodified line853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896770 unmodified lines# ── Event wiring ─────────────────────────────────────────────────────────# Lightweight UI handlers: hide Gradio progress. On ZeroGPU/Spaces, the# default spinner often sticks on pure gr.update visibility changes# (LoRA weight sliders, canvas size text) until another event flushes UI._ui = dict(show_progress="hidden")base_image.upload(fn=reencode_upload, inputs=[base_image], outputs=[base_image], **_ui)base_image.change(fn=on_base_image_change, inputs=[base_image], outputs=[size_info], **_ui)reference_images.change(fn=on_reference_change, inputs=[reference_images], outputs=[reference_info], **_ui)# Every browser open re-reads the bucket JSON and refreshes selector choices.# Without this, choices stay frozen at process start and newly saved LoRAs10 unmodified linesinputs=[dynamic_loras_state, lora_selector],outputs=[lora_selector, catalog_save_select, catalog_remove_select,dynamic_loras_state, catalog_load_status],show_progress="hidden",)reload_catalog_btn.click(fn=_on_page_load,inputs=[dynamic_loras_state, lora_selector],outputs=[lora_selector, catalog_save_select, catalog_remove_select,dynamic_loras_state, catalog_load_status],show_progress="minimal",)# update_weight_sliders is the one imported from lora_registry now.# always_last: rapid multi-tick checkbox changes collapse to one update.lora_selector.change(fn=update_weight_sliders,inputs=[lora_selector, dynamic_loras_state],outputs=weight_sliders + [lora_prompt_display, selected_lora_details],show_progress="hidden",trigger_mode="always_last",)# add_custom_lora is also imported from lora_registry.3 unmodified linesinputs=[lora_repo_id, lora_weight_name, lora_adapter_name, dynamic_loras_state],outputs=[lora_status, lora_selector, dynamic_loras_state,catalog_save_select, catalog_remove_select],show_progress="minimal",)catalog_save_select.change(fn=fill_catalog_save_form,inputs=[catalog_save_select, dynamic_loras_state],outputs=[catalog_save_title, catalog_save_weight, catalog_save_prompt,catalog_save_triggers, catalog_save_notes],show_progress="hidden",)catalog_save_btn.click(fn=save_session_lora_to_catalog,2 unmodified linescatalog_save_triggers, catalog_save_notes],outputs=[catalog_save_status, lora_selector, catalog_save_select,catalog_remove_select, dynamic_loras_state],show_progress="minimal",)catalog_remove_btn.click(fn=remove_lora,inputs=[catalog_remove_select, dynamic_loras_state, lora_selector],outputs=[catalog_remove_status, lora_selector, catalog_save_select,catalog_remove_select, dynamic_loras_state],show_progress="minimal",)add_prompt_btn.click(1 unmodified lineinputs=[prompt_name_input, prompt_text_input, custom_prompts_state, custom_prompt_counter_state],outputs=[prompt_status, custom_prompts_state, custom_prompt_counter_state,custom_prompt_selector, delete_prompt_name, prompt_name_input],show_progress="hidden",)delete_prompt_btn.click(fn=delete_custom_prompt,inputs=[delete_prompt_name, custom_prompt_selector, custom_prompts_state],outputs=[prompt_status, custom_prompts_state, custom_prompt_selector, delete_prompt_name],show_progress="hidden",)custom_prompt_selector.change(fn=update_custom_prompt_display,inputs=[custom_prompt_selector, custom_prompts_state],outputs=[custom_prompt_display],show_progress="hidden",trigger_mode="always_last",)canvas_mode.change(fn=on_canvas_mode_change, inputs=[canvas_mode],outputs=[custom_width, custom_height], **_ui)canvas_fit_mode.change(fn=on_fit_mode_change, inputs=[canvas_fit_mode],outputs=[pad_color], **_ui)batch_vary.change(fn=on_batch_vary_change, inputs=[batch_vary],outputs=[sweep_min, sweep_max], **_ui)output_gallery.select(fn=on_gallery_select, inputs=[output_gallery],outputs=[selected_output_state], show_progress="hidden")# Keep the large Download button pointed at the selected gallery item# (or the latest item when nothing valid is selected).selected_output_state.change(fn=resolve_output_download_path,inputs=[selected_output_state, output_gallery],outputs=[download_output_btn],show_progress="hidden",)output_gallery.change(fn=resolve_output_download_path,inputs=[selected_output_state, output_gallery],outputs=[download_output_btn],show_progress="hidden",)# Native DownloadButton still saves the file; also open the served image# URL in a new browser tab so it can be viewed immediately.
624 unmodified lines6256266276286296306316326336346356366376386396406416426436446456465 unmodified lines652653654655656657658659624 unmodified linesdef update_weight_sliders(selected_titles, dynamic_loras):selected_styles = [get_style_by_title(t, dynamic_loras)for t in (selected_titles or [])if get_style_by_title(t, dynamic_loras)]slider_updates = []for i in range(MAX_LORA_SLOTS):if i < len(selected_styles):style = selected_styles[i]slider_updates.append(gr.update(visible=True,label=f"{style['title']} — weight",value=style.get("default_weight", 1.0),))else:slider_updates.append(gr.update(visible=False, value=1.0))# Refill from selected LoRA defaults whenever the selection changes.# The textbox itself is interactive so the user can tweak the combined5 unmodified lineselse:lora_prompt_update = gr.update(value="", visible=False)details = format_selected_lora_details(selected_titles, dynamic_loras)details_update = gr.update(value=details, visible=bool(details))return slider_updates + [lora_prompt_update, details_update]624 unmodified lines6256266276286296306316326336346356366376386396406416426436446456466476486496506516526536545 unmodified lines660661662663664665666667668669624 unmodified linesdef update_weight_sliders(selected_titles, dynamic_loras):# Resolve each title once (previous code called get_style_by_title twice).selected_styles = []for t in (selected_titles or []):style = get_style_by_title(t, dynamic_loras)if style is not None:selected_styles.append(style)slider_updates = []for i in range(MAX_LORA_SLOTS):if i < len(selected_styles):style = selected_styles[i]slider_updates.append(gr.update(visible=True,interactive=True,label=f"{style['title']} — weight",value=float(style.get("default_weight", 1.0)),))else:# Keep label stable when hiding — fewer DOM thrash / stuck-progress cases.slider_updates.append(gr.update(visible=False,interactive=False,value=1.0,))# Refill from selected LoRA defaults whenever the selection changes.# The textbox itself is interactive so the user can tweak the combined5 unmodified lineselse:lora_prompt_update = gr.update(value="", visible=False)details = format_selected_lora_details([s["title"] for s in selected_styles], dynamic_loras)details_update = gr.update(value=details or "", visible=bool(details))return slider_updates + [lora_prompt_update, details_update]
app.py+27-7
lora_registry.py+19-9