harp-dev commited on
Commit
3398bbd
·
verified ·
1 Parent(s): 3cedd40

Fetch the stem checkpoints from a model repository

Browse files
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import math
2
  import librosa
3
  import tempfile
@@ -297,7 +298,33 @@ model_card = ModelCard(
297
  tags=[Subcategory.STEM_SEPARATION, 'drums', 'demucs', 'source-separation', 'pyharp', 'stems', 'multi-output'],
298
  )
299
 
300
- MODEL = LarsNet(wiener_filter=False, device="cpu", config="config.yaml")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
301
 
302
 
303
  @torch.inference_mode()
 
1
+ from huggingface_hub import hf_hub_download
2
  import math
3
  import librosa
4
  import tempfile
 
298
  tags=[Subcategory.STEM_SEPARATION, 'drums', 'demucs', 'source-separation', 'pyharp', 'stems', 'multi-output'],
299
  )
300
 
301
+
302
+ # The five stem checkpoints live in a model repository rather than in this
303
+ # Space, which keeps the Space small enough to clone quickly. They are fetched
304
+ # at module scope, so a failure shows up when the Space boots rather than
305
+ # inside a job, and pinned to a revision so behavior cannot change under us.
306
+ #
307
+ # The vendored LarsNet class reads these paths out of config.yaml itself, so
308
+ # the config is copied with the downloaded paths filled in rather than the
309
+ # class being patched.
310
+ _WEIGHTS_REPO = "teamup-tech/LarsNet-weights"
311
+ _WEIGHTS_REVISION = "1da4e632b0c47b3002a7d2f2d23e54531ae6eee7"
312
+
313
+ _config = yaml.safe_load(Path("config.yaml").read_text())
314
+ _config["inference_models"] = {
315
+ stem: hf_hub_download(
316
+ repo_id=_WEIGHTS_REPO,
317
+ filename=f"pretrained_{stem}_unet.pth",
318
+ revision=_WEIGHTS_REVISION,
319
+ )
320
+ for stem in _config["inference_models"]
321
+ }
322
+
323
+ CONFIG_PATH = Path(tempfile.mkdtemp(prefix="larsnet-")) / "config.yaml"
324
+ CONFIG_PATH.write_text(yaml.safe_dump(_config))
325
+
326
+ MODEL = LarsNet(wiener_filter=False, device="cpu",
327
+ config=str(CONFIG_PATH))
328
 
329
 
330
  @torch.inference_mode()
pretrained_larsnet_models/cymbals/pretrained_cymbals_unet.pth DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:889804c465e2c6fdbbe45febbd4daafef01d8d22f9f34fb968695ab9793858d0
3
- size 118037828
 
 
 
 
pretrained_larsnet_models/hihat/pretrained_hihat_unet.pth DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ac004ac24a26e77f6d39671ed8ba45c3f476e956900d469ebb402386dad11dd7
3
- size 118037828
 
 
 
 
pretrained_larsnet_models/kick/pretrained_kick_unet.pth DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:ed821b6a69b1ef0413ac9ef7958ac9a37e5f4f056e66f0191496bf903ac2628d
3
- size 118037828
 
 
 
 
pretrained_larsnet_models/snare/pretrained_snare_unet.pth DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:78bd75001ff6c52b23de6245cecd1606adbd45348e0216f6d8c116553013e4fd
3
- size 118037828
 
 
 
 
pretrained_larsnet_models/toms/pretrained_toms_unet.pth DELETED
@@ -1,3 +0,0 @@
1
- version https://git-lfs.github.com/spec/v1
2
- oid sha256:699112983948e14d805890a0723e5b402203a3a1db1cd0ccdd8a80058062ef77
3
- size 118037828