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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -13,9 +13,16 @@ device = "cuda" if torch.cuda.is_available() else "cpu"
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
@@ -69,6 +76,13 @@ def inference(audio_file, model_name, vocals, drums, bass, other, mp3, mp3_bitra
69
  sox_cmd = ["sox", "-m"] + selected_stems + [output_file]
70
  subprocess.run(sox_cmd, check=True)
71
 
 
 
 
 
 
 
 
72
  return output_file
73
 
74
  # Define the Gradio interface
 
13
  try:
14
  subprocess.run(["sox", "--version"], check=True, capture_output=True)
15
  except FileNotFoundError:
16
+ print("sox is not installed. Trying to install it now...")
17
+ try:
18
+ subprocess.run(["apt-get", "update"], check=True)
19
+ subprocess.run(["apt-get", "install", "-y", "sox"], check=True)
20
+ print("sox has been installed.")
21
+ except subprocess.CalledProcessError as e:
22
+ print(f"Error installing sox: {e}")
23
+ print("Please install sox manually or try adding the following repository to your sources list:")
24
+ print("deb http://deb.debian.org/debian stretch main contrib non-free")
25
+ exit(1)
26
 
27
  # Define the inference function
28
  @spaces.GPU
 
76
  sox_cmd = ["sox", "-m"] + selected_stems + [output_file]
77
  subprocess.run(sox_cmd, check=True)
78
 
79
+ # Automatically convert to MP3 if requested
80
+ if mp3:
81
+ mp3_output_file = os.path.splitext(output_file)[0] + ".mp3"
82
+ ffmpeg_cmd = ["ffmpeg", "-y", "-i", output_file, "-ab", str(mp3_bitrate) + "k", mp3_output_file]
83
+ subprocess.run(ffmpeg_cmd, check=True)
84
+ output_file = mp3_output_file # Update output_file to the MP3 file
85
+
86
  return output_file
87
 
88
  # Define the Gradio interface