Spaces:
Sleeping
Sleeping
Update js/app.py
Browse files50 unmodified lines51525354555657585954555657585960616227 unmodified lines9091929393949596174 unmodified lines2712722732742752762772782792742752762772782792802 unmodified lines28328428528828628728828950 unmodified linesJOB_TTL_SECONDS = 30 * 60 # delete job files/state 30 min after completionSWEEP_INTERVAL_SECONDS = 5 * 60
# Demucs model name. htdemucs is Meta's best general-purpose free model# and natively separates into 4 stems: vocals, drums, bass, other.# For "2-stem" mode we just sum drums+bass+other into "instrumental".# htdemucs_ft is the fine-tuned checkpoint of htdemucs β same speed,# measurably better separation quality on most music genres.MODEL_NAME = "htdemucs_ft"# htdemucs is Meta's default Demucs v4 Hybrid Transformer model.# Unlike the v3 MDX ensembles (which run 4 separate neural networks# sequentially), htdemucs performs separation of all stems in a# single forward pass. This is 2-3x faster on CPU-only hosts, uses# less memory, and delivers equal or superior Transformer-based quality.MODEL_NAME = "htdemucs"
_model = None # populated at startup
27 unmodified lines
def load_model(): """ Loads htdemucs_ft once at startup and tunes PyTorch for maximum Loads htdemucs once at startup and tunes PyTorch for maximum single-machine CPU throughput. """ global _model174 unmodified lines job.progress = 20
# ββ 3. Separate (the expensive step) βββββββββββββββββββββββββββββββββββββββ # Do NOT pass a custom segment= here. htdemucs_ft's hybrid STFT branch # requires chunks of exactly model.segment (7.8 s = 343,980 samples at # 44100 Hz). Passing a different value (e.g. 10 s = 441,000 samples) # makes the internal overlap-add reshape impossible and crashes with # "shape [1,4,-1,343980] is invalid for input of size β¦". # apply_model reads model.segment automatically when segment= is omitted. # segment= is intentionally omitted: apply_model reads model.segment # (architecture-native chunk size) automatically. # overlap=0.1 (10 %) instead of the default 0.25 reduces the number of # chunks by ~20 % with negligible quality loss on normal music. _N_THREADS = max(os.cpu_count() or 2, 2) with torch.no_grad(): sources_norm = apply_model(2 unmodified lines device="cpu", progress=False, split=True, overlap=0.25, # 25 % overlap β accuracy/speed sweet-spot overlap=0.1, # reduced from 0.25 β 20 % fewer chunks num_workers=0, # no subprocesses on HF Spaces )[0] # drop batch dim: (stems, 2, samples) del wav_normjs/app.py+12-14