Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,6 @@ from concurrent.futures import Future
|
|
11 |
import torch
|
12 |
import gradio as gr
|
13 |
import pydub
|
14 |
-
from scipy.io.wavfile import write
|
15 |
|
16 |
from audiocraft.data.audio_utils import convert_audio
|
17 |
from audiocraft.data.audio import audio_write
|
@@ -25,12 +24,7 @@ BATCHED_DURATION = 15
|
|
25 |
INTERRUPTING = False
|
26 |
# We have to wrap subprocess call to clean a bit the log when using gr.make_waveform
|
27 |
_old_call = sp.call
|
28 |
-
|
29 |
-
"./out/mdx_extra_q/test/vocals.wav",
|
30 |
-
"./out/mdx_extra_q/test/bass.wav",
|
31 |
-
"./out/mdx_extra_q/test/drums.wav",
|
32 |
-
"./out/mdx_extra_q/test/other.wav"
|
33 |
-
]
|
34 |
|
35 |
def _call_nostderr(*args, **kwargs):
|
36 |
# Avoid ffmpeg vomitting on the logs.
|
@@ -167,43 +161,7 @@ def predict_full(model, text, melody, duration, topk, topp, temperature, cfg_coe
|
|
167 |
outs = _do_predictions(
|
168 |
[text], [melody], duration, progress=True,
|
169 |
top_k=topk, top_p=topp, temperature=temperature, cfg_coef=cfg_coef)
|
170 |
-
|
171 |
-
return inference(outs[0])
|
172 |
-
|
173 |
-
def inference(audio):
|
174 |
-
print (audio)
|
175 |
-
os.makedirs("out", exist_ok=True)
|
176 |
-
command = "python3 -m demucs.separate -n mdx_extra_q -d cpu test.wav -o out"
|
177 |
-
|
178 |
-
|
179 |
-
# Find the index of "test.wav" in the command
|
180 |
-
index = command.find("test.wav")
|
181 |
-
|
182 |
-
# Replace "test.wav" with the file path
|
183 |
-
new_command = command[:index] + audio + command[index + len("test.wav"):]
|
184 |
-
|
185 |
-
process = sp.run(new_command, shell=True, stdout=sp.PIPE, stderr=sp.PIPE)
|
186 |
-
print("Demucs script output:", process.stdout.decode())
|
187 |
-
|
188 |
-
os.makedirs("out", exist_ok=True)
|
189 |
-
result = os.system(new_command)
|
190 |
-
print(f"Demucs script result: {result}")
|
191 |
-
directory_name = os.path.splitext(os.path.basename(audio))[0]
|
192 |
-
|
193 |
-
files = [audio,
|
194 |
-
f"./out/mdx_extra_q/{directory_name}/vocals.wav",
|
195 |
-
f"./out/mdx_extra_q/{directory_name}/bass.wav",
|
196 |
-
f"./out/mdx_extra_q/{directory_name}/drums.wav",
|
197 |
-
f"./out/mdx_extra_q/{directory_name}/other.wav"
|
198 |
-
]
|
199 |
-
|
200 |
-
for file in files:
|
201 |
-
if not os.path.isfile(file):
|
202 |
-
print(f"File not found: {file}")
|
203 |
-
else:
|
204 |
-
print(f"File exists: {file}")
|
205 |
-
|
206 |
-
return files
|
207 |
|
208 |
|
209 |
def toggle_audio_src(choice):
|
@@ -246,13 +204,10 @@ def ui_full(launch_kwargs):
|
|
246 |
temperature = gr.Number(label="Temperature", value=1.0, interactive=True)
|
247 |
cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)
|
248 |
with gr.Column():
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
gr.Audio(type='filepath',label="base Music"),
|
254 |
-
gr.Audio(type='filepath',label="drum Music"),
|
255 |
-
gr.Audio(type='filepath',label="other Music")])
|
256 |
radio.change(toggle_audio_src, radio, [melody], queue=False, show_progress=False)
|
257 |
gr.Examples(
|
258 |
fn=predict_full,
|
@@ -284,11 +239,7 @@ def ui_full(launch_kwargs):
|
|
284 |
],
|
285 |
],
|
286 |
inputs=[text, melody, model],
|
287 |
-
outputs=[
|
288 |
-
gr.Audio(type='filepath',label="Vocal Music"),
|
289 |
-
gr.Audio(type='filepath',label="base Music"),
|
290 |
-
gr.Audio(type='filepath',label="drum Music"),
|
291 |
-
gr.Audio(type='filepath',label="other Music")]
|
292 |
)
|
293 |
gr.Markdown(
|
294 |
"""
|
@@ -347,14 +298,7 @@ def ui_batched(launch_kwargs):
|
|
347 |
with gr.Row():
|
348 |
submit = gr.Button("Generate")
|
349 |
with gr.Column():
|
350 |
-
|
351 |
-
gr.Audio(type='filepath',label="Generated Music"),
|
352 |
-
gr.Audio(type='filepath',label="Vocal Music"),
|
353 |
-
gr.Audio(type='filepath',label="base Music"),
|
354 |
-
gr.Audio(type='filepath',label="drum Music"),
|
355 |
-
gr.Audio(type='filepath',label="other Music")
|
356 |
-
#gr.outputs.Audio(type='filepath')
|
357 |
-
],
|
358 |
submit.click(predict_batched, inputs=[text, melody],
|
359 |
outputs=[output], batch=True, max_batch_size=MAX_BATCH_SIZE)
|
360 |
radio.change(toggle_audio_src, radio, [melody], queue=False, show_progress=False)
|
@@ -440,5 +384,8 @@ if __name__ == "__main__":
|
|
440 |
if args.share:
|
441 |
launch_kwargs['share'] = args.share
|
442 |
|
443 |
-
|
|
|
|
|
|
|
444 |
ui_full(launch_kwargs)
|
|
|
11 |
import torch
|
12 |
import gradio as gr
|
13 |
import pydub
|
|
|
14 |
|
15 |
from audiocraft.data.audio_utils import convert_audio
|
16 |
from audiocraft.data.audio import audio_write
|
|
|
24 |
INTERRUPTING = False
|
25 |
# We have to wrap subprocess call to clean a bit the log when using gr.make_waveform
|
26 |
_old_call = sp.call
|
27 |
+
|
|
|
|
|
|
|
|
|
|
|
28 |
|
29 |
def _call_nostderr(*args, **kwargs):
|
30 |
# Avoid ffmpeg vomitting on the logs.
|
|
|
161 |
outs = _do_predictions(
|
162 |
[text], [melody], duration, progress=True,
|
163 |
top_k=topk, top_p=topp, temperature=temperature, cfg_coef=cfg_coef)
|
164 |
+
return outs[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
|
167 |
def toggle_audio_src(choice):
|
|
|
204 |
temperature = gr.Number(label="Temperature", value=1.0, interactive=True)
|
205 |
cfg_coef = gr.Number(label="Classifier Free Guidance", value=3.0, interactive=True)
|
206 |
with gr.Column():
|
207 |
+
output = gr.Audio(label="Generated Music")
|
208 |
+
submit.click(predict_full,
|
209 |
+
inputs=[model, text, melody, duration, topk, topp, temperature, cfg_coef],
|
210 |
+
outputs=[output])
|
|
|
|
|
|
|
211 |
radio.change(toggle_audio_src, radio, [melody], queue=False, show_progress=False)
|
212 |
gr.Examples(
|
213 |
fn=predict_full,
|
|
|
239 |
],
|
240 |
],
|
241 |
inputs=[text, melody, model],
|
242 |
+
outputs=[output]
|
|
|
|
|
|
|
|
|
243 |
)
|
244 |
gr.Markdown(
|
245 |
"""
|
|
|
298 |
with gr.Row():
|
299 |
submit = gr.Button("Generate")
|
300 |
with gr.Column():
|
301 |
+
output = gr.Audio(label="Generated Music")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
302 |
submit.click(predict_batched, inputs=[text, melody],
|
303 |
outputs=[output], batch=True, max_batch_size=MAX_BATCH_SIZE)
|
304 |
radio.change(toggle_audio_src, radio, [melody], queue=False, show_progress=False)
|
|
|
384 |
if args.share:
|
385 |
launch_kwargs['share'] = args.share
|
386 |
|
387 |
+
# Show the interface
|
388 |
+
if IS_BATCHED:
|
389 |
+
ui_batched(launch_kwargs)
|
390 |
+
else:
|
391 |
ui_full(launch_kwargs)
|