v5: target cluster range + caching + average linkage — app.py
Browse files14 unmodified lines1516171819202113 unmodified lines3536373839404132 unmodified lines747576777879808182178 unmodified lines26126226326426526626726826927023 unmodified lines29429529629729829930014 unmodified linesextract_stem, detect_onsets, classify_hits,cluster_hits, select_best, synthesize_from_cluster,sample_quality_score, export_midi, detect_bpm,render_midi_with_samples, build_archive,DEMUCS_MODELS, DEMUCS_STEMS,)from synth_generator import generate_test_song13 unmodified linesdef run_extraction(audio_in, stem_choice, demucs_model, demucs_shifts, demucs_overlap,onset_mode, onset_delta, energy_db, pre_pad, min_dur, max_dur, min_gap,ncc_threshold, ncc_compare_ms,do_synthesize, progress=gr.Progress()):if audio_in is None:return [None] * 832 unmodified linesprogress(0.35, desc="Classifying...")hits = classify_hits(hits)progress(0.45, desc=f"NCC clustering (threshold={ncc_threshold})...")clusters = cluster_hits(hits, ncc_threshold=float(ncc_threshold),max_compare_ms=float(ncc_compare_ms))progress(0.65, desc="Scoring & selecting best...")select_best(clusters)178 unmodified lineswith gr.Accordion("🔗 Clustering", open=False):with gr.Row():ncc_thresh = gr.Slider(0.5, 0.99, value=0.80, step=0.01,label='NCC threshold (higher = stricter matching)')ncc_ms = gr.Slider(50, 1000, value=200, step=50,label='Compare window (ms)')with gr.Accordion("⚙️ Post-processing", open=False):do_synth = gr.Checkbox(value=True, label='Synthesize optimal samples from clusters')23 unmodified linesrun_extraction,[audio_in, stem_dd, demucs_model, demucs_shifts, demucs_overlap,onset_mode, onset_delta, energy_db, pre_pad, min_dur, max_dur, min_gap,ncc_thresh, ncc_ms, do_synth],[stem_out, summary_md, rendered_out, sample_files,midi_file, archive_file, status_txt, metrics_tbl])14 unmodified lines1516171819202113 unmodified lines3536373839404132 unmodified lines7475767778798081828384178 unmodified lines26326426526626726826927027127227327427527627727827928028123 unmodified lines30530630730830931031114 unmodified linesextract_stem, detect_onsets, classify_hits,cluster_hits, select_best, synthesize_from_cluster,sample_quality_score, export_midi, detect_bpm,render_midi_with_samples, build_archive, cache_clear,DEMUCS_MODELS, DEMUCS_STEMS,)from synth_generator import generate_test_song13 unmodified linesdef run_extraction(audio_in, stem_choice, demucs_model, demucs_shifts, demucs_overlap,onset_mode, onset_delta, energy_db, pre_pad, min_dur, max_dur, min_gap,ncc_threshold, ncc_compare_ms, linkage, target_min, target_max,do_synthesize, progress=gr.Progress()):if audio_in is None:return [None] * 832 unmodified linesprogress(0.35, desc="Classifying...")hits = classify_hits(hits)progress(0.45, desc=f"NCC clustering...")clusters = cluster_hits(hits, ncc_threshold=float(ncc_threshold),max_compare_ms=float(ncc_compare_ms),target_min=int(target_min), target_max=int(target_max),linkage=str(linkage))progress(0.65, desc="Scoring & selecting best...")select_best(clusters)178 unmodified lineswith gr.Accordion("🔗 Clustering", open=False):with gr.Row():ncc_thresh = gr.Slider(0.3, 0.99, value=0.80, step=0.01,label='NCC threshold (higher = stricter)')ncc_ms = gr.Slider(50, 1000, value=200, step=50,label='Compare window (ms)')linkage_dd = gr.Dropdown(['average', 'complete', 'single'],value='average', label='Linkage')with gr.Row():target_min = gr.Number(value=0, label='Target min clusters (0 = use threshold)',precision=0)target_max = gr.Number(value=0, label='Target max clusters (0 = use threshold)',precision=0)gr.Markdown("*Set both target min/max > 0 to auto-search for the right threshold. ""Leave at 0 to use the NCC threshold directly.*")with gr.Accordion("⚙️ Post-processing", open=False):do_synth = gr.Checkbox(value=True, label='Synthesize optimal samples from clusters')23 unmodified linesrun_extraction,[audio_in, stem_dd, demucs_model, demucs_shifts, demucs_overlap,onset_mode, onset_delta, energy_db, pre_pad, min_dur, max_dur, min_gap,ncc_thresh, ncc_ms, linkage_dd, target_min, target_max, do_synth],[stem_out, summary_md, rendered_out, sample_files,midi_file, archive_file, status_txt, metrics_tbl])
app.py+18-7