Offex commited on
Commit
c0c025d
·
verified ·
1 Parent(s): a2abc24

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -2,30 +2,33 @@ import gradio as gr
2
  import subprocess
3
  import os
4
  import uuid
 
5
 
6
- def clean_audio(audio):
7
  uid = str(uuid.uuid4())
8
- input_path = f"/tmp/{uid}.wav"
9
- output_dir = f"/tmp/out_{uid}"
10
 
11
- os.makedirs(output_dir, exist_ok=True)
12
-
13
- # Save input
14
- with open(input_path, "wb") as f:
15
- f.write(audio)
16
 
17
  # Demucs command
18
- cmd = f"demucs -n htdemucs {input_path} -o {output_dir}"
19
- subprocess.call(cmd, shell=True)
 
 
 
 
 
20
 
21
- vocals = f"{output_dir}/htdemucs/{uid}/vocals.wav"
 
 
22
 
23
- return vocals
24
 
25
  gr.Interface(
26
  fn=clean_audio,
27
- inputs=gr.Audio(type="binary", label="Upload Audio"),
28
- outputs=gr.Audio(label="Clean Vocals"),
29
  title="AI Voice Cleaner & Vocal Remover",
30
- description="Noise remove + music separation using Demucs"
31
  ).launch()
 
2
  import subprocess
3
  import os
4
  import uuid
5
+ import shutil
6
 
7
+ def clean_audio(audio_path):
8
  uid = str(uuid.uuid4())
9
+ out_dir = f"/tmp/out_{uid}"
 
10
 
11
+ os.makedirs(out_dir, exist_ok=True)
 
 
 
 
12
 
13
  # Demucs command
14
+ cmd = [
15
+ "demucs",
16
+ "-n", "htdemucs",
17
+ audio_path,
18
+ "-o", out_dir
19
+ ]
20
+ subprocess.run(cmd, check=True)
21
 
22
+ vocals_path = os.path.join(
23
+ out_dir, "htdemucs", os.path.splitext(os.path.basename(audio_path))[0], "vocals.wav"
24
+ )
25
 
26
+ return vocals_path
27
 
28
  gr.Interface(
29
  fn=clean_audio,
30
+ inputs=gr.Audio(type="filepath", label="Upload Audio"),
31
+ outputs=gr.Audio(type="filepath", label="Clean Vocals"),
32
  title="AI Voice Cleaner & Vocal Remover",
33
+ description="Noise removal & vocal separation using Demucs (HF Spaces compatible)"
34
  ).launch()