Spaces:
Build error
Build error
updated gif
Browse files
app.py
CHANGED
|
@@ -58,7 +58,7 @@
|
|
| 58 |
# description=description,
|
| 59 |
# ).launch()
|
| 60 |
|
| 61 |
-
|
| 62 |
|
| 63 |
# import os
|
| 64 |
# import gradio as gr
|
|
@@ -70,17 +70,15 @@
|
|
| 70 |
# from audio_separator import Separator
|
| 71 |
|
| 72 |
# def inference(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, backing_vocals):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
# os.makedirs("out", exist_ok=True)
|
| 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,14 +86,14 @@
|
|
| 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==
|
| 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,7 +106,9 @@
|
|
| 108 |
# "backing_vocals": secondary_stem_path if backing_vocals else None
|
| 109 |
# }
|
| 110 |
|
| 111 |
-
#
|
|
|
|
|
|
|
| 112 |
|
| 113 |
# # Define checkboxes for each stem
|
| 114 |
# checkbox_labels = ["Full Vocals", "Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Backing Vocals"]
|
|
@@ -123,7 +123,6 @@
|
|
| 123 |
# [gr.Audio(label=label, visible=False) for label in checkbox_labels],
|
| 124 |
# title=title,
|
| 125 |
# description=description,
|
| 126 |
-
|
| 127 |
# )
|
| 128 |
|
| 129 |
# iface.launch()
|
|
@@ -132,6 +131,8 @@
|
|
| 132 |
|
| 133 |
|
| 134 |
|
|
|
|
|
|
|
| 135 |
import os
|
| 136 |
import gradio as gr
|
| 137 |
from scipy.io.wavfile import write
|
|
@@ -141,32 +142,37 @@ import torch
|
|
| 141 |
# Assuming audio_separator is available in your environment
|
| 142 |
from audio_separator import Separator
|
| 143 |
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
|
|
|
|
|
|
| 149 |
os.makedirs("out", exist_ok=True)
|
| 150 |
audio_path = 'test.wav'
|
| 151 |
write(audio_path, audio[0], audio[1])
|
| 152 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 153 |
-
print(f"Using device: {device}")
|
| 154 |
|
| 155 |
try:
|
| 156 |
command = f"python3 -m demucs.separate -n htdemucs_6s -d {device} {audio_path} -o out"
|
| 157 |
process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 158 |
-
print("Demucs script output:", process.stdout.decode())
|
| 159 |
except subprocess.CalledProcessError as e:
|
| 160 |
-
|
| 161 |
-
return [gr.Audio(visible=False)] * 8 + [loading_gif_path]
|
| 162 |
|
| 163 |
try:
|
| 164 |
separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=device=='cuda', output_format='wav')
|
| 165 |
primary_stem_path, secondary_stem_path = separator.separate()
|
| 166 |
except Exception as e:
|
| 167 |
-
|
| 168 |
-
return [gr.Audio(visible=False)] * 8 + [loading_gif_path]
|
| 169 |
|
|
|
|
| 170 |
stem_paths = {
|
| 171 |
"vocals": "./out/htdemucs_6s/test/vocals.wav" if vocals else None,
|
| 172 |
"bass": "./out/htdemucs_6s/test/bass.wav" if bass else None,
|
|
@@ -178,9 +184,23 @@ def inference(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, bac
|
|
| 178 |
"backing_vocals": secondary_stem_path if backing_vocals else None
|
| 179 |
}
|
| 180 |
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 184 |
|
| 185 |
# Define checkboxes for each stem
|
| 186 |
checkbox_labels = ["Full Vocals", "Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Backing Vocals"]
|
|
@@ -192,9 +212,10 @@ description = "Music Source Separation in the Waveform Domain. Upload your audio
|
|
| 192 |
iface = gr.Interface(
|
| 193 |
inference,
|
| 194 |
[gr.components.Audio(type="numpy", label="Input")] + checkboxes,
|
| 195 |
-
[gr.Audio(label=label, visible=False) for label in checkbox_labels],
|
| 196 |
title=title,
|
| 197 |
description=description,
|
| 198 |
)
|
| 199 |
|
| 200 |
iface.launch()
|
|
|
|
|
|
| 58 |
# description=description,
|
| 59 |
# ).launch()
|
| 60 |
|
| 61 |
+
|
| 62 |
|
| 63 |
# import os
|
| 64 |
# import gradio as gr
|
|
|
|
| 70 |
# from audio_separator import Separator
|
| 71 |
|
| 72 |
# def inference(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, backing_vocals):
|
| 73 |
+
# # Initially, show the loading GIF
|
| 74 |
+
# loading_gif_path = "7RwF.gif"
|
| 75 |
+
# gr.Image(loading_gif_path,visible=True)
|
| 76 |
+
|
| 77 |
# os.makedirs("out", exist_ok=True)
|
| 78 |
# audio_path = 'test.wav'
|
| 79 |
# write(audio_path, audio[0], audio[1])
|
| 80 |
# device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
| 81 |
# print(f"Using device: {device}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
|
| 83 |
# try:
|
| 84 |
# command = f"python3 -m demucs.separate -n htdemucs_6s -d {device} {audio_path} -o out"
|
|
|
|
| 86 |
# print("Demucs script output:", process.stdout.decode())
|
| 87 |
# except subprocess.CalledProcessError as e:
|
| 88 |
# print("Error in Demucs script:", e.stderr.decode())
|
| 89 |
+
# return [gr.Audio(visible=False)] * 8 + [loading_gif_path]
|
| 90 |
|
| 91 |
# try:
|
| 92 |
+
# separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=device=='cuda', output_format='wav')
|
| 93 |
# primary_stem_path, secondary_stem_path = separator.separate()
|
| 94 |
# except Exception as e:
|
| 95 |
# print("Error in custom separation:", str(e))
|
| 96 |
+
# return [gr.Audio(visible=False)] * 8 + [loading_gif_path]
|
| 97 |
|
| 98 |
# stem_paths = {
|
| 99 |
# "vocals": "./out/htdemucs_6s/test/vocals.wav" if vocals else None,
|
|
|
|
| 106 |
# "backing_vocals": secondary_stem_path if backing_vocals else None
|
| 107 |
# }
|
| 108 |
|
| 109 |
+
# # Once processing is done, hide the GIF by returning a transparent image
|
| 110 |
+
# gr.Image(visible=False)
|
| 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"]
|
|
|
|
| 123 |
# [gr.Audio(label=label, visible=False) for label in checkbox_labels],
|
| 124 |
# title=title,
|
| 125 |
# description=description,
|
|
|
|
| 126 |
# )
|
| 127 |
|
| 128 |
# iface.launch()
|
|
|
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
+
|
| 135 |
+
|
| 136 |
import os
|
| 137 |
import gradio as gr
|
| 138 |
from scipy.io.wavfile import write
|
|
|
|
| 142 |
# Assuming audio_separator is available in your environment
|
| 143 |
from audio_separator import Separator
|
| 144 |
|
| 145 |
+
# Global variable to track the display state of the GIF
|
| 146 |
+
show_loading_gif = True
|
| 147 |
+
|
| 148 |
+
def start_loading():
|
| 149 |
+
global show_loading_gif
|
| 150 |
+
show_loading_gif = True
|
| 151 |
+
|
| 152 |
+
def stop_loading():
|
| 153 |
+
global show_loading_gif
|
| 154 |
+
show_loading_gif = False
|
| 155 |
|
| 156 |
+
def process_audio(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, backing_vocals):
|
| 157 |
+
# Audio processing logic
|
| 158 |
os.makedirs("out", exist_ok=True)
|
| 159 |
audio_path = 'test.wav'
|
| 160 |
write(audio_path, audio[0], audio[1])
|
| 161 |
device = 'cuda' if torch.cuda.is_available() else 'cpu'
|
|
|
|
| 162 |
|
| 163 |
try:
|
| 164 |
command = f"python3 -m demucs.separate -n htdemucs_6s -d {device} {audio_path} -o out"
|
| 165 |
process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
| 166 |
except subprocess.CalledProcessError as e:
|
| 167 |
+
return None # Handle the error appropriately
|
|
|
|
| 168 |
|
| 169 |
try:
|
| 170 |
separator = Separator("./out/htdemucs_6s/test/vocals.wav", model_name='UVR_MDXNET_KARA_2', use_cuda=device=='cuda', output_format='wav')
|
| 171 |
primary_stem_path, secondary_stem_path = separator.separate()
|
| 172 |
except Exception as e:
|
| 173 |
+
return None # Handle the error appropriately
|
|
|
|
| 174 |
|
| 175 |
+
# Generate paths for the stems
|
| 176 |
stem_paths = {
|
| 177 |
"vocals": "./out/htdemucs_6s/test/vocals.wav" if vocals else None,
|
| 178 |
"bass": "./out/htdemucs_6s/test/bass.wav" if bass else None,
|
|
|
|
| 184 |
"backing_vocals": secondary_stem_path if backing_vocals else None
|
| 185 |
}
|
| 186 |
|
| 187 |
+
return [stem_paths[stem] for stem in stem_paths]
|
| 188 |
+
|
| 189 |
+
def inference(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, backing_vocals):
|
| 190 |
+
global show_loading_gif
|
| 191 |
+
|
| 192 |
+
# Start loading
|
| 193 |
+
start_loading()
|
| 194 |
+
|
| 195 |
+
# Call the main processing function
|
| 196 |
+
audio_outputs = process_audio(audio, vocals, bass, drums, other, piano, guitar, lead_vocals, backing_vocals)
|
| 197 |
+
|
| 198 |
+
# Stop loading
|
| 199 |
+
stop_loading()
|
| 200 |
+
|
| 201 |
+
# Return the outputs along with the loading GIF state
|
| 202 |
+
loading_gif_path = "7RwF.gif" if show_loading_gif else ""
|
| 203 |
+
return loading_gif_path, audio_outputs
|
| 204 |
|
| 205 |
# Define checkboxes for each stem
|
| 206 |
checkbox_labels = ["Full Vocals", "Bass", "Drums", "Other", "Piano", "Guitar", "Lead Vocals", "Backing Vocals"]
|
|
|
|
| 212 |
iface = gr.Interface(
|
| 213 |
inference,
|
| 214 |
[gr.components.Audio(type="numpy", label="Input")] + checkboxes,
|
| 215 |
+
[gr.Image(), [gr.Audio(label=label, visible=False) for label in checkbox_labels]],
|
| 216 |
title=title,
|
| 217 |
description=description,
|
| 218 |
)
|
| 219 |
|
| 220 |
iface.launch()
|
| 221 |
+
|