harp-dev Claude Opus 5.5 commited on
Commit
4a2ae26
·
verified ·
1 Parent(s): 6d9cf2a

Read htdemucs from the Demucs mirror, and declare the backbone's license

Browse files

Reads the htdemucs checkpoint from teamup-tech/Demucs-weights rather than Meta's servers, declares CC-BY-NC-4.0, the license of the MERT backbone, declares 16 kHz mono, and moves the model card first. It also imports spaces plainly, since it is always installed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Files changed (2) hide show
  1. README.md +3 -1
  2. app.py +30 -31
README.md CHANGED
@@ -8,7 +8,7 @@ sdk_version: 6.17.3
8
  python_version: '3.11'
9
  app_file: app.py
10
  pinned: false
11
- license: apache-2.0
12
  short_description: Text-to-song generation with lyrics and vocals
13
  tags:
14
  - category:generation
@@ -16,6 +16,8 @@ tags:
16
  - input:text
17
  - input:audio
18
  - output:audio
 
 
19
  ---
20
 
21
  Text-to-song generation with lyrics and vocals.
 
8
  python_version: '3.11'
9
  app_file: app.py
10
  pinned: false
11
+ license: cc-by-nc-4.0
12
  short_description: Text-to-song generation with lyrics and vocals
13
  tags:
14
  - category:generation
 
16
  - input:text
17
  - input:audio
18
  - output:audio
19
+ - sample-rate:16000
20
+ - channels:mono
21
  ---
22
 
23
  Text-to-song generation with lyrics and vocals.
app.py CHANGED
@@ -1,25 +1,14 @@
 
 
1
  import sys
2
 
3
  sys.stdout.reconfigure(line_buffering=True)
4
 
5
- try:
6
- import spaces
7
- except ImportError:
8
- # keep @spaces.GPU usable as a no-op; ZeroGPU requires this exact name.
9
- class spaces:
10
- class GPU:
11
- def __init__(self, func=None, duration=60):
12
- self.func = func
13
-
14
- def __call__(self, *args, **kwargs):
15
- if self.func is not None:
16
- return self.func(*args, **kwargs)
17
- func = args[0]
18
- return func
19
-
20
  import os
21
  import shutil
22
  import tempfile
 
23
 
24
  import gradio as gr
25
  import numpy as np
@@ -27,7 +16,7 @@ import soundfile as sf
27
  import torch
28
  from demucs import pretrained
29
  from huggingface_hub import hf_hub_download, snapshot_download
30
- from pyharp import ModelCard, Subcategory, build_endpoint
31
 
32
  from songgen import (
33
  SongGenDualTrackForConditionalGeneration,
@@ -35,6 +24,21 @@ from songgen import (
35
  SongGenProcessor,
36
  )
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
39
 
40
  MODES = {
@@ -88,7 +92,16 @@ def fetch_assets():
88
  snapshot_download(MERT_REPO, revision=MERT_REVISION,
89
  allow_patterns=["*.json", "*.py", "pytorch_model.bin"])
90
  snapshot_download(HUBERT_REPO, revision=HUBERT_REVISION)
91
- pretrained.get_model("htdemucs") # caches its checkpoint for the processor
 
 
 
 
 
 
 
 
 
92
  except Exception as e:
93
  assets_error = str(e)
94
 
@@ -100,20 +113,6 @@ if __name__ != "__main__":
100
  fetch_assets()
101
 
102
 
103
- model_card = ModelCard(
104
- name="SongGen",
105
- description=(
106
- "Single-stage auto-regressive transformer for text-to-song generation. "
107
- "Give it lyrics and a description of the music, plus an optional "
108
- "reference voice, and it generates a full song. Repository: "
109
- "https://github.com/LiuZH-19/SongGen Paper: "
110
- "https://arxiv.org/abs/2502.13128"
111
- ),
112
- author="Zihan Liu, Shuangrui Ding, Zhixiong Zhang, Xiaoyi Dong, Pan Zhang, Yuhang Zang, Yuhang Cao, Dahua Lin, Jiaqi Wang",
113
- tags=[Subcategory.HOLISTIC],
114
- )
115
-
116
-
117
  def get_mode(mode_name):
118
  """Build a mode's model + processor on first use, then reuse them.
119
  Loading MERT's remote code touches CUDA, so this can only happen inside
 
1
+ import spaces # imported first, as ZeroGPU requires
2
+
3
  import sys
4
 
5
  sys.stdout.reconfigure(line_buffering=True)
6
 
7
+ import contextlib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  import os
9
  import shutil
10
  import tempfile
11
+ from pathlib import Path
12
 
13
  import gradio as gr
14
  import numpy as np
 
16
  import torch
17
  from demucs import pretrained
18
  from huggingface_hub import hf_hub_download, snapshot_download
19
+ from pyharp import Channels, ModelCard, SampleRate, Subcategory, build_endpoint
20
 
21
  from songgen import (
22
  SongGenDualTrackForConditionalGeneration,
 
24
  SongGenProcessor,
25
  )
26
 
27
+ model_card = ModelCard(
28
+ name="SongGen",
29
+ description=(
30
+ "Single-stage auto-regressive transformer for text-to-song generation. "
31
+ "Give it lyrics and a description of the music, plus an optional "
32
+ "reference voice, and it generates a full song, as 16 kHz mono audio. The code is "
33
+ "Apache-2.0, but the model runs on the MERT-v1-330M encoder, whose weights are "
34
+ "CC-BY-NC-4.0, so results cannot be used commercially. Repository: "
35
+ "https://github.com/LiuZH-19/SongGen Paper: "
36
+ "https://arxiv.org/abs/2502.13128"
37
+ ),
38
+ author="Zihan Liu, Shuangrui Ding, Zhixiong Zhang, Xiaoyi Dong, Pan Zhang, Yuhang Zang, Yuhang Cao, Dahua Lin, Jiaqi Wang",
39
+ tags=[Subcategory.HOLISTIC, SampleRate(16000), Channels(1)],
40
+ )
41
+
42
  DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
43
 
44
  MODES = {
 
92
  snapshot_download(MERT_REPO, revision=MERT_REVISION,
93
  allow_patterns=["*.json", "*.py", "pytorch_model.bin"])
94
  snapshot_download(HUBERT_REPO, revision=HUBERT_REVISION)
95
+ # demucs would download the htdemucs checkpoint from Meta's own server, so it is read from
96
+ # a mirror on the Hub, linked where torch.hub looks first, and cached for the processor
97
+ demucs_hub = Path(torch.hub.get_dir()) / "checkpoints"
98
+ demucs_hub.mkdir(parents=True, exist_ok=True)
99
+ with contextlib.suppress(FileExistsError):
100
+ (demucs_hub / "955717e8-8726e21a.th").symlink_to(hf_hub_download(
101
+ "teamup-tech/Demucs-weights", "hybrid_transformer/955717e8-8726e21a.th",
102
+ revision="e12e76af128e0935a0ad1734cb97974e5d27663d",
103
+ ))
104
+ pretrained.get_model("htdemucs")
105
  except Exception as e:
106
  assets_error = str(e)
107
 
 
113
  fetch_assets()
114
 
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  def get_mode(mode_name):
117
  """Build a mode's model + processor on first use, then reuse them.
118
  Loading MERT's remote code touches CUDA, so this can only happen inside