owiedotch commited on
Commit
37de889
1 Parent(s): c3c9d62

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -9
app.py CHANGED
@@ -9,6 +9,14 @@ import subprocess
9
  # Check if CUDA is available
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
 
 
 
 
 
 
 
 
 
12
  # Define the inference function
13
  @spaces.GPU
14
  def inference(audio_file, model_name, vocals, drums, bass, other, mp3, mp3_bitrate):
@@ -57,12 +65,9 @@ def inference(audio_file, model_name, vocals, drums, bass, other, mp3, mp3_bitra
57
  # If only one stem is selected, just copy it
58
  os.rename(selected_stems[0], output_file)
59
  else:
60
- # Otherwise, use ffmpeg to mix the stems
61
- ffmpeg_cmd = ["ffmpeg", "-y"]
62
- for stem in selected_stems:
63
- ffmpeg_cmd.extend(["-i", f"\"{stem}\""]) # Quote file paths
64
- ffmpeg_cmd.extend(["-filter_complex", f"amix=inputs={len(selected_stems)}:duration=longest", f"\"{output_file}\""]) # Quote file paths
65
- subprocess.run(ffmpeg_cmd, check=True)
66
 
67
  return output_file
68
 
@@ -71,13 +76,13 @@ iface = gr.Interface(
71
  fn=inference,
72
  inputs=[
73
  gr.Audio(type="filepath"),
74
- gr.Dropdown(["htdemucs", "htdemucs_ft", "htdemucs_6s", "hdemucs_mmi", "mdx", "mdx_extra", "mdx_q", "mdx_extra_q"], label="Model Name"),
75
  gr.Checkbox(label="Vocals", value=True),
76
  gr.Checkbox(label="Drums", value=True),
77
  gr.Checkbox(label="Bass", value=True),
78
  gr.Checkbox(label="Other", value=True),
79
- gr.Checkbox(label="Save as MP3"),
80
- gr.Slider(128, 320, step=32, label="MP3 Bitrate", visible=False),
81
  ],
82
  outputs=gr.Audio(type="filepath"),
83
  title="Demucs Music Source Separation and Mixing",
 
9
  # Check if CUDA is available
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
11
 
12
+ # Check if sox is installed and install it if necessary
13
+ try:
14
+ subprocess.run(["sox", "--version"], check=True, capture_output=True)
15
+ except FileNotFoundError:
16
+ print("sox is not installed. Installing it now...")
17
+ subprocess.run(["apt-get", "install", "-y", "sox"], check=True)
18
+ print("sox has been installed.")
19
+
20
  # Define the inference function
21
  @spaces.GPU
22
  def inference(audio_file, model_name, vocals, drums, bass, other, mp3, mp3_bitrate):
 
65
  # If only one stem is selected, just copy it
66
  os.rename(selected_stems[0], output_file)
67
  else:
68
+ # Otherwise, use sox to mix the stems
69
+ sox_cmd = ["sox", "-m"] + selected_stems + [output_file]
70
+ subprocess.run(sox_cmd, check=True)
 
 
 
71
 
72
  return output_file
73
 
 
76
  fn=inference,
77
  inputs=[
78
  gr.Audio(type="filepath"),
79
+ gr.Dropdown(["htdemucs", "htdemucs_ft", "htdemucs_6s", "hdemucs_mmi", "mdx", "mdx_extra", "mdx_q", "mdx_extra_q"], label="Model Name", value="htdemucs_ft"), # Set default value
80
  gr.Checkbox(label="Vocals", value=True),
81
  gr.Checkbox(label="Drums", value=True),
82
  gr.Checkbox(label="Bass", value=True),
83
  gr.Checkbox(label="Other", value=True),
84
+ gr.Checkbox(label="Save as MP3", value=False), # Set default value to False
85
+ gr.Slider(128, 320, step=32, label="MP3 Bitrate", visible=True), # Set visible to True
86
  ],
87
  outputs=gr.Audio(type="filepath"),
88
  title="Demucs Music Source Separation and Mixing",