Spaces:
Sleeping
Sleeping
Commit ·
ba48acb
1
Parent(s): 764d3da
fixed DOM incompleted bug
Browse files248 unmodified lines24925025125225225325425566 unmodified lines322323324325326325326327328329330328329330331332333334335336337331332333334335336111 unmodified lines448449450455456451452453454455456457248 unmodified lines elapsed, n_patches, per_patch, (n_patches / elapsed if elapsed else 0.0))
# finished: persist the document, refresh the file list, select the new entry label = OUTPUT_PREFIX + time.strftime('%H%M%S') + ('_m%d' % meas if meas else '') + '_s%d' % int(seed) label = OUTPUT_PREFIX + time.strftime('%Y%m%d_%H%M%S') + ('_m%d' % meas if meas else '') + '_s%d' % int(seed) store[label] = pretty os.makedirs(OUTPUT_DIR, exist_ok=True) out_path = os.path.join(OUTPUT_DIR, label.replace(OUTPUT_PREFIX, '') + '.lyl')66 unmodified lines}'''
# Read the live editor text and render it to SVG. gr.Code renders a CodeMirror# editor; its current text lives in the `.cm-content` element (textContent).# Render the editor text to SVG. The text is passed in by Gradio as the event's# input value — we must NOT scrape it from the DOM: gr.Code is a CodeMirror editor# that virtualises long documents (only the rows near the viewport exist in the# DOM), so `.cm-content`.innerText is truncated for long scores and the render# comes out incomplete. Taking the value as an argument gives the full text._JS_RENDER = '''function () { if (!window.LilyScore) return; const root = document.querySelector('#ls-editor'); let text = ''; if (root) { const cm = root.querySelector('.cm-content'); if (cm) text = cm.innerText; else { const ta = root.querySelector('textarea'); if (ta) text = ta.value; } } window.LilyScore.render(text);function (text) { if (window.LilyScore) window.LilyScore.render(text || ''); return [];}'''
111 unmodified lines ) gen_event.then(None, None, None, js=_JS_GEN_END)
# every editor change (streaming syncs + manual edits + file loads) -> re-render SVG editor.change(None, None, None, js=_JS_RENDER) # every editor change (streaming syncs + manual edits + file loads) -> re-render # SVG. Pass the editor value as input so the js receives the FULL text (gr.Code # virtualises long docs in the DOM, so scraping it client-side truncates). editor.change(None, inputs=[editor], outputs=None, js=_JS_RENDER)
# Stop: cancel generation, then lift the gate so the player returns stop_btn.click(None, None, None, cancels=[gen_event]).then(None, None, None, js=_JS_GEN_END)app.py+13-15