Update app.py
Browse files
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(
|
| 7 |
uid = str(uuid.uuid4())
|
| 8 |
-
|
| 9 |
-
output_dir = f"/tmp/out_{uid}"
|
| 10 |
|
| 11 |
-
os.makedirs(
|
| 12 |
-
|
| 13 |
-
# Save input
|
| 14 |
-
with open(input_path, "wb") as f:
|
| 15 |
-
f.write(audio)
|
| 16 |
|
| 17 |
# Demucs command
|
| 18 |
-
cmd =
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
return
|
| 24 |
|
| 25 |
gr.Interface(
|
| 26 |
fn=clean_audio,
|
| 27 |
-
inputs=gr.Audio(type="
|
| 28 |
-
outputs=gr.Audio(label="Clean Vocals"),
|
| 29 |
title="AI Voice Cleaner & Vocal Remover",
|
| 30 |
-
description="Noise
|
| 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()
|