rikhoffbauer2 commited on
Commit
1bdf6ad
·
verified ·
1 Parent(s): 1243e53

v5: target cluster range + caching + average linkage — app_v2.py

Browse files
Files changed (1) hide show
  1. app_v2.py +18 -7
app_v2.py CHANGED
@@ -15,7 +15,7 @@ from sample_extractor import (
15
  extract_stem, detect_onsets, classify_hits,
16
  cluster_hits, select_best, synthesize_from_cluster,
17
  sample_quality_score, export_midi, detect_bpm,
18
- render_midi_with_samples, build_archive,
19
  DEMUCS_MODELS, DEMUCS_STEMS,
20
  )
21
  from synth_generator import generate_test_song
@@ -35,7 +35,7 @@ def audio_tuple(a, sr):
35
 
36
  def run_extraction(audio_in, stem_choice, demucs_model, demucs_shifts, demucs_overlap,
37
  onset_mode, onset_delta, energy_db, pre_pad, min_dur, max_dur, min_gap,
38
- ncc_threshold, ncc_compare_ms,
39
  do_synthesize, progress=gr.Progress()):
40
  if audio_in is None:
41
  return [None] * 8
@@ -74,9 +74,11 @@ def run_extraction(audio_in, stem_choice, demucs_model, demucs_shifts, demucs_ov
74
  progress(0.35, desc="Classifying...")
75
  hits = classify_hits(hits)
76
 
77
- progress(0.45, desc=f"NCC clustering (threshold={ncc_threshold})...")
78
  clusters = cluster_hits(hits, ncc_threshold=float(ncc_threshold),
79
- max_compare_ms=float(ncc_compare_ms))
 
 
80
 
81
  progress(0.65, desc="Scoring & selecting best...")
82
  select_best(clusters)
@@ -261,10 +263,19 @@ def build_app():
261
 
262
  with gr.Accordion("🔗 Clustering", open=False):
263
  with gr.Row():
264
- ncc_thresh = gr.Slider(0.5, 0.99, value=0.80, step=0.01,
265
- label='NCC threshold (higher = stricter matching)')
266
  ncc_ms = gr.Slider(50, 1000, value=200, step=50,
267
  label='Compare window (ms)')
 
 
 
 
 
 
 
 
 
268
 
269
  with gr.Accordion("⚙️ Post-processing", open=False):
270
  do_synth = gr.Checkbox(value=True, label='Synthesize optimal samples from clusters')
@@ -294,7 +305,7 @@ def build_app():
294
  run_extraction,
295
  [audio_in, stem_dd, demucs_model, demucs_shifts, demucs_overlap,
296
  onset_mode, onset_delta, energy_db, pre_pad, min_dur, max_dur, min_gap,
297
- ncc_thresh, ncc_ms, do_synth],
298
  [stem_out, summary_md, rendered_out, sample_files,
299
  midi_file, archive_file, status_txt, metrics_tbl])
300
 
 
15
  extract_stem, detect_onsets, classify_hits,
16
  cluster_hits, select_best, synthesize_from_cluster,
17
  sample_quality_score, export_midi, detect_bpm,
18
+ render_midi_with_samples, build_archive, cache_clear,
19
  DEMUCS_MODELS, DEMUCS_STEMS,
20
  )
21
  from synth_generator import generate_test_song
 
35
 
36
  def run_extraction(audio_in, stem_choice, demucs_model, demucs_shifts, demucs_overlap,
37
  onset_mode, onset_delta, energy_db, pre_pad, min_dur, max_dur, min_gap,
38
+ ncc_threshold, ncc_compare_ms, linkage, target_min, target_max,
39
  do_synthesize, progress=gr.Progress()):
40
  if audio_in is None:
41
  return [None] * 8
 
74
  progress(0.35, desc="Classifying...")
75
  hits = classify_hits(hits)
76
 
77
+ progress(0.45, desc=f"NCC clustering...")
78
  clusters = cluster_hits(hits, ncc_threshold=float(ncc_threshold),
79
+ max_compare_ms=float(ncc_compare_ms),
80
+ target_min=int(target_min), target_max=int(target_max),
81
+ linkage=str(linkage))
82
 
83
  progress(0.65, desc="Scoring & selecting best...")
84
  select_best(clusters)
 
263
 
264
  with gr.Accordion("🔗 Clustering", open=False):
265
  with gr.Row():
266
+ ncc_thresh = gr.Slider(0.3, 0.99, value=0.80, step=0.01,
267
+ label='NCC threshold (higher = stricter)')
268
  ncc_ms = gr.Slider(50, 1000, value=200, step=50,
269
  label='Compare window (ms)')
270
+ linkage_dd = gr.Dropdown(['average', 'complete', 'single'],
271
+ value='average', label='Linkage')
272
+ with gr.Row():
273
+ target_min = gr.Number(value=0, label='Target min clusters (0 = use threshold)',
274
+ precision=0)
275
+ target_max = gr.Number(value=0, label='Target max clusters (0 = use threshold)',
276
+ precision=0)
277
+ gr.Markdown("*Set both target min/max > 0 to auto-search for the right threshold. "
278
+ "Leave at 0 to use the NCC threshold directly.*")
279
 
280
  with gr.Accordion("⚙️ Post-processing", open=False):
281
  do_synth = gr.Checkbox(value=True, label='Synthesize optimal samples from clusters')
 
305
  run_extraction,
306
  [audio_in, stem_dd, demucs_model, demucs_shifts, demucs_overlap,
307
  onset_mode, onset_delta, energy_db, pre_pad, min_dur, max_dur, min_gap,
308
+ ncc_thresh, ncc_ms, linkage_dd, target_min, target_max, do_synth],
309
  [stem_out, summary_md, rendered_out, sample_files,
310
  midi_file, archive_file, status_txt, metrics_tbl])
311