Spaces:
Sleeping
Sleeping
Commit ·
e30c292
1
Parent(s): ba48acb
add generation progress bar, seed randomization, dark-theme score colors
Browse files- run_generation: gr.Progress bar (by measures or patch budget), show_progress=minimal
- randomize the seed slider after each generation; output file keeps the seed used
- date-prefixed output filenames (YYYYMMDD_HHMMSS)
- score colors: force dark on the whole svg subtree to beat Gradio's .prose * rule
(covers staff/barLine/ledgerLines/grpSym), fixing pale lines under the dark theme
Files changed (2)
- app.py+33-7
- web/score-player.css+14-8
17 unmodified lines181920212223178 unmodified lines2022032042052062072082092102112122132142 unmodified lines21721821922022122222322422522622722822923023123223323423523623723823924024124224312 unmodified lines256257258259260261262180 unmodified lines44344444544644744844945017 unmodified linesimport reimport timeimport jsonimport loggingfrom collections import deque178 unmodified linesreturn sys_logdef run_generation (prompt, measures, temperature, max_patches, seed, store, top_k=0, top_p=0.9):'''Streaming generate callback. Yields updates for (log, editor, file_list, store).store: {label: lyl_text} dict held in gr.State; the produced document is addedto it under a timestamped label once generation finishes.top_k / top_p have fixed defaults (no UI controls); pass them explicitly to override.'''meas = int(measures) if measures and int(measures) > 0 else Nonestore = dict(store or {})2 unmodified linesraw = pretty = ''n_yields = 0t0 = time.perf_counter()try:gen = get_generator()# drop a marker in the log timeline; _log_panel expands it to the live output,# so subsequent log lines (timing/done) land *after* the generation text.LOG.info(_GEN_MARKER)for raw, pretty, done in gen.generate_stream(prompt_text=prompt or '', max_patches=int(max_patches), temperature=float(temperature),top_k=int(top_k), top_p=float(top_p), measures=meas, seed=int(seed)):if not done:n_yields += 1# The log streams every patch (raw text). The editor, however, must stay# syntactically valid: only sync it at a measure boundary — i.e. when the# accumulated text ends with the measure separator `|` (so it never shows a# half-generated, incomplete measure). `done` forces a final sync.at_boundary = raw.rstrip().endswith('|')editor_update = pretty if (at_boundary or done) else gr.update()yield _log_panel(raw), editor_update, gr.update(), storeexcept Exception as e:LOG.exception('generation failed: %s', e)yield _log_panel(raw), pretty, gr.update(), storereturn# timing: the stream yields once for prefill + once per generated patch, so the12 unmodified lineswith open(out_path, 'w', encoding='utf-8') as f:f.write(pretty)LOG.info('generation done: %d chars -> %s', len(pretty), os.path.basename(out_path))yield _log_panel(raw), pretty, gr.update(choices=list(store.keys()), value=label), storedef load_file (label, store):180 unmodified linesgen_event = gen_btn.click(run_generation,inputs=[prompt, measures, temperature, max_patches, seed, store],outputs=[log, editor, file_list, store],js=_JS_GEN_START,)gen_event.then(None, None, None, js=_JS_GEN_END)17 unmodified lines18192021222324178 unmodified lines2032042052062072082092102112122132142152162172182192202212222 unmodified lines22522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126212 unmodified lines275276277278279280281282283284180 unmodified lines46546646746846947047147247347447547617 unmodified linesimport reimport timeimport jsonimport randomimport loggingfrom collections import deque178 unmodified linesreturn sys_logdef run_generation (prompt, measures, temperature, max_patches, seed, store, top_k=0, top_p=0.9,progress=gr.Progress()):'''Streaming generate callback. Yields updates for (log, editor, file_list, store, seed).store: {label: lyl_text} dict held in gr.State; the produced document is addedto it under a timestamped label once generation finishes.top_k / top_p have fixed defaults (no UI controls); pass them explicitly to override.A gr.Progress bar tracks generation: by completed measures when a measure countis requested, else by generated patches out of max_patches.The output file is named with the seed used for THIS generation; on completionthe seed slider is randomized (final yield) so the next click uses a fresh seed.'''meas = int(measures) if measures and int(measures) > 0 else Nonestore = dict(store or {})2 unmodified linesraw = pretty = ''n_yields = 0mp = int(max_patches)t0 = time.perf_counter()progress(0.0, desc='Starting…')try:gen = get_generator()# drop a marker in the log timeline; _log_panel expands it to the live output,# so subsequent log lines (timing/done) land *after* the generation text.LOG.info(_GEN_MARKER)for raw, pretty, done in gen.generate_stream(prompt_text=prompt or '', max_patches=mp, temperature=float(temperature),top_k=int(top_k), top_p=float(top_p), measures=meas, seed=int(seed)):if not done:n_yields += 1# progress: by measures (count completed `|` separators vs target) when a# measure count was requested, else by patch budget. clamp to [0,1).if meas:frac = raw.count('|') / measdesc = 'measure %d/%d' % (min(raw.count('|'), meas), meas)else:frac = max(0, n_yields - 1) / mpdesc = 'patch %d/%d' % (max(0, n_yields - 1), mp)progress(min(frac, 0.99) if not done else 1.0, desc=desc)# The log streams every patch (raw text). The editor, however, must stay# syntactically valid: only sync it at a measure boundary — i.e. when the# accumulated text ends with the measure separator `|` (so it never shows a# half-generated, incomplete measure). `done` forces a final sync.at_boundary = raw.rstrip().endswith('|')editor_update = pretty if (at_boundary or done) else gr.update()yield _log_panel(raw), editor_update, gr.update(), store, gr.update()except Exception as e:LOG.exception('generation failed: %s', e)yield _log_panel(raw), pretty, gr.update(), store, gr.update()return# timing: the stream yields once for prefill + once per generated patch, so the12 unmodified lineswith open(out_path, 'w', encoding='utf-8') as f:f.write(pretty)LOG.info('generation done: %d chars -> %s', len(pretty), os.path.basename(out_path))# randomize the seed slider for the next run (the file above already used the# seed this generation ran with, so naming is unaffected)next_seed = random.randint(0, 2147483647)yield _log_panel(raw), pretty, gr.update(choices=list(store.keys()), value=label), store, gr.update(value=next_seed)def load_file (label, store):180 unmodified linesgen_event = gen_btn.click(run_generation,inputs=[prompt, measures, temperature, max_patches, seed, store],outputs=[log, editor, file_list, store, seed],js=_JS_GEN_START,# "minimal" = a small runtime/progress indicator only (top-right), NOT a# spinner covering the output area. "full" overlays the Logs/editor# outputs and, since we yield every patch, flickers badly.show_progress='minimal',)gen_event.then(None, None, None, js=_JS_GEN_END)
27 unmodified lines2829303132333435363738391 unmodified line4142434445464748495027 unmodified lines.ls-svg {background: #fff;/* Verovio draws staff lines / notes with stroke|fill="currentColor", whichinherits the CSS `color`. Gradio's dark theme sets a light body color (withenough specificity to beat a plain class rule), so the score would render aspale lines on the white box. Force a dark ink color with !important so itholds regardless of the active Gradio theme. */color: #1a1a1a !important;display: inline-block;min-width: 100%;}1 unmodified linemax-width: 100%;height: auto;}/* Belt-and-suspenders: pin currentColor on the actual drawing elements too. */.ls-svg svg .staff path,.ls-svg svg .barLine path,.ls-svg svg .ledgerLines path {stroke: #1a1a1a;}27 unmodified lines2829303132331 unmodified line3536373839404142434445464748495051525354555627 unmodified lines.ls-svg {background: #fff;display: inline-block;min-width: 100%;}1 unmodified linemax-width: 100%;height: auto;}/* Verovio draws everything with stroke|fill="currentColor", which resolves to thecomputed `color`. We can't rely on inheritance from a container `color`: Gradio's`.prose * { color: var(--body-text-color) }` sets color DIRECTLY on everydescendant (so it wins over an inherited value), which under the dark theme is alight grey — leaving staff lines, bar lines and the per-system left brace/bracket(grpSym) too pale. Force a dark `color` on the whole svg subtree (high enoughspecificity + !important to beat `.prose *`), and pin stroke on the line elementsas belt-and-suspenders. */.ls-svg svg,.ls-svg svg * {color: #1a1a1a !important;}.ls-svg svg .staff path,.ls-svg svg .barLine path,.ls-svg svg .ledgerLines path,.ls-svg svg .grpSym path {stroke: #1a1a1a;}
app.py+33-7
web/score-player.css+14-8