nakas commited on
Commit
d924a6d
1 Parent(s): 921741c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -47
app.py CHANGED
@@ -1,34 +1,20 @@
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,31 +27,21 @@ def music_gen_and_separation(text, audio):
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()
 
1
  import os
2
  import gradio as gr
3
  from scipy.io.wavfile import write
4
+ import subprocess
 
 
5
 
6
+ def inference(audio):
7
+ os.makedirs("out", exist_ok=True)
8
+ write('test.wav', audio[0], audio[1])
9
 
10
+ command = "python3 -m demucs.separate -n mdx_extra_q -d cpu test.wav -o out"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  else:
28
  print(f"File exists: {file}")
29
 
30
+ return files
31
+
32
+ title = "Demucs"
33
+ description = "Forked from here https://huggingface.co/spaces/akhaliq/demucs/ and changed to updated demucs pip source. Gradio demo for Demucs: Music Source Separation in the Waveform Domain. To use it, simply upload your audio, or click one of the examples to load them. Read more at the links below."
34
+ article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1911.13254' target='_blank'>Music Source Separation in the Waveform Domain</a> | <a href='https://github.com/facebookresearch/demucs' target='_blank'>Github Repo</a></p>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ examples=[['test.mp3']]
37
  gr.Interface(
38
+ inference,
39
+ gr.components.Audio(type="numpy", label="Input"),
40
+ [gr.components.Audio(type="filepath", label="Vocals"),
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(enable_queue=True)