Spaces:
Sleeping
Sleeping
Update js/app.py
Browse files50 unmodified lines51525354555657585960616227 unmodified lines90919293949596174 unmodified lines2712722732742752762772782792802812822 unmodified lines28528628728828929029150 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"_model = None # populated at startup27 unmodified linesdef load_model():"""Loads htdemucs_ft once at startup and tunes PyTorch for maximumsingle-machine CPU throughput."""global _model174 unmodified linesjob.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._N_THREADS = max(os.cpu_count() or 2, 2)with torch.no_grad():sources_norm = apply_model(2 unmodified linesdevice="cpu",progress=False,split=True,overlap=0.25, # 25 % overlap β accuracy/speed sweet-spotnum_workers=0, # no subprocesses on HF Spaces)[0] # drop batch dim: (stems, 2, samples)del wav_norm50 unmodified lines51525354555657585960616227 unmodified lines90919293949596174 unmodified lines2712722732742752762772782792802 unmodified lines28328428528628728828950 unmodified linesJOB_TTL_SECONDS = 30 * 60 # delete job files/state 30 min after completionSWEEP_INTERVAL_SECONDS = 5 * 60# 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 startup27 unmodified linesdef load_model():"""Loads htdemucs once at startup and tunes PyTorch for maximumsingle-machine CPU throughput."""global _model174 unmodified linesjob.progress = 20# ββ 3. Separate (the expensive step) βββββββββββββββββββββββββββββββββββββββ# 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 linesdevice="cpu",progress=False,split=True,overlap=0.1, # reduced from 0.25 β 20 % fewer chunksnum_workers=0, # no subprocesses on HF Spaces)[0] # drop batch dim: (stems, 2, samples)del wav_norm
js/app.py+12-14