JayLL13 commited on
Commit
f6054eb
·
verified ·
1 Parent(s): b8d9590

feat: redesign Tune Studio as an Idea, Lyrics and Music column flow

Browse files
Files changed (2) hide show
  1. README.md +3 -2
  2. app.py +162 -99
README.md CHANGED
@@ -21,9 +21,10 @@ Type a topic and pick a style. The app writes English lyrics with DeepSeek V4.1
21
  ## Using the app
22
 
23
  1. Open **Settings** and paste a Hugging Face token with the *Make calls to Inference Providers* permission. The token is stored only in your browser.
24
- 2. Type your topic, pick a style, and click **Create song**.
25
  3. Optional: open **Advanced** to choose symbolic planning (melody + chords, melody only, or no score), render quality (16 or 32 steps), and the seed.
26
- 4. Like the melody but not the words? Click **New lyrics, same melody**. The app writes new lyrics with the same sections and sings them on the same score, style, and seed. This needs a song made with a score, so it is not offered for "No score" songs.
 
27
 
28
  ## Run locally
29
 
 
21
  ## Using the app
22
 
23
  1. Open **Settings** and paste a Hugging Face token with the *Make calls to Inference Providers* permission. The token is stored only in your browser.
24
+ 2. In **1 · Idea**, type your topic, pick a style, and click **Create song**. After the first song this button reads **New song** and always makes new lyrics and new music.
25
  3. Optional: open **Advanced** to choose symbolic planning (melody + chords, melody only, or no score), render quality (16 or 32 steps), and the seed.
26
+ 4. In **2 · Lyrics**, **Rewrite lyrics · keep melody** writes new words with the same sections and sings them on the same score, style, and seed. It needs a song made with a score, so it is off for "No score" songs.
27
+ 5. In **3 · Music**, **New music · keep lyrics** composes a new score for the same lyrics, using the current style and Advanced settings from column 1.
28
 
29
  ## Run locally
30
 
app.py CHANGED
@@ -21,40 +21,48 @@ STYLE_PRESETS = {
21
  PLANNING_CHOICES = [("Melody + chords", "full"), ("Melody only", "melody"), ("No score", "off")]
22
  QUALITY_CHOICES = [("Fast · 16 steps", 16), ("Best quality · 32 steps", 32)]
23
  MAX_SEED = 2**31 - 1
 
24
 
25
  CSS = """
26
- #page { max-width: 760px; margin: 0 auto; }
27
- .hero { text-align: center; padding-top: 16px; }
28
- .hero h1 { font-size: 2rem; margin-bottom: 4px; }
29
  .hero p { opacity: 0.75; margin-top: 0; }
30
- #create-btn { font-size: 1.05rem; }
 
 
 
31
  """
32
 
33
  HERO_HTML = """
34
  <div class="hero">
35
- <h1>Turn a topic into a song</h1>
36
- <p>Describe what your song is about. We write English lyrics and sing them for you.</p>
37
  </div>
38
  """
39
 
40
  writer = HfLyricsWriter()
41
-
42
-
43
  KEEP = object()
44
 
45
 
46
- def outputs(status, lyrics=KEEP, audio=KEEP, seed=KEEP, remix=KEEP, song=KEEP):
47
- """One value per result component; KEEP leaves that component unchanged."""
48
- def value(item, convert=lambda x: x):
49
- return gr.skip() if item is KEEP else convert(item)
50
 
 
 
 
 
 
51
  return (
52
  status,
53
- value(lyrics),
54
- value(audio),
55
- value(seed),
56
- value(remix, lambda visible: gr.update(visible=visible)),
57
- value(song),
 
 
 
58
  )
59
 
60
 
@@ -64,6 +72,10 @@ def pick_seed(seed, randomize: bool) -> int:
64
  return int(seed)
65
 
66
 
 
 
 
 
67
  def verify_token(token: str):
68
  token = (token or "").strip()
69
  if not token:
@@ -79,8 +91,12 @@ def remove_token():
79
  return "", "", "Token removed from this browser."
80
 
81
 
82
- def render(song: dict):
83
- """Render `song` on the GPU and yield either the finished result or an error status."""
 
 
 
 
84
  try:
85
  audio_path, abc = render_song(
86
  song["style"], song["lyrics"], song["seed"], song["cot"], song["steps"], song.get("abc")
@@ -88,20 +104,15 @@ def render(song: dict):
88
  except Exception as exc:
89
  logger.exception("Song rendering failed")
90
  message = exc.message if isinstance(exc, gr.Error) else "Something went wrong while making the song."
91
- yield outputs(f"Could not make the song: {message}")
92
  return
93
  song = {**song, "abc": abc}
94
- yield outputs(
95
- "Done. Press play or download below.",
96
- lyrics=song["lyrics"],
97
- audio=audio_path,
98
- seed=song["seed"],
99
- remix=abc is not None,
100
- song=song,
101
- )
102
 
103
 
104
- def create_song(topic, style_label, custom_style, cot, steps, seed, randomize, token):
 
105
  topic = (topic or "").strip()
106
  token = (token or "").strip()
107
  if len(topic) < 3:
@@ -109,49 +120,69 @@ def create_song(topic, style_label, custom_style, cot, steps, seed, randomize, t
109
  if not token:
110
  raise gr.Error("Add your Hugging Face token in Settings first.")
111
 
112
- yield outputs("Writing lyrics…", lyrics="", audio=None, remix=False)
113
  try:
114
  lyrics = writer.write(topic, token)
115
  except LyricsError as exc:
116
- yield outputs(f"Could not write lyrics: {exc}")
117
  return
118
 
119
  song = {
120
  "topic": topic,
121
- "style": (custom_style or "").strip() or STYLE_PRESETS[style_label],
122
  "lyrics": lyrics,
123
  "seed": pick_seed(seed, randomize),
124
  "cot": cot,
125
  "steps": int(steps),
126
  "abc": None,
127
  }
128
- yield outputs("Singing and producing. This usually takes a few minutes…", lyrics=lyrics, seed=song["seed"])
129
- yield from render(song)
 
130
 
131
 
132
- def rewrite_lyrics(direction, last_song, token):
 
133
  token = (token or "").strip()
134
- if not last_song or not last_song.get("abc"):
135
- raise gr.Error("Create a song with a score first, then rewrite its lyrics.")
136
  if not token:
137
  raise gr.Error("Add your Hugging Face token in Settings first.")
138
 
139
- yield outputs("Writing new lyrics for the same melody…", remix=False)
140
  try:
141
- lyrics = writer.rewrite(last_song["topic"], last_song["lyrics"], direction or "", token)
142
  except LyricsError as exc:
143
- yield outputs(f"Could not write new lyrics: {exc}", remix=True)
144
  return
145
 
146
- # Same score, style and seed, so only the words change.
147
- song = {**last_song, "lyrics": lyrics}
148
- yield outputs("Singing the new lyrics on the same melody. This usually takes a few minutes…", lyrics=lyrics)
149
- yield from render(song)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
150
 
151
 
152
  with gr.Blocks(title="Tune Studio", theme=gr.themes.Soft(primary_hue="violet"), css=CSS) as demo:
153
  token_state = gr.BrowserState("")
154
- last_song = gr.State(None)
155
 
156
  with gr.Column(elem_id="page"):
157
  gr.HTML(HERO_HTML)
@@ -168,68 +199,100 @@ with gr.Blocks(title="Tune Studio", theme=gr.themes.Soft(primary_hue="violet"),
168
  remove_button = gr.Button("Remove token", variant="stop")
169
  settings_status = gr.Markdown()
170
 
171
- topic_input = gr.Textbox(
172
- label="Topic",
173
- placeholder="e.g. a rainy night in the city, missing someone who left",
174
- lines=3,
175
- max_lines=5,
176
- )
177
- style_input = gr.Radio(choices=list(STYLE_PRESETS), value="Pop", label="Style")
178
- with gr.Accordion("Describe your own style (optional)", open=False):
179
- custom_style_input = gr.Textbox(
180
- placeholder="e.g. jazz piano, smooth male vocal",
181
- show_label=False,
182
- )
183
- with gr.Accordion("Advanced", open=False):
184
- planning_input = gr.Radio(
185
- choices=PLANNING_CHOICES,
186
- value="full",
187
- label="Symbolic planning",
188
- info="The model first writes a score, then sings it. 'No score' skips the score, "
189
- "so 'New lyrics, same melody' is not available for that song.",
190
- )
191
- quality_input = gr.Radio(choices=QUALITY_CHOICES, value=16, label="Render quality")
192
- with gr.Row():
193
- seed_input = gr.Number(value=42, precision=0, minimum=0, maximum=MAX_SEED, label="Seed")
194
- randomize_input = gr.Checkbox(value=True, label="New random seed each time")
195
-
196
- create_button = gr.Button("Create song", variant="primary", elem_id="create-btn")
197
- status = gr.Markdown()
198
- audio_output = gr.Audio(
199
- label="Your song",
200
- type="filepath",
201
- interactive=False,
202
- show_download_button=True,
203
- )
204
- lyrics_output = gr.Textbox(
205
- label="Lyrics",
206
- lines=12,
207
- max_lines=24,
208
- interactive=False,
209
- show_copy_button=True,
210
- )
211
- with gr.Group(visible=False) as remix_group:
212
- gr.Markdown("**Like the melody but not the words?** Get new lyrics sung on the same melody.")
213
- direction_input = gr.Textbox(
214
- placeholder="Optional: what to change, e.g. more hopeful, mention the ocean",
215
- show_label=False,
216
- )
217
- remix_button = gr.Button("New lyrics, same melody", variant="secondary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
  gr.Markdown(
219
  "Lyrics: DeepSeek V4.1 Flash via Hugging Face Inference Providers, billed to your account. "
220
- "Music: YuE2-3B. Model weights are CC BY-NC 4.0."
 
221
  )
222
 
223
- results = [status, lyrics_output, audio_output, seed_input, remix_group, last_song]
 
 
 
 
 
224
  demo.load(lambda saved: saved, token_state, token_input)
225
  verify_button.click(verify_token, token_input, [settings_status, token_state])
226
  remove_button.click(remove_token, None, [token_input, token_state, settings_status])
227
  create_button.click(
228
- create_song,
229
- [topic_input, style_input, custom_style_input, planning_input, quality_input,
230
- seed_input, randomize_input, token_input],
231
- results,
232
  )
233
- remix_button.click(rewrite_lyrics, [direction_input, last_song, token_input], results)
 
234
 
235
  demo.queue(default_concurrency_limit=1).launch()
 
21
  PLANNING_CHOICES = [("Melody + chords", "full"), ("Melody only", "melody"), ("No score", "off")]
22
  QUALITY_CHOICES = [("Fast · 16 steps", 16), ("Best quality · 32 steps", 32)]
23
  MAX_SEED = 2**31 - 1
24
+ RENDER_WAIT = "This usually takes a few minutes."
25
 
26
  CSS = """
27
+ #page { max-width: 1400px; margin: 0 auto; }
28
+ .hero { text-align: center; padding-top: 8px; }
29
+ .hero h1 { font-size: 1.9rem; margin-bottom: 2px; }
30
  .hero p { opacity: 0.75; margin-top: 0; }
31
+ #status { min-height: 1.6em; text-align: center; font-weight: 600; }
32
+ .step-title h3 { margin: 0; }
33
+ .hint { opacity: 0.7; font-size: 0.88rem; }
34
+ #score textarea { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }
35
  """
36
 
37
  HERO_HTML = """
38
  <div class="hero">
39
+ <h1>Tune Studio</h1>
40
+ <p>Type a topic. We write English lyrics, compose a score, and sing it.</p>
41
  </div>
42
  """
43
 
44
  writer = HfLyricsWriter()
 
 
45
  KEEP = object()
46
 
47
 
48
+ def keep_or(item):
49
+ return gr.skip() if item is KEEP else item
 
 
50
 
51
+
52
+ def results(status, song, *, busy=False, lyrics=KEEP, audio=KEEP, score=KEEP, seed=KEEP):
53
+ """Values for every result component. Button states follow `song` and whether a job runs."""
54
+ has_song = bool(song)
55
+ can_rewrite = has_song and bool(song.get("abc"))
56
  return (
57
  status,
58
+ keep_or(lyrics),
59
+ keep_or(audio),
60
+ keep_or(score),
61
+ keep_or(seed),
62
+ gr.update(interactive=not busy, value="New song" if has_song else "Create song"),
63
+ gr.update(interactive=not busy and can_rewrite),
64
+ gr.update(interactive=not busy and has_song),
65
+ song,
66
  )
67
 
68
 
 
72
  return int(seed)
73
 
74
 
75
+ def chosen_style(style_label: str, custom_style: str) -> str:
76
+ return (custom_style or "").strip() or STYLE_PRESETS[style_label]
77
+
78
+
79
  def verify_token(token: str):
80
  token = (token or "").strip()
81
  if not token:
 
91
  return "", "", "Token removed from this browser."
92
 
93
 
94
+ def render(song: dict, success: str):
95
+ """Sing `song` on the GPU and yield the finished result or an error.
96
+
97
+ On failure the new lyrics are kept, so "New music · keep lyrics" can retry without
98
+ writing them again.
99
+ """
100
  try:
101
  audio_path, abc = render_song(
102
  song["style"], song["lyrics"], song["seed"], song["cot"], song["steps"], song.get("abc")
 
104
  except Exception as exc:
105
  logger.exception("Song rendering failed")
106
  message = exc.message if isinstance(exc, gr.Error) else "Something went wrong while making the song."
107
+ yield results(f"Could not make the song: {message}", song, audio=None, score="")
108
  return
109
  song = {**song, "abc": abc}
110
+ score = abc or "No score for this song: it was made with 'No score' planning."
111
+ yield results(success, song, audio=audio_path, score=score, seed=song["seed"])
 
 
 
 
 
 
112
 
113
 
114
+ def new_song(topic, style_label, custom_style, cot, steps, seed, randomize, token, current):
115
+ """New lyrics, new score and new audio from the topic."""
116
  topic = (topic or "").strip()
117
  token = (token or "").strip()
118
  if len(topic) < 3:
 
120
  if not token:
121
  raise gr.Error("Add your Hugging Face token in Settings first.")
122
 
123
+ yield results("Step 1 of 2 · Writing lyrics…", current, busy=True)
124
  try:
125
  lyrics = writer.write(topic, token)
126
  except LyricsError as exc:
127
+ yield results(f"Could not write lyrics: {exc}", current)
128
  return
129
 
130
  song = {
131
  "topic": topic,
132
+ "style": chosen_style(style_label, custom_style),
133
  "lyrics": lyrics,
134
  "seed": pick_seed(seed, randomize),
135
  "cot": cot,
136
  "steps": int(steps),
137
  "abc": None,
138
  }
139
+ yield results(f"Step 2 of 2 · Composing and singing. {RENDER_WAIT}", current, busy=True,
140
+ lyrics=lyrics, audio=None, score="", seed=song["seed"])
141
+ yield from render(song, "Your song is ready.")
142
 
143
 
144
+ def rewrite_lyrics(direction, token, current):
145
+ """New lyrics sung on the current song's score, style and seed."""
146
  token = (token or "").strip()
147
+ if not current or not current.get("abc"):
148
+ raise gr.Error("Make a song with a score first, then rewrite its lyrics.")
149
  if not token:
150
  raise gr.Error("Add your Hugging Face token in Settings first.")
151
 
152
+ yield results("Step 1 of 2 · Writing new lyrics for the same melody…", current, busy=True)
153
  try:
154
+ lyrics = writer.rewrite(current["topic"], current["lyrics"], direction or "", token)
155
  except LyricsError as exc:
156
+ yield results(f"Could not write new lyrics: {exc}", current)
157
  return
158
 
159
+ song = {**current, "lyrics": lyrics}
160
+ yield results(f"Step 2 of 2 · Singing the new lyrics on the same melody. {RENDER_WAIT}", current,
161
+ busy=True, lyrics=lyrics, audio=None)
162
+ yield from render(song, "New lyrics are ready on the same melody.")
163
+
164
+
165
+ def new_music(style_label, custom_style, cot, steps, seed, randomize, current):
166
+ """A new score and audio for the current lyrics, using the settings in the Idea column."""
167
+ if not current:
168
+ raise gr.Error("Make a song first, then make new music for its lyrics.")
169
+
170
+ song = {
171
+ **current,
172
+ "style": chosen_style(style_label, custom_style),
173
+ "seed": pick_seed(seed, randomize),
174
+ "cot": cot,
175
+ "steps": int(steps),
176
+ "abc": None,
177
+ }
178
+ yield results(f"Composing new music for the same lyrics. {RENDER_WAIT}", current, busy=True,
179
+ audio=None, score="", seed=song["seed"])
180
+ yield from render(song, "New music is ready for the same lyrics.")
181
 
182
 
183
  with gr.Blocks(title="Tune Studio", theme=gr.themes.Soft(primary_hue="violet"), css=CSS) as demo:
184
  token_state = gr.BrowserState("")
185
+ current_song = gr.State(None)
186
 
187
  with gr.Column(elem_id="page"):
188
  gr.HTML(HERO_HTML)
 
199
  remove_button = gr.Button("Remove token", variant="stop")
200
  settings_status = gr.Markdown()
201
 
202
+ status = gr.Markdown(elem_id="status")
203
+
204
+ with gr.Row(equal_height=False):
205
+ with gr.Column(variant="panel", min_width=320):
206
+ gr.Markdown("### 1 · Idea", elem_classes="step-title")
207
+ topic_input = gr.Textbox(
208
+ label="Topic",
209
+ placeholder="e.g. a rainy night in the city, missing someone who left",
210
+ lines=3,
211
+ max_lines=5,
212
+ )
213
+ style_input = gr.Radio(choices=list(STYLE_PRESETS), value="Pop", label="Style")
214
+ with gr.Accordion("Describe your own style (optional)", open=False):
215
+ custom_style_input = gr.Textbox(
216
+ placeholder="e.g. jazz piano, smooth male vocal",
217
+ show_label=False,
218
+ )
219
+ with gr.Accordion("Advanced", open=False):
220
+ planning_input = gr.Radio(
221
+ choices=PLANNING_CHOICES,
222
+ value="full",
223
+ label="Symbolic planning",
224
+ info="The model writes a score, then sings it. 'No score' skips the score, "
225
+ "so that song's lyrics cannot be rewritten on the same melody.",
226
+ )
227
+ quality_input = gr.Radio(choices=QUALITY_CHOICES, value=16, label="Render quality")
228
+ with gr.Row():
229
+ seed_input = gr.Number(value=42, precision=0, minimum=0, maximum=MAX_SEED, label="Seed")
230
+ randomize_input = gr.Checkbox(value=True, label="New random seed each time")
231
+ create_button = gr.Button("Create song", variant="primary", size="lg")
232
+ gr.Markdown("Writes new lyrics and new music from your topic.", elem_classes="hint")
233
+
234
+ with gr.Column(variant="panel", min_width=320):
235
+ gr.Markdown("### 2 · Lyrics", elem_classes="step-title")
236
+ lyrics_output = gr.Textbox(
237
+ label="Lyrics",
238
+ lines=16,
239
+ max_lines=30,
240
+ interactive=False,
241
+ show_copy_button=True,
242
+ )
243
+ direction_input = gr.Textbox(
244
+ label="What should change? (optional)",
245
+ placeholder="e.g. more hopeful, mention the ocean",
246
+ )
247
+ rewrite_button = gr.Button("Rewrite lyrics · keep melody", interactive=False)
248
+ gr.Markdown(
249
+ "Writes new words with the same sections and sings them on the same score, style and seed.",
250
+ elem_classes="hint",
251
+ )
252
+
253
+ with gr.Column(variant="panel", min_width=320):
254
+ gr.Markdown("### 3 · Music", elem_classes="step-title")
255
+ audio_output = gr.Audio(
256
+ label="Your song",
257
+ type="filepath",
258
+ interactive=False,
259
+ show_download_button=True,
260
+ )
261
+ score_output = gr.Textbox(
262
+ label="Score (ABC notation)",
263
+ lines=10,
264
+ max_lines=20,
265
+ interactive=False,
266
+ show_copy_button=True,
267
+ elem_id="score",
268
+ )
269
+ music_button = gr.Button("New music · keep lyrics", interactive=False)
270
+ gr.Markdown(
271
+ "Composes a new score for the same lyrics, using the style and Advanced settings in column 1.",
272
+ elem_classes="hint",
273
+ )
274
+
275
  gr.Markdown(
276
  "Lyrics: DeepSeek V4.1 Flash via Hugging Face Inference Providers, billed to your account. "
277
+ "Music: YuE2-3B on ZeroGPU. Model weights are CC BY-NC 4.0.",
278
+ elem_classes="hint",
279
  )
280
 
281
+ result_components = [
282
+ status, lyrics_output, audio_output, score_output, seed_input,
283
+ create_button, rewrite_button, music_button, current_song,
284
+ ]
285
+ settings_inputs = [style_input, custom_style_input, planning_input, quality_input, seed_input, randomize_input]
286
+
287
  demo.load(lambda saved: saved, token_state, token_input)
288
  verify_button.click(verify_token, token_input, [settings_status, token_state])
289
  remove_button.click(remove_token, None, [token_input, token_state, settings_status])
290
  create_button.click(
291
+ new_song,
292
+ [topic_input, *settings_inputs, token_input, current_song],
293
+ result_components,
 
294
  )
295
+ rewrite_button.click(rewrite_lyrics, [direction_input, token_input, current_song], result_components)
296
+ music_button.click(new_music, [*settings_inputs, current_song], result_components)
297
 
298
  demo.queue(default_concurrency_limit=1).launch()