amirgame197 commited on
Commit
fb25e22
·
verified ·
1 Parent(s): 2dd34c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -21
app.py CHANGED
@@ -13,38 +13,31 @@ def separate_audio(audio_path, stem_count):
13
  print(f"{audio_filename=}")
14
  print(f"{stem_count=}")
15
 
16
- # Ensure the output directory exists
17
- randomnumber = str(random.randint(111111111, 999999999))
18
- output_folder = f"{gradio_temp_path}/separated_audio/{randomnumber}"
19
- os.makedirs(output_folder, exist_ok=True)
20
-
21
- command = f"spleeter separate -p spleeter:{stem_count}stems -o {output_folder} {audio_path}"
22
  command = command.split()
23
  print(f"{command=}")
24
 
25
- result = subprocess.run(command, capture_output=True)
26
  print(result)
27
- if result.returncode != 0:
28
- print(f"Error: {result.stderr.decode('utf-8')}")
29
- return []
30
-
31
- # Check if the separated files exist and return their paths
32
  paths = []
33
- stems = ['vocals', 'drums', 'bass', 'other', 'piano']
34
- for stem in stems[:stem_count]:
35
- stem_path = os.path.join(output_folder, stem, f"{audio_filename}_{stem}.wav")
36
- print(f"Checking {stem_path}")
37
- if os.path.exists(stem_path):
38
- paths.append(gr.Audio(file=stem_path, label=stem.capitalize()))
39
- else:
40
- print(f"File not found: {stem_path}")
 
 
41
 
42
  return paths
43
 
44
  iface = gr.Interface(
45
  fn=separate_audio,
46
  inputs=[gr.Audio(type="filepath"), gr.Radio([2, 4, 5])],
47
- 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")]
48
  )
49
 
50
  iface.launch()
 
13
  print(f"{audio_filename=}")
14
  print(f"{stem_count=}")
15
 
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
+ randomnumber = str(random.randint(111111111, 999999999))
 
 
 
 
23
  paths = []
24
+ if stem_count == 2:
25
+ paths.append(('Accompaniment', f"{gradio_temp_path}/separated_audio/{randomnumber}/accompaniment.wav"))
26
+ paths.append(('Vocals', f"{gradio_temp_path}/separated_audio/{randomnumber}/vocals.wav"))
27
+ elif stem_count == 4 or stem_count == 5:
28
+ paths.append(('Vocals', f"{gradio_temp_path}/separated_audio/{randomnumber}/vocals.wav"))
29
+ paths.append(('Drums', f"{gradio_temp_path}/separated_audio/{randomnumber}/drums.wav"))
30
+ paths.append(('Bass', f"{gradio_temp_path}/separated_audio/{randomnumber}/bass.wav"))
31
+ paths.append(('Other', f"{gradio_temp_path}/separated_audio/{randomnumber}/other.wav"))
32
+ if stem_count == 5:
33
+ paths.append(('Piano', f"{gradio_temp_path}/separated_audio/{randomnumber}/piano.wav"))
34
 
35
  return paths
36
 
37
  iface = gr.Interface(
38
  fn=separate_audio,
39
  inputs=[gr.Audio(type="filepath"), gr.Radio([2, 4, 5])],
40
+ outputs="text",
41
  )
42
 
43
  iface.launch()