Spaces:
Sleeping
Sleeping
Expose conservative sampling controls
Browse files
app.py
CHANGED
|
@@ -32,6 +32,8 @@ COURSE_DENS = {"easy": 1, "normal": 2, "hard": 4, "oni": 7}
|
|
| 32 |
CHAR = {"don": "1", "ka": "2", "don_big": "3", "ka_big": "4",
|
| 33 |
"roll": "5", "roll_big": "6", "balloon": "7"}
|
| 34 |
SUB = 96
|
|
|
|
|
|
|
| 35 |
|
| 36 |
_MODELS = {}
|
| 37 |
|
|
@@ -262,7 +264,7 @@ def render_audio_plan(mel, title, course, plan=None):
|
|
| 262 |
|
| 263 |
|
| 264 |
def generate(audio, course, level, bpm_override, auto_plan_on, use_beat, use_planner,
|
| 265 |
-
sampling, progress=gr.Progress()):
|
| 266 |
if audio is None:
|
| 267 |
raise gr.Error("Please upload an audio file.")
|
| 268 |
|
|
@@ -311,6 +313,8 @@ def generate(audio, course, level, bpm_override, auto_plan_on, use_beat, use_pla
|
|
| 311 |
bpm = float(np.atleast_1d(librosa.beat.beat_track(y=wav, sr=SR)[0])[0])
|
| 312 |
if grid is None and abs(bpm - round(bpm)) < 0.06:
|
| 313 |
bpm = float(round(bpm))
|
|
|
|
|
|
|
| 314 |
|
| 315 |
plan = None
|
| 316 |
P(0.28, "Planning song structure…")
|
|
@@ -329,7 +333,7 @@ def generate(audio, course, level, bpm_override, auto_plan_on, use_beat, use_pla
|
|
| 329 |
g = generate_song_slot(
|
| 330 |
M["slot"], mel, grid, course, level=int(level),
|
| 331 |
density_bucket=COURSE_DENS[course], greedy=not sampling, seed=0,
|
| 332 |
-
device=DEVICE, plan=plan,
|
| 333 |
on_progress=lambda d, t: P(0.32 + 0.58 * d / max(t, 1),
|
| 334 |
f"Generating notes (slot-exact)… {d}/{t} windows"))
|
| 335 |
tja = write_tja_slots(g, grid, title, course, int(level), wave_name,
|
|
@@ -339,7 +343,7 @@ def generate(audio, course, level, bpm_override, auto_plan_on, use_beat, use_pla
|
|
| 339 |
g = generate_song(
|
| 340 |
M["gen"], mel, course, level=int(level),
|
| 341 |
density_bucket=COURSE_DENS[course], greedy=not sampling,
|
| 342 |
-
seed=0, device=DEVICE, plan=plan,
|
| 343 |
on_progress=lambda d, t: P(0.32 + 0.58 * d / max(t, 1),
|
| 344 |
f"Generating notes… {d}/{t} windows"))
|
| 345 |
g = snap_chart(g, bpm)
|
|
@@ -360,7 +364,8 @@ def generate(audio, course, level, bpm_override, auto_plan_on, use_beat, use_pla
|
|
| 360 |
grid_info = " · grid: unreliable, barline anchoring off"
|
| 361 |
else:
|
| 362 |
grid_info = ""
|
| 363 |
-
|
|
|
|
| 364 |
+ (f" · plan: {sum(1 for b in plan if b[3]==1)} gaps, {sum(1 for b in plan if b[3]==2)} climax" if plan else ""))
|
| 365 |
return tja_path, info, tja_img, audio_plan_img
|
| 366 |
|
|
@@ -385,13 +390,22 @@ with gr.Blocks(title="SoftChart — AI Taiko chart generator") as demo:
|
|
| 385 |
with gr.Row():
|
| 386 |
use_beat = gr.Checkbox(label="Beat-anchor barlines", value=True)
|
| 387 |
sampling = gr.Checkbox(label="Sampling (diverse) vs greedy (best)", value=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 388 |
btn = gr.Button("Generate chart", variant="primary")
|
| 389 |
with gr.Column():
|
| 390 |
out_tja = gr.File(label="Download .tja")
|
| 391 |
out_info = gr.Textbox(label="Result", interactive=False)
|
| 392 |
out_chart = gr.Image(label="TJA chart")
|
| 393 |
out_img = gr.Image(label="Full-song mel + plan")
|
| 394 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
[out_tja, out_info, out_chart, out_img])
|
| 396 |
|
| 397 |
if __name__ == "__main__":
|
|
|
|
| 32 |
CHAR = {"don": "1", "ka": "2", "don_big": "3", "ka_big": "4",
|
| 33 |
"roll": "5", "roll_big": "6", "balloon": "7"}
|
| 34 |
SUB = 96
|
| 35 |
+
DEFAULT_TEMPERATURE = 0.8
|
| 36 |
+
DEFAULT_TOP_P = 0.9
|
| 37 |
|
| 38 |
_MODELS = {}
|
| 39 |
|
|
|
|
| 264 |
|
| 265 |
|
| 266 |
def generate(audio, course, level, bpm_override, auto_plan_on, use_beat, use_planner,
|
| 267 |
+
sampling, temperature, top_p, progress=gr.Progress()):
|
| 268 |
if audio is None:
|
| 269 |
raise gr.Error("Please upload an audio file.")
|
| 270 |
|
|
|
|
| 313 |
bpm = float(np.atleast_1d(librosa.beat.beat_track(y=wav, sr=SR)[0])[0])
|
| 314 |
if grid is None and abs(bpm - round(bpm)) < 0.06:
|
| 315 |
bpm = float(round(bpm))
|
| 316 |
+
temperature = float(np.clip(temperature or DEFAULT_TEMPERATURE, 0.2, 1.2))
|
| 317 |
+
top_p = float(np.clip(top_p or DEFAULT_TOP_P, 0.5, 1.0))
|
| 318 |
|
| 319 |
plan = None
|
| 320 |
P(0.28, "Planning song structure…")
|
|
|
|
| 333 |
g = generate_song_slot(
|
| 334 |
M["slot"], mel, grid, course, level=int(level),
|
| 335 |
density_bucket=COURSE_DENS[course], greedy=not sampling, seed=0,
|
| 336 |
+
temperature=temperature, top_p=top_p, device=DEVICE, plan=plan,
|
| 337 |
on_progress=lambda d, t: P(0.32 + 0.58 * d / max(t, 1),
|
| 338 |
f"Generating notes (slot-exact)… {d}/{t} windows"))
|
| 339 |
tja = write_tja_slots(g, grid, title, course, int(level), wave_name,
|
|
|
|
| 343 |
g = generate_song(
|
| 344 |
M["gen"], mel, course, level=int(level),
|
| 345 |
density_bucket=COURSE_DENS[course], greedy=not sampling,
|
| 346 |
+
temperature=temperature, top_p=top_p, seed=0, device=DEVICE, plan=plan,
|
| 347 |
on_progress=lambda d, t: P(0.32 + 0.58 * d / max(t, 1),
|
| 348 |
f"Generating notes… {d}/{t} windows"))
|
| 349 |
g = snap_chart(g, bpm)
|
|
|
|
| 364 |
grid_info = " · grid: unreliable, barline anchoring off"
|
| 365 |
else:
|
| 366 |
grid_info = ""
|
| 367 |
+
sampling_info = f" · sampling T {temperature:.2f}, top-p {top_p:.2f}" if sampling else ""
|
| 368 |
+
info = (f"BPM {bpm:.1f} · {len(g['hits'])} notes · {len(g['spans'])} spans" + grid_info + sampling_info
|
| 369 |
+ (f" · plan: {sum(1 for b in plan if b[3]==1)} gaps, {sum(1 for b in plan if b[3]==2)} climax" if plan else ""))
|
| 370 |
return tja_path, info, tja_img, audio_plan_img
|
| 371 |
|
|
|
|
| 390 |
with gr.Row():
|
| 391 |
use_beat = gr.Checkbox(label="Beat-anchor barlines", value=True)
|
| 392 |
sampling = gr.Checkbox(label="Sampling (diverse) vs greedy (best)", value=False)
|
| 393 |
+
with gr.Row():
|
| 394 |
+
temperature = gr.Slider(0.2, 1.2, value=DEFAULT_TEMPERATURE, step=0.05,
|
| 395 |
+
label="Temperature", interactive=False)
|
| 396 |
+
top_p = gr.Slider(0.5, 1.0, value=DEFAULT_TOP_P, step=0.01,
|
| 397 |
+
label="Top-p", interactive=False)
|
| 398 |
btn = gr.Button("Generate chart", variant="primary")
|
| 399 |
with gr.Column():
|
| 400 |
out_tja = gr.File(label="Download .tja")
|
| 401 |
out_info = gr.Textbox(label="Result", interactive=False)
|
| 402 |
out_chart = gr.Image(label="TJA chart")
|
| 403 |
out_img = gr.Image(label="Full-song mel + plan")
|
| 404 |
+
sampling.change(
|
| 405 |
+
lambda enabled: (gr.update(interactive=enabled), gr.update(interactive=enabled)),
|
| 406 |
+
sampling, [temperature, top_p])
|
| 407 |
+
btn.click(generate, [audio, course, level, bpm, auto_plan_on, use_beat, use_planner,
|
| 408 |
+
sampling, temperature, top_p],
|
| 409 |
[out_tja, out_info, out_chart, out_img])
|
| 410 |
|
| 411 |
if __name__ == "__main__":
|