|
|
import librosa |
|
|
import gradio as gr |
|
|
import subprocess |
|
|
import os |
|
|
import uuid |
|
|
|
|
|
MAX_DURATION = 60 |
|
|
|
|
|
def clean_audio(audio_path): |
|
|
duration = librosa.get_duration(path=audio_path) |
|
|
if duration > MAX_DURATION: |
|
|
raise gr.Error("❌ Audio too long. Max 60 seconds allowed.") |
|
|
|
|
|
uid = str(uuid.uuid4()) |
|
|
out_dir = f"/tmp/out_{uid}" |
|
|
os.makedirs(out_dir, exist_ok=True) |
|
|
|
|
|
cmd = [ |
|
|
"python", "-m", "demucs", |
|
|
"-n", "htdemucs", |
|
|
audio_path, |
|
|
"-o", out_dir |
|
|
] |
|
|
subprocess.run(cmd, check=True) |
|
|
|
|
|
model_dir = os.path.join(out_dir, "htdemucs") |
|
|
song_dir = os.listdir(model_dir)[0] |
|
|
vocals_path = os.path.join(model_dir, song_dir, "vocals.wav") |
|
|
|
|
|
return vocals_path |
|
|
|
|
|
gr.Interface( |
|
|
fn=clean_audio, |
|
|
inputs=gr.Audio(type="filepath", label="Upload Audio"), |
|
|
outputs=gr.Audio(type="filepath", label="Clean Vocals"), |
|
|
title="AI Voice Cleaner & Vocal Remover", |
|
|
description="Demucs-based vocal separation (HF Spaces compatible)" |
|
|
).launch() |