Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,34 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from scipy.io.wavfile import write
|
4 |
-
import subprocess
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
os.makedirs("out", exist_ok=True)
|
8 |
-
write('test.wav', audio[0], audio[1])
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
12 |
print("Demucs script output:", process.stdout.decode())
|
13 |
-
|
14 |
-
os.makedirs("out", exist_ok=True)
|
15 |
-
write('test.wav', audio[0], audio[1])
|
16 |
-
result = os.system("python3 -m demucs.separate -n mdx_extra_q -d cpu test.wav -o out")
|
17 |
-
print(f"Demucs script result: {result}")
|
18 |
|
19 |
# Check if files exist before returning
|
20 |
files = ["./out/mdx_extra_q/test/vocals.wav",
|
@@ -27,21 +41,31 @@ def inference(audio):
|
|
27 |
else:
|
28 |
print(f"File exists: {file}")
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
|
36 |
-
examples=[['test.mp3']]
|
37 |
gr.Interface(
|
38 |
-
|
39 |
-
|
40 |
-
[
|
41 |
-
gr.components.Audio(type="filepath", label="Bass"),
|
42 |
-
gr.components.Audio(type="filepath", label="Drums"),
|
43 |
-
gr.components.Audio(type="filepath", label="Other")],
|
44 |
title=title,
|
45 |
description=description,
|
46 |
article=article
|
47 |
-
).launch(
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
from scipy.io.wavfile import write
|
4 |
+
import subprocess
|
5 |
+
import torch
|
6 |
+
import typing as tp
|
7 |
|
8 |
+
from audiocraft.data.audio_utils import convert_audio
|
|
|
|
|
9 |
|
10 |
+
# Import the necessary MusicGen code here
|
11 |
+
|
12 |
+
def load_model():
|
13 |
+
# Load the MusicGen model here
|
14 |
+
|
15 |
+
def music_gen_and_separation(text, audio):
|
16 |
+
# Perform music generation with the loaded MusicGen model
|
17 |
+
texts = [text] # Use the provided text for music generation
|
18 |
+
melodies = [(audio[1], audio[0])] # Convert audio to melody format for MusicGen
|
19 |
+
|
20 |
+
# Perform music generation using the loaded MusicGen model
|
21 |
+
generated_music = predict_full(model, texts, melodies, duration, topk, topp, temperature, cfg_coef)
|
22 |
+
|
23 |
+
# Perform source separation using Demucs
|
24 |
+
# Save the generated music to a temporary file
|
25 |
+
temp_file = "generated_music.wav"
|
26 |
+
write(temp_file, generated_music, 32000)
|
27 |
+
|
28 |
+
# Run Demucs for source separation
|
29 |
+
command = "python3 -m demucs.separate -n mdx_extra_q -d cpu " + temp_file + " -o out"
|
30 |
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
31 |
print("Demucs script output:", process.stdout.decode())
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
# Check if files exist before returning
|
34 |
files = ["./out/mdx_extra_q/test/vocals.wav",
|
|
|
41 |
else:
|
42 |
print(f"File exists: {file}")
|
43 |
|
44 |
+
# Convert the separated audio files to numpy arrays
|
45 |
+
separated_audio = []
|
46 |
+
for file in files:
|
47 |
+
_, audio = read(file)
|
48 |
+
separated_audio.append(audio)
|
49 |
+
|
50 |
+
return separated_audio
|
51 |
+
|
52 |
+
|
53 |
+
title = "MusicGen with Demucs"
|
54 |
+
description = "Combine MusicGen with Demucs for music generation and source separation."
|
55 |
+
article = "<p>Article content goes here.</p>"
|
56 |
+
|
57 |
+
input_text = gr.inputs.Textbox(label="Input Text")
|
58 |
+
input_audio = gr.inputs.Audio(label="Input Audio")
|
59 |
+
output_vocals = gr.outputs.Audio(label="Vocals")
|
60 |
+
output_bass = gr.outputs.Audio(label="Bass")
|
61 |
+
output_drums = gr.outputs.Audio(label="Drums")
|
62 |
+
output_other = gr.outputs.Audio(label="Other")
|
63 |
|
|
|
64 |
gr.Interface(
|
65 |
+
music_gen_and_separation,
|
66 |
+
[input_text, input_audio],
|
67 |
+
[output_vocals, output_bass, output_drums, output_other],
|
|
|
|
|
|
|
68 |
title=title,
|
69 |
description=description,
|
70 |
article=article
|
71 |
+
).launch()
|