Spaces:
Running
Running
File size: 2,436 Bytes
66497d4 921741c 780b186 921741c 387d68b 921741c 387d68b 0dcd08a 921741c 66497d4 921741c 66497d4 a92b621 921741c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
import os
import gradio as gr
from scipy.io.wavfile import write
import subprocess
import torch
import typing as tp
from audiocraft.data.audio_utils import convert_audio
# Import the necessary MusicGen code here
def load_model():
# Load the MusicGen model here
def music_gen_and_separation(text, audio):
# Perform music generation with the loaded MusicGen model
texts = [text] # Use the provided text for music generation
melodies = [(audio[1], audio[0])] # Convert audio to melody format for MusicGen
# Perform music generation using the loaded MusicGen model
generated_music = predict_full(model, texts, melodies, duration, topk, topp, temperature, cfg_coef)
# Perform source separation using Demucs
# Save the generated music to a temporary file
temp_file = "generated_music.wav"
write(temp_file, generated_music, 32000)
# Run Demucs for source separation
command = "python3 -m demucs.separate -n mdx_extra_q -d cpu " + temp_file + " -o out"
process = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
print("Demucs script output:", process.stdout.decode())
# Check if files exist before returning
files = ["./out/mdx_extra_q/test/vocals.wav",
"./out/mdx_extra_q/test/bass.wav",
"./out/mdx_extra_q/test/drums.wav",
"./out/mdx_extra_q/test/other.wav"]
for file in files:
if not os.path.isfile(file):
print(f"File not found: {file}")
else:
print(f"File exists: {file}")
# Convert the separated audio files to numpy arrays
separated_audio = []
for file in files:
_, audio = read(file)
separated_audio.append(audio)
return separated_audio
title = "MusicGen with Demucs"
description = "Combine MusicGen with Demucs for music generation and source separation."
article = "<p>Article content goes here.</p>"
input_text = gr.inputs.Textbox(label="Input Text")
input_audio = gr.inputs.Audio(label="Input Audio")
output_vocals = gr.outputs.Audio(label="Vocals")
output_bass = gr.outputs.Audio(label="Bass")
output_drums = gr.outputs.Audio(label="Drums")
output_other = gr.outputs.Audio(label="Other")
gr.Interface(
music_gen_and_separation,
[input_text, input_audio],
[output_vocals, output_bass, output_drums, output_other],
title=title,
description=description,
article=article
).launch() |