Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,108 +1,103 @@
|
|
| 1 |
# app.py
|
| 2 |
-
#
|
| 3 |
-
#
|
| 4 |
-
#
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
import subprocess
|
| 8 |
import os
|
| 9 |
import shutil
|
| 10 |
import uuid
|
| 11 |
-
import traceback
|
| 12 |
from pathlib import Path
|
| 13 |
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
|
| 18 |
-
os.makedirs(
|
| 19 |
-
os.makedirs(
|
| 20 |
|
| 21 |
|
| 22 |
def run(cmd):
|
| 23 |
-
|
| 24 |
-
res = subprocess.run(cmd, check=True, capture_output=True, text=True)
|
| 25 |
-
return 0, res.stdout + res.stderr
|
| 26 |
-
except subprocess.CalledProcessError as e:
|
| 27 |
-
return e.returncode, (e.stdout or "") + (e.stderr or "")
|
| 28 |
|
| 29 |
|
| 30 |
def separate(file):
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
out
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
out
|
| 71 |
-
])
|
| 72 |
-
|
| 73 |
-
return out, "Success β
"
|
| 74 |
-
|
| 75 |
-
except Exception:
|
| 76 |
-
return None, traceback.format_exc()
|
| 77 |
|
| 78 |
|
| 79 |
with gr.Blocks() as demo:
|
| 80 |
gr.Markdown("""
|
| 81 |
-
# π§ AI Vocal Remover (STABLE
|
| 82 |
|
| 83 |
β MP3 / WAV / FLAC / MP4
|
| 84 |
-
β
|
| 85 |
-
β
|
| 86 |
-
β
|
| 87 |
""")
|
| 88 |
|
| 89 |
-
inp = gr.File(
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
| 92 |
|
| 93 |
btn = gr.Button("Remove Vocals π₯")
|
| 94 |
-
btn.click(fn=separate, inputs=inp, outputs=
|
| 95 |
|
| 96 |
if __name__ == "__main__":
|
| 97 |
demo.launch()
|
| 98 |
|
| 99 |
|
| 100 |
-
#
|
|
|
|
|
|
|
| 101 |
# gradio==4.44.0
|
| 102 |
# demucs==4.0.1
|
| 103 |
-
# torch
|
| 104 |
-
# torchaudio
|
|
|
|
| 105 |
# soundfile
|
| 106 |
|
|
|
|
| 107 |
# apt.txt
|
|
|
|
| 108 |
# ffmpeg
|
|
|
|
| 1 |
# app.py
|
| 2 |
+
# 𧨠SCRAPPED & REBUILT β SIMPLE, SOLID HuggingFace Vocal Remover
|
| 3 |
+
# Fix: install torchcodec instead of fighting torchaudio
|
| 4 |
+
# This is the MINIMAL setup that actually works
|
| 5 |
|
| 6 |
import gradio as gr
|
| 7 |
import subprocess
|
| 8 |
import os
|
| 9 |
import shutil
|
| 10 |
import uuid
|
|
|
|
| 11 |
from pathlib import Path
|
| 12 |
|
| 13 |
+
MODEL = "htdemucs"
|
| 14 |
+
WORK = "work"
|
| 15 |
+
OUT = "outputs"
|
| 16 |
|
| 17 |
+
os.makedirs(WORK, exist_ok=True)
|
| 18 |
+
os.makedirs(OUT, exist_ok=True)
|
| 19 |
|
| 20 |
|
| 21 |
def run(cmd):
|
| 22 |
+
subprocess.run(cmd, check=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
|
| 25 |
def separate(file):
|
| 26 |
+
if file is None:
|
| 27 |
+
return None
|
| 28 |
+
|
| 29 |
+
input_path = file if isinstance(file, str) else file.name
|
| 30 |
+
uid = str(uuid.uuid4())[:8]
|
| 31 |
+
wav = f"{WORK}/{uid}.wav"
|
| 32 |
+
|
| 33 |
+
# 1οΈβ£ Convert anything β WAV
|
| 34 |
+
run([
|
| 35 |
+
"ffmpeg", "-y", "-i", input_path,
|
| 36 |
+
"-ac", "2", "-ar", "44100", wav
|
| 37 |
+
])
|
| 38 |
+
|
| 39 |
+
shutil.rmtree("separated", ignore_errors=True)
|
| 40 |
+
|
| 41 |
+
# 2οΈβ£ Demucs (two-stems so we get no_vocals.wav)
|
| 42 |
+
run([
|
| 43 |
+
"demucs",
|
| 44 |
+
"-n", MODEL,
|
| 45 |
+
"--two-stems", "vocals",
|
| 46 |
+
wav
|
| 47 |
+
])
|
| 48 |
+
|
| 49 |
+
base = Path(wav).stem
|
| 50 |
+
inst = f"separated/{MODEL}/{base}/no_vocals.wav"
|
| 51 |
+
|
| 52 |
+
if not Path(inst).exists():
|
| 53 |
+
raise RuntimeError("no_vocals.wav not produced")
|
| 54 |
+
|
| 55 |
+
out = f"{OUT}/{base}_instrumental.wav"
|
| 56 |
+
|
| 57 |
+
# 3οΈβ£ Loud normalize
|
| 58 |
+
run([
|
| 59 |
+
"ffmpeg", "-y", "-i", inst,
|
| 60 |
+
"-af", "loudnorm=I=-14:LRA=11:TP=-1",
|
| 61 |
+
out
|
| 62 |
+
])
|
| 63 |
+
|
| 64 |
+
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
|
| 67 |
with gr.Blocks() as demo:
|
| 68 |
gr.Markdown("""
|
| 69 |
+
# π§ AI Vocal Remover (STABLE)
|
| 70 |
|
| 71 |
β MP3 / WAV / FLAC / MP4
|
| 72 |
+
β Uses Demucs (htdemucs)
|
| 73 |
+
β Clean, loud instrumentals
|
| 74 |
+
β No crashes
|
| 75 |
""")
|
| 76 |
|
| 77 |
+
inp = gr.File(
|
| 78 |
+
file_types=[".wav", ".mp3", ".flac", ".ogg", ".mp4"],
|
| 79 |
+
label="Upload audio or video"
|
| 80 |
+
)
|
| 81 |
+
out = gr.Audio(type="filepath", label="Instrumental (No Vocals)")
|
| 82 |
|
| 83 |
btn = gr.Button("Remove Vocals π₯")
|
| 84 |
+
btn.click(fn=separate, inputs=inp, outputs=out)
|
| 85 |
|
| 86 |
if __name__ == "__main__":
|
| 87 |
demo.launch()
|
| 88 |
|
| 89 |
|
| 90 |
+
# =============================
|
| 91 |
+
# requirements.txt (FINAL)
|
| 92 |
+
# =============================
|
| 93 |
# gradio==4.44.0
|
| 94 |
# demucs==4.0.1
|
| 95 |
+
# torch
|
| 96 |
+
# torchaudio
|
| 97 |
+
# torchcodec
|
| 98 |
# soundfile
|
| 99 |
|
| 100 |
+
# =============================
|
| 101 |
# apt.txt
|
| 102 |
+
# =============================
|
| 103 |
# ffmpeg
|