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

checkbox update

Browse files
Files changed (1) hide show
  1. app.py +91 -23
app.py CHANGED
@@ -1,12 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
  import gradio as gr
3
  from scipy.io.wavfile import write
4
  import subprocess
5
  import torch
6
 
7
- from audio_separator import Separator # Ensure this is correctly implemented
 
8
 
9
- def inference(audio):
10
  os.makedirs("out", exist_ok=True)
11
  audio_path = 'test.wav'
12
  write(audio_path, audio[0], audio[1])
@@ -16,45 +80,49 @@ def inference(audio):
16
  print(f"Using device: {device}")
17
  else:
18
  use_cuda=False
19
- print(f"Using device: {device}")
20
  try:
21
-
22
- # Using subprocess.run for better control
23
  command = f"python3 -m demucs.separate -n htdemucs_6s -d {device} {audio_path} -o out"
24
  process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
25
  print("Demucs script output:", process.stdout.decode())
26
  except subprocess.CalledProcessError as e:
27
  print("Error in Demucs script:", e.stderr.decode())
28
- return None
29
 
30
  try:
31
- # Separating the stems using your custom separator
32
- separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=use_cuda, output_format='mp3')
33
  primary_stem_path, secondary_stem_path = separator.separate()
34
  except Exception as e:
35
  print("Error in custom separation:", str(e))
36
- return None
37
 
38
- # Collecting all file paths
39
- files = [f"./out/htdemucs_6s/test/{stem}.wav" for stem in ["vocals", "bass", "drums", "other", "piano", "guitar"]]
40
- files.extend([secondary_stem_path,primary_stem_path ])
 
 
 
 
 
 
 
41
 
42
- # Check if files exist
43
- existing_files = [file for file in files if os.path.isfile(file)]
44
- if not existing_files:
45
- print("No files were created.")
46
- return None
47
 
48
- return existing_files
 
 
49
 
50
  # Gradio Interface
51
  title = "Source Separation Demo"
52
- description = "Music Source Separation in the Waveform Domain. To use it, simply upload your audio."
53
- gr.Interface(
54
  inference,
55
- gr.components.Audio(type="numpy", label="Input"),
56
- [gr.components.Audio(type="filepath", label=stem) for stem in ["Full Vocals","Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Backing Vocals" ]],
57
  title=title,
58
  description=description,
59
- ).launch()
 
60
 
 
 
1
+ # import os
2
+ # import gradio as gr
3
+ # from scipy.io.wavfile import write
4
+ # import subprocess
5
+ # import torch
6
+
7
+ # from audio_separator import Separator # Ensure this is correctly implemented
8
+
9
+ # def inference(audio):
10
+ # os.makedirs("out", exist_ok=True)
11
+ # audio_path = 'test.wav'
12
+ # write(audio_path, audio[0], audio[1])
13
+ # device = 'cuda' if torch.cuda.is_available() else 'cpu'
14
+ # if device=='cuda':
15
+ # use_cuda=True
16
+ # print(f"Using device: {device}")
17
+ # else:
18
+ # use_cuda=False
19
+ # print(f"Using device: {device}")
20
+ # try:
21
+
22
+ # # Using subprocess.run for better control
23
+ # command = f"python3 -m demucs.separate -n htdemucs_6s -d {device} {audio_path} -o out"
24
+ # process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
25
+ # print("Demucs script output:", process.stdout.decode())
26
+ # except subprocess.CalledProcessError as e:
27
+ # print("Error in Demucs script:", e.stderr.decode())
28
+ # return None
29
+
30
+ # try:
31
+ # # Separating the stems using your custom separator
32
+ # separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=use_cuda, output_format='mp3')
33
+ # primary_stem_path, secondary_stem_path = separator.separate()
34
+ # except Exception as e:
35
+ # print("Error in custom separation:", str(e))
36
+ # return None
37
+
38
+ # # Collecting all file paths
39
+ # files = [f"./out/htdemucs_6s/test/{stem}.wav" for stem in ["vocals", "bass", "drums", "other", "piano", "guitar"]]
40
+ # files.extend([secondary_stem_path,primary_stem_path ])
41
+
42
+ # # Check if files exist
43
+ # existing_files = [file for file in files if os.path.isfile(file)]
44
+ # if not existing_files:
45
+ # print("No files were created.")
46
+ # return None
47
+
48
+ # return existing_files
49
+
50
+ # # Gradio Interface
51
+ # title = "Source Separation Demo"
52
+ # description = "Music Source Separation in the Waveform Domain. To use it, simply upload your audio."
53
+ # gr.Interface(
54
+ # inference,
55
+ # gr.components.Audio(type="numpy", label="Input"),
56
+ # [gr.components.Audio(type="filepath", label=stem) for stem in ["Full Vocals","Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Backing Vocals" ]],
57
+ # title=title,
58
+ # description=description,
59
+ # ).launch()
60
+
61
+
62
+
63
+
64
  import os
65
  import gradio as gr
66
  from scipy.io.wavfile import write
67
  import subprocess
68
  import torch
69
 
70
+ # Assuming audio_separator is available in your environment
71
+ from audio_separator import Separator
72
 
73
+ def inference(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, backing_vocals):
74
  os.makedirs("out", exist_ok=True)
75
  audio_path = 'test.wav'
76
  write(audio_path, audio[0], audio[1])
 
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"
86
  process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
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,
101
+ "bass": "./out/htdemucs_6s/test/bass.wav" if bass else None,
102
+ "drums": "./out/htdemucs_6s/test/drums.wav" if drums else None,
103
+ "other": "./out/htdemucs_6s/test/other.wav" if other else None,
104
+ "piano": "./out/htdemucs_6s/test/piano.wav" if piano else None,
105
+ "guitar": "./out/htdemucs_6s/test/guitar.wav" if guitar else None,
106
+ "lead_vocals": primary_stem_path if lead_vocals else None,
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"]
114
+ checkboxes = [gr.components.Checkbox(label=label) for label in checkbox_labels]
115
 
116
  # Gradio Interface
117
  title = "Source Separation Demo"
118
+ description = "Music Source Separation in the Waveform Domain. Upload your audio to begin."
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)