Spaces:
Sleeping
fixed layout to fit 3 across on laptop & fixed reset button in viewer
Browse filesRoot cause — In Gradio 6.10, the Model3D Undo (reset) button is wired to a Svelte-local state has_change_history in Index-DN7eG78L.js:330 that only flips to true inside handle_change, which fires only when the user uploads through Model3D's own upload widget. Since your app supplies the model value programmatically from the gr.File component, that handler never runs, so the button stays permanently disabled. The has_change_history flag is not exposed as a Python prop, so it can't be set from app.py.
Fix — In app.py:
Added APP_HEAD containing a small <script> with a MutationObserver that strips the disabled attribute off any .model3D button[aria-label="Undo"] whenever Svelte sets it. The button's onclick handler is still wired up — disabling only blocks the click — so once enabled, clicks reach handle_undo → canvas3d.reset_camera_position() → viewer.resetCamera().
Added a small CSS rule in APP_CSS so the button no longer renders in its grayed-out state.
Moved css and head from the gr.Blocks(...) constructor to demo.launch(...), since Gradio 6.0 moved those parameters and the old call site was already emitting a deprecation warning.
31 unmodified lines323334353637164 unmodified lines20220320420520620720817 unmodified lines226227228229230231232117 unmodified lines35035135235331 unmodified lines.gradio-container .prose {margin-bottom: 0.4rem !important;}"""164 unmodified linesdef build_demo() -> gr.Blocks:with gr.Blocks(title="STL TIFF Slicer", css=APP_CSS) as demo:gr.Markdown("""# STL to TIFF Slicer17 unmodified lineswith gr.Row():for i in range(3):with gr.Column():stl_file = gr.File(label=f"STL File {i + 1}",file_types=[".stl"],117 unmodified linesif __name__ == "__main__":demo.launch(ssr_mode=False)31 unmodified lines32333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586164 unmodified lines25125225325425525625717 unmodified lines275276277278279280281117 unmodified lines39940040140231 unmodified lines.gradio-container .prose {margin-bottom: 0.4rem !important;}.model3D button[aria-label="Undo"] {color: var(--block-label-text-color) !important;cursor: pointer !important;opacity: 1 !important;}"""# Gradio 6.10's gr.Model3D leaves the Undo (reset view) button permanently# disabled when the value is supplied programmatically — its `has_change_history`# state only flips on uploads through Model3D's own upload widget. This script# strips the disabled attribute so clicks reach Svelte's handle_undo, which# calls reset_camera_position on the underlying canvas.APP_HEAD = """<script>(function () {function enableUndoButtons(root) {(root || document).querySelectorAll('.model3D button[aria-label="Undo"]').forEach(function (btn) {if (btn.disabled) {btn.disabled = false;}});}function start() {enableUndoButtons();var observer = new MutationObserver(function (mutations) {for (var i = 0; i < mutations.length; i++) {var m = mutations[i];if (m.type === 'attributes' && m.target && m.target.matches && m.target.matches('.model3D button[aria-label="Undo"]')) {if (m.target.disabled) m.target.disabled = false;} else if (m.type === 'childList') {enableUndoButtons(m.target);}}});observer.observe(document.body, {childList: true,subtree: true,attributes: true,attributeFilter: ['disabled']});}if (document.readyState === 'loading') {document.addEventListener('DOMContentLoaded', start);} else {start();}})();</script>"""164 unmodified linesdef build_demo() -> gr.Blocks:with gr.Blocks(title="STL TIFF Slicer") as demo:gr.Markdown("""# STL to TIFF Slicer17 unmodified lineswith gr.Row():for i in range(3):with gr.Column(min_width=250):stl_file = gr.File(label=f"STL File {i + 1}",file_types=[".stl"],117 unmodified linesif __name__ == "__main__":demo.launch(ssr_mode=False, css=APP_CSS, head=APP_HEAD)