Pecorized commited on
Commit
ed2622c
1 Parent(s): 08000a8

initial push

Browse files
Files changed (3) hide show
  1. app.py +51 -0
  2. package.txt +1 -0
  3. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from scipy.io.wavfile import write
4
+ import subprocess
5
+
6
+ from audio_separator import Separator # Ensure this is correctly implemented
7
+
8
+ def inference(audio):
9
+ os.makedirs("out", exist_ok=True)
10
+ audio_path = 'test.wav'
11
+ write(audio_path, audio[0], audio[1])
12
+
13
+ try:
14
+ # Using subprocess.run for better control
15
+ command = f"python3 -m demucs.separate -n htdemucs_6s -d cpu {audio_path} -o out"
16
+ process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
17
+ print("Demucs script output:", process.stdout.decode())
18
+ except subprocess.CalledProcessError as e:
19
+ print("Error in Demucs script:", e.stderr.decode())
20
+ return None
21
+
22
+ try:
23
+ # Separating the stems using your custom separator
24
+ separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=False, output_format='mp3')
25
+ primary_stem_path, secondary_stem_path = separator.separate()
26
+ except Exception as e:
27
+ print("Error in custom separation:", str(e))
28
+ return None
29
+
30
+ # Collecting all file paths
31
+ files = [f"./out/htdemucs_6s/test/{stem}.wav" for stem in ["vocals", "bass", "drums", "other", "piano", "guitar"]]
32
+ files.extend([secondary_stem_path,primary_stem_path ])
33
+
34
+ # Check if files exist
35
+ existing_files = [file for file in files if os.path.isfile(file)]
36
+ if not existing_files:
37
+ print("No files were created.")
38
+ return None
39
+
40
+ return existing_files
41
+
42
+ # Gradio Interface
43
+ title = "Source Separation Demo"
44
+ description = "Music Source Separation in the Waveform Domain. To use it, simply upload your audio."
45
+ gr.Interface(
46
+ inference,
47
+ gr.components.Audio(type="numpy", label="Input"),
48
+ [gr.components.Audio(type="filepath", label=stem) for stem in ["Full Vocals","Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Chorus" ]],
49
+ title=title,
50
+ description=description,
51
+ ).launch()
package.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ ffmpeg
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ git+https://github.com/facebookresearch/demucs#egg=demucs
2
+ scipy
3
+ diffq
4
+ audio-separator