Pecorized commited on
Commit
afe64d9
1 Parent(s): 1912645

Updated with checkbox done

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -60,7 +60,6 @@
60
 
61
 
62
 
63
-
64
  import os
65
  import gradio as gr
66
  from scipy.io.wavfile import write
@@ -75,11 +74,13 @@ def inference(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, bac
75
  audio_path = 'test.wav'
76
  write(audio_path, audio[0], audio[1])
77
  device = 'cuda' if torch.cuda.is_available() else 'cpu'
 
78
  if device=='cuda':
79
  use_cuda=True
80
  print(f"Using device: {device}")
81
  else:
82
  use_cuda=False
 
83
 
84
  try:
85
  command = f"python3 -m demucs.separate -n htdemucs_6s -d {device} {audio_path} -o out"
@@ -87,14 +88,14 @@ def inference(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, bac
87
  print("Demucs script output:", process.stdout.decode())
88
  except subprocess.CalledProcessError as e:
89
  print("Error in Demucs script:", e.stderr.decode())
90
- return None, None, None, None, None, None, None, None
91
 
92
  try:
93
- separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=device=='cuda', output_format='wav')
94
  primary_stem_path, secondary_stem_path = separator.separate()
95
  except Exception as e:
96
  print("Error in custom separation:", str(e))
97
- return None, None, None, None, None, None, None, None
98
 
99
  stem_paths = {
100
  "vocals": "./out/htdemucs_6s/test/vocals.wav" if vocals else None,
@@ -107,7 +108,7 @@ def inference(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, bac
107
  "backing_vocals": secondary_stem_path if backing_vocals else None
108
  }
109
 
110
- return [stem_paths[stem] for stem in stem_paths]
111
 
112
  # Define checkboxes for each stem
113
  checkbox_labels = ["Full Vocals", "Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Backing Vocals"]
@@ -119,10 +120,11 @@ description = "Music Source Separation in the Waveform Domain. Upload your audio
119
  iface = gr.Interface(
120
  inference,
121
  [gr.components.Audio(type="numpy", label="Input")] + checkboxes,
122
- [gr.components.Audio(type="filepath", label=label) for label in checkbox_labels],
123
  title=title,
124
  description=description,
125
-
126
  )
127
 
128
- iface.launch(debug=True)
 
 
60
 
61
 
62
 
 
63
  import os
64
  import gradio as gr
65
  from scipy.io.wavfile import write
 
74
  audio_path = 'test.wav'
75
  write(audio_path, audio[0], audio[1])
76
  device = 'cuda' if torch.cuda.is_available() else 'cpu'
77
+ print(f"Using device: {device}")
78
  if device=='cuda':
79
  use_cuda=True
80
  print(f"Using device: {device}")
81
  else:
82
  use_cuda=False
83
+ print(f"Using device: {device}")
84
 
85
  try:
86
  command = f"python3 -m demucs.separate -n htdemucs_6s -d {device} {audio_path} -o out"
 
88
  print("Demucs script output:", process.stdout.decode())
89
  except subprocess.CalledProcessError as e:
90
  print("Error in Demucs script:", e.stderr.decode())
91
+ return [gr.Audio(visible=False)] * 8
92
 
93
  try:
94
+ separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=device==use_cuda, output_format='wav')
95
  primary_stem_path, secondary_stem_path = separator.separate()
96
  except Exception as e:
97
  print("Error in custom separation:", str(e))
98
+ return [gr.Audio(visible=False)] * 8
99
 
100
  stem_paths = {
101
  "vocals": "./out/htdemucs_6s/test/vocals.wav" if vocals else None,
 
108
  "backing_vocals": secondary_stem_path if backing_vocals else None
109
  }
110
 
111
+ return [gr.Audio(stem_paths[stem], visible=bool(stem_paths[stem])) for stem in stem_paths]
112
 
113
  # Define checkboxes for each stem
114
  checkbox_labels = ["Full Vocals", "Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Backing Vocals"]
 
120
  iface = gr.Interface(
121
  inference,
122
  [gr.components.Audio(type="numpy", label="Input")] + checkboxes,
123
+ [gr.Audio(label=label, visible=False) for label in checkbox_labels],
124
  title=title,
125
  description=description,
126
+
127
  )
128
 
129
+ iface.launch()
130
+