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 lines18192021222324178 unmodified lines2032042052052062062072082092102112122132142152162172182192202212222 unmodified lines22522622722822923023123223323423523622723723823924024124224324424524624724824925025125225325425523725625725824025926026126212 unmodified lines275276277278279280259281282283284180 unmodified lines46546646744646846947047147247347447547617 unmodified linesimport reimport timeimport jsonimport randomimport loggingfrom collections import deque
178 unmodified lines return sys_log
def 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).def 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 added to 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 count is requested, else by generated patches out of max_patches.
The output file is named with the seed used for THIS generation; on completion the seed slider is randomized (final yield) so the next click uses a fresh seed. ''' meas = int(measures) if measures and int(measures) > 0 else None store = dict(store or {})2 unmodified lines
raw = pretty = '' n_yields = 0 mp = 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=int(max_patches), temperature=float(temperature), 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('|') / meas desc = 'measure %d/%d' % (min(raw.count('|'), meas), meas) else: frac = max(0, n_yields - 1) / mp desc = '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 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 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 lines with 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 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 lines gen_event = gen_btn.click( run_generation, inputs=[prompt, measures, temperature, max_patches, seed, store], outputs=[log, editor, file_list, 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 lines2829303132333435363132331 unmodified line35363744383940414243444546474849505147525354555627 unmodified lines
.ls-svg { background: #fff; /* Verovio draws staff lines / notes with stroke|fill="currentColor", which inherits the CSS `color`. Gradio's dark theme sets a light body color (with enough specificity to beat a plain class rule), so the score would render as pale lines on the white box. Force a dark ink color with !important so it holds regardless of the active Gradio theme. */ color: #1a1a1a !important; display: inline-block; min-width: 100%;}1 unmodified line max-width: 100%; height: auto;}/* Belt-and-suspenders: pin currentColor on the actual drawing elements too. *//* Verovio draws everything with stroke|fill="currentColor", which resolves to the computed `color`. We can't rely on inheritance from a container `color`: Gradio's `.prose * { color: var(--body-text-color) }` sets color DIRECTLY on every descendant (so it wins over an inherited value), which under the dark theme is a light 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 enough specificity + !important to beat `.prose *`), and pin stroke on the line elements as 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 .ledgerLines path,.ls-svg svg .grpSym path { stroke: #1a1a1a;}
app.py+33-7
web/score-player.css+14-8