splitify-backend / README.md
BhavyaPatel07's picture
Upload 5 files
b32fd79 verified
|
Raw History Blame Contribute Delete
2.36 kB
metadata
title: StemSplit Backend
emoji: 🎵
colorFrom: indigo
colorTo: pink
sdk: docker
app_port: 7860
pinned: false

StemSplit Backend

FastAPI service that splits a song into stems (vocals / instrumental, or vocals / drums / bass / other) using Meta's Demucs (htdemucs) model. Runs as a Docker Space on Hugging Face's free CPU tier.

How it works

  1. POST /separate — upload an audio file (mp3/wav/m4a/flac/ogg, max 25MB) with a mode field of 2stem or 4stem. Returns a job_id.
  2. GET /status/{job_id} — poll this. Returns queued, processing (with a 0-100 progress), done, or error.
  3. GET /download/{job_id}/{stem} — once status is done, download each stem as a WAV. stem is one of vocals/instrumental (2stem mode) or vocals/drums/bass/other (4stem mode).

Why these specific design choices

  • htdemucs: Meta's current best general-purpose open-source separation model, and the only one that gives you both 2-stem and 4-stem output from a single model (no need to juggle two different checkpoints).
  • In-memory asyncio queue, one job at a time: the free CPU tier has 2 vCPUs and no GPU. Running jobs concurrently would just slow every job down and risk OOM. A simple sequential queue is the most reliable choice at this scale.
  • Model weights baked into the Docker image (download_model.py runs at build time): avoids any network dependency or download delay/failure on cold start, which is the most common cause of "it worked yesterday, now it's broken" reports for Demucs-on-Spaces deployments.
  • 25MB upload limit: keeps CPU-only inference time bounded to a few minutes for typical songs, instead of letting someone upload a 40-minute DJ set that never finishes in time.
  • Ephemeral /tmp storage with a sweeper: HF Spaces wipes container disk on restart/sleep anyway, so there's no point trying to persist job files. The sweeper just keeps the running container from filling up its disk during a long session.

Cold starts

Free CPU Spaces sleep after 48 hours of inactivity. The first request after a sleep will take longer (container boot + model load into RAM), even though the model weights themselves don't need downloading. The frontend should show a "waking up the server, this can take a minute" state on first load.