Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -12,60 +12,60 @@ from audiocraft.data.audio_utils import convert_audio
|
|
12 |
def load_model():
|
13 |
# Load the MusicGen model here
|
14 |
|
15 |
-
def music_gen_and_separation(text, audio):
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
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 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
).launch()
|
|
|
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",
|
35 |
+
"./out/mdx_extra_q/test/bass.wav",
|
36 |
+
"./out/mdx_extra_q/test/drums.wav",
|
37 |
+
"./out/mdx_extra_q/test/other.wav"]
|
38 |
+
for file in files:
|
39 |
+
if not os.path.isfile(file):
|
40 |
+
print(f"File not found: {file}")
|
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()
|