Spaces:
Running
Running
Commit ·
30ed586
1
Parent(s): 1962366
lilylet: emit %-style prompt lines (period/composer/instrument) instead of [composer ...] fields; postprocess treats % as meta
Browse files- app.py +12 -7
- lilyscript/postprocess.py +3 -1
app.py
CHANGED
|
@@ -170,22 +170,27 @@ def load_library ():
|
|
| 170 |
return {**load_examples(), **load_outputs()}
|
| 171 |
|
| 172 |
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
|
| 176 |
def sync_prompt (composer, genre, instrument, current):
|
| 177 |
'''Rewrite the metadata-prompt text from the three style dropdowns.
|
| 178 |
|
| 179 |
-
The
|
| 180 |
-
|
| 181 |
-
|
|
|
|
|
|
|
| 182 |
'''
|
| 183 |
lines = []
|
| 184 |
-
for
|
| 185 |
value = (value or '').strip()
|
| 186 |
if value:
|
| 187 |
-
lines.append(f'
|
| 188 |
-
# keep every line that isn't one of the
|
| 189 |
for ln in (current or '').splitlines():
|
| 190 |
if not _STYLE_LINE_RE.match(ln.strip()):
|
| 191 |
if ln.strip():
|
|
|
|
| 170 |
return {**load_examples(), **load_outputs()}
|
| 171 |
|
| 172 |
|
| 173 |
+
# A managed style line in the new `--styles-in-comments` format: a leading `%<value>`
|
| 174 |
+
# comment carrying period / composer / instrumentation (one per line). `sync_prompt`
|
| 175 |
+
# regenerates these from the dropdowns; any other line the user typed is preserved.
|
| 176 |
+
_STYLE_LINE_RE = re.compile(r'^%(?!%).*$')
|
| 177 |
|
| 178 |
|
| 179 |
def sync_prompt (composer, genre, instrument, current):
|
| 180 |
'''Rewrite the metadata-prompt text from the three style dropdowns.
|
| 181 |
|
| 182 |
+
The model is trained on the `--styles-in-comments` format: style is carried by
|
| 183 |
+
leading `%<value>` comment lines, ordered period/composer/instrumentation (matching
|
| 184 |
+
abc2lilylet's catalogCommentLines: %<genre> / %<composer> / %<instrument>). These
|
| 185 |
+
are regenerated from the dropdowns and placed at the top; any other line the user
|
| 186 |
+
typed (e.g. a `[staves "..."]` header) is preserved below in its original order.
|
| 187 |
'''
|
| 188 |
lines = []
|
| 189 |
+
for value in (genre, composer, instrument):
|
| 190 |
value = (value or '').strip()
|
| 191 |
if value:
|
| 192 |
+
lines.append(f'%{value}')
|
| 193 |
+
# keep every line that isn't one of the managed `%<style>` lines
|
| 194 |
for ln in (current or '').splitlines():
|
| 195 |
if not _STYLE_LINE_RE.match(ln.strip()):
|
| 196 |
if ln.strip():
|
lilyscript/postprocess.py
CHANGED
|
@@ -39,7 +39,9 @@ def postprocess (text: str) -> str:
|
|
| 39 |
pending = m.group(1)
|
| 40 |
ln = _STREAM_RE.sub('', ln).rstrip()
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
# blank line once the metadata block ends and the body begins
|
| 44 |
if not meta_done and out and not is_meta and ln:
|
| 45 |
out.append('')
|
|
|
|
| 39 |
pending = m.group(1)
|
| 40 |
ln = _STREAM_RE.sub('', ln).rstrip()
|
| 41 |
|
| 42 |
+
# metadata lines: `[field "..."]` headers and leading `%<style>` comments
|
| 43 |
+
# (the --styles-in-comments format). Both belong to the meta block.
|
| 44 |
+
is_meta = (ln.startswith('[') and ln.endswith(']')) or (ln.startswith('%') and not ln.startswith('%%'))
|
| 45 |
# blank line once the metadata block ends and the body begins
|
| 46 |
if not meta_done and out and not is_meta and ln:
|
| 47 |
out.append('')
|