amirgame197 commited on
Commit
ca128e7
1 Parent(s): 5383dc8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -23
app.py CHANGED
@@ -12,36 +12,25 @@ def separate_audio(audio_path, stem_count):
12
  print(f"{gradio_temp_path=}")
13
  print(f"{audio_filename=}")
14
  print(f"{stem_count=}")
15
-
16
- # Construct the spleeter command
17
- command = f"spleeter separate -p spleeter:{stem_count}stems -o {gradio_temp_path} {audio_path}"
18
  command = command.split()
19
  print(f"{command=}")
20
 
21
- # Run the spleeter command and capture the output
22
- result = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
23
- print(f"stdout: {result.stdout.decode('utf-8')}")
24
- print(f"stderr: {result.stderr.decode('utf-8')}")
25
-
26
- # Check if the command executed successfully
27
- if result.returncode != 0:
28
- print(f"Error executing command: {result.returncode}")
29
- return []
30
 
31
- # Generate a random number for unique folder naming
32
- randomnumber = str(random.randint(111111111, 999999999))
33
  paths = []
34
- # Define the output paths for the separated stems
35
  if stem_count == 2:
36
- paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/accompaniment.wav"))
37
- paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/vocals.wav"))
38
  elif stem_count == 4 or stem_count == 5:
39
- paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/vocals.wav"))
40
- paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/drums.wav"))
41
- paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/bass.wav"))
42
- paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/other.wav"))
43
  if stem_count == 5:
44
- paths.append(os.path.join(gradio_temp_path, f"separated_audio/{audio_filename}/piano.wav"))
45
 
46
  # Return the audio file paths as a list of Audio components
47
  return [gr.Audio(path) for path in paths]
@@ -50,7 +39,7 @@ def separate_audio(audio_path, stem_count):
50
  iface = gr.Interface(
51
  fn=separate_audio,
52
  inputs=[gr.Audio(type="filepath"), gr.Radio([2, 4, 5])],
53
- outputs=[gr.Audio() for _ in range(2)] # Adjust the range according to the max number of stems
54
  )
55
 
56
  # Launch the interface
 
12
  print(f"{gradio_temp_path=}")
13
  print(f"{audio_filename=}")
14
  print(f"{stem_count=}")
15
+ os.mkdir(gradio_temp_path + f"/separated_audio/{audio_filename}")
16
+ command = f"spleeter separate -p spleeter:{stem_count}stems {audio_path}"
 
17
  command = command.split()
18
  print(f"{command=}")
19
 
20
+ result = subprocess.run(command)
21
+ print(result)
 
 
 
 
 
 
 
22
 
 
 
23
  paths = []
 
24
  if stem_count == 2:
25
+ paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/accompaniment.wav")
26
+ paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/vocals.wav")
27
  elif stem_count == 4 or stem_count == 5:
28
+ paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/vocals.wav")
29
+ paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/drums.wav")
30
+ paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/bass.wav")
31
+ paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/other.wav")
32
  if stem_count == 5:
33
+ paths.append(gradio_temp_path + f"/separated_audio/{audio_filename}/piano.wav")
34
 
35
  # Return the audio file paths as a list of Audio components
36
  return [gr.Audio(path) for path in paths]
 
39
  iface = gr.Interface(
40
  fn=separate_audio,
41
  inputs=[gr.Audio(type="filepath"), gr.Radio([2, 4, 5])],
42
+ outputs=[gr.Audio(label='Accompaniment'), gr.Audio(label='Vocals'), gr.Audio(label='Drums'), gr.Audio(label='Bass'), gr.Audio(label='Other'), gr.Audio(label='Piano')]
43
  )
44
 
45
  # Launch the interface