lllindsey0615 commited on
Commit
ee4b2a5
·
1 Parent(s): 435984f

debug the configuration error

Browse files
Files changed (2) hide show
  1. app.py +24 -35
  2. requirements.txt +5 -4
app.py CHANGED
@@ -1,44 +1,37 @@
1
- import torch
2
- import torchaudio
3
  import gradio as gr
4
  import spaces # Enables ZeroGPU on Hugging Face
5
- from demucs import pretrained
6
- from demucs.apply import apply_model
 
 
 
 
7
  from pyharp import *
8
- from audiotools import AudioSignal
 
9
 
10
 
11
- # Available Demucs models
12
  DEMUX_MODELS = ["mdx_extra_q", "mdx_extra", "htdemucs", "mdx_q"]
13
 
14
  STEM_CHOICES = {
15
- "Vocals": 3,
16
- "Drums": 0,
17
- "Bass": 1,
18
- "Other": 2,
19
  "Instrumental (No Vocals)": "instrumental"
20
  }
21
 
22
- @spaces.GPU
23
- def separate_stem(audio_file_path: str, model_name: str, stem_choice: str):
24
- """
25
- Separates an audio file into the chosen stem using a Demucs model.
26
- Ensures correct stem ordering and supports mono input.
27
- """
28
- # Load Demucs model
29
  model = pretrained.get_model(model_name)
30
  model.to('cuda' if torch.cuda.is_available() else 'cpu')
31
  model.eval()
32
 
33
- # Load the audio file
34
  waveform, sr = torchaudio.load(audio_file_path)
35
-
36
- # Check if input is mono
37
  is_mono = waveform.shape[0] == 1
38
  if is_mono:
39
- waveform = waveform.repeat(2, 1) # Convert mono to stereo for Demucs
40
 
41
- # Apply Demucs model
42
  with torch.no_grad():
43
  stems_batch = apply_model(
44
  model,
@@ -48,24 +41,20 @@ def separate_stem(audio_file_path: str, model_name: str, stem_choice: str):
48
  split=True
49
  )
50
 
51
- # stems shape: (batch, stems, channels, samples)
52
- stems = stems_batch[0]
53
-
54
- print(f"Model '{model_name}' extracted stems shape: {stems.shape}")
55
 
56
  if stem_choice == "Instrumental (No Vocals)":
57
- stem = stems[0] + stems[1] + stems[2] # Drums + Bass + Other
58
  else:
59
  stem_index = STEM_CHOICES[stem_choice]
60
  stem = stems[stem_index]
61
 
62
- # Convert back to mono if the input was originally mono
63
  if is_mono:
64
- stem = stem.mean(dim=0, keepdim=True) # Stereo → Mono
65
 
66
- # Convert to AudioSignal with float32 dtype
67
- stem_signal = AudioSignal(stem.cpu().numpy().astype('float32'), sample_rate=sr)
68
- return stem_signal
69
 
70
  def process_fn_stem(audio_file_path: str, demucs_model: str, stem_choice: str):
71
  """
@@ -78,7 +67,7 @@ def process_fn_stem(audio_file_path: str, demucs_model: str, stem_choice: str):
78
  return stem_path, LabelList(labels=[])
79
 
80
 
81
- # Define the model card
82
  model_card = ModelCard(
83
  name="Demucs Stem Separator",
84
  description="Uses Demucs to separate a music track into a selected stem.",
@@ -86,9 +75,9 @@ model_card = ModelCard(
86
  tags=["demucs", "source-separation", "pyharp", "stems"]
87
  )
88
 
89
- # Build Gradio interface with dropdowns for model and stem selection
90
  with gr.Blocks() as demo:
91
- gr.LoginButton()
92
  dropdown_model = gr.Dropdown(
93
  label="Select Demucs Model",
94
  choices=DEMUX_MODELS,
 
 
 
1
  import gradio as gr
2
  import spaces # Enables ZeroGPU on Hugging Face
3
+ from transformers import AutoModelForCausalLM
4
+ from anticipation.sample import generate
5
+ from anticipation.convert import events_to_midi, midi_to_events
6
+ from anticipation import ops
7
+ from anticipation.tokenize import extract_instruments
8
+ import torch
9
  from pyharp import *
10
+ from safetensors.torch import load_file
11
+ import os
12
 
13
 
 
14
  DEMUX_MODELS = ["mdx_extra_q", "mdx_extra", "htdemucs", "mdx_q"]
15
 
16
  STEM_CHOICES = {
17
+ "Vocals": 3,
18
+ "Drums": 0,
19
+ "Bass": 1,
20
+ "Other": 2,
21
  "Instrumental (No Vocals)": "instrumental"
22
  }
23
 
24
+ @space.GPU
25
+ def separate_stem(audio_file_path: str, model_name: str, stem_choice: str) -> AudioSignal:
 
 
 
 
 
26
  model = pretrained.get_model(model_name)
27
  model.to('cuda' if torch.cuda.is_available() else 'cpu')
28
  model.eval()
29
 
 
30
  waveform, sr = torchaudio.load(audio_file_path)
 
 
31
  is_mono = waveform.shape[0] == 1
32
  if is_mono:
33
+ waveform = waveform.repeat(2, 1)
34
 
 
35
  with torch.no_grad():
36
  stems_batch = apply_model(
37
  model,
 
41
  split=True
42
  )
43
 
44
+ stems = stems_batch[0]
 
 
 
45
 
46
  if stem_choice == "Instrumental (No Vocals)":
47
+ stem = stems[0] + stems[1] + stems[2]
48
  else:
49
  stem_index = STEM_CHOICES[stem_choice]
50
  stem = stems[stem_index]
51
 
 
52
  if is_mono:
53
+ stem = stem.mean(dim=0, keepdim=True)
54
 
55
+ return AudioSignal(stem.cpu().numpy().astype('float32'), sample_rate=sr)
56
+
57
+ # Gradio Callback Function
58
 
59
  def process_fn_stem(audio_file_path: str, demucs_model: str, stem_choice: str):
60
  """
 
67
  return stem_path, LabelList(labels=[])
68
 
69
 
70
+ # Model Card
71
  model_card = ModelCard(
72
  name="Demucs Stem Separator",
73
  description="Uses Demucs to separate a music track into a selected stem.",
 
75
  tags=["demucs", "source-separation", "pyharp", "stems"]
76
  )
77
 
78
+ # Gradio UI
79
  with gr.Blocks() as demo:
80
+
81
  dropdown_model = gr.Dropdown(
82
  label="Select Demucs Model",
83
  choices=DEMUX_MODELS,
requirements.txt CHANGED
@@ -1,6 +1,5 @@
1
-
2
  -e git+https://github.com/TEAMuP-dev/pyharp.git#egg=pyharp
3
- demucs==4.0.0
4
  dora-search
5
  einops
6
  julius>=0.2.3
@@ -8,11 +7,13 @@ lameenc>=1.2
8
  openunmix
9
  pyyaml
10
  tqdm
11
- torch==2.0.1
12
  torchaudio>=0.8, <2.1
13
  diffq>=0.2.1
14
  ffmpeg
15
  numpy<2
16
  scipy
17
  soundfile
18
- hydra-core>=1.1
 
 
 
 
1
  -e git+https://github.com/TEAMuP-dev/pyharp.git#egg=pyharp
2
+ demucs
3
  dora-search
4
  einops
5
  julius>=0.2.3
 
7
  openunmix
8
  pyyaml
9
  tqdm
10
+ torch>=1.8.1, <2.1
11
  torchaudio>=0.8, <2.1
12
  diffq>=0.2.1
13
  ffmpeg
14
  numpy<2
15
  scipy
16
  soundfile
17
+ hydra-core>=1.1
18
+ typing
19
+ pydantic==2.10.6