Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,7 +9,7 @@ import sys
|
|
| 9 |
from huggingface_hub import hf_hub_download
|
| 10 |
|
| 11 |
# ==========================================
|
| 12 |
-
# 1.
|
| 13 |
# ==========================================
|
| 14 |
try:
|
| 15 |
from bs_roformer import BSRoformer
|
|
@@ -28,7 +28,7 @@ except NameError:
|
|
| 28 |
pass
|
| 29 |
|
| 30 |
def load_model():
|
| 31 |
-
print(">>> 📡
|
| 32 |
try:
|
| 33 |
checkpoint_path = hf_hub_download(
|
| 34 |
repo_id="Tachyeon/IAM-RoFormer-Model-Weights",
|
|
@@ -60,7 +60,7 @@ def separate_audio(audio_path):
|
|
| 60 |
mix, sr = librosa.load(audio_path, sr=44100, mono=False)
|
| 61 |
if len(mix.shape) == 1: mix = np.stack([mix, mix], axis=0)
|
| 62 |
|
| 63 |
-
#
|
| 64 |
chunk_size = 44100 * 10
|
| 65 |
overlap = 44100 * 1
|
| 66 |
|
|
@@ -71,7 +71,6 @@ def separate_audio(audio_path):
|
|
| 71 |
final_output = torch.zeros(1, 4, 2, length).to(DEVICE)
|
| 72 |
counts = torch.zeros(1, 4, 2, length).to(DEVICE)
|
| 73 |
|
| 74 |
-
# Process
|
| 75 |
with torch.no_grad():
|
| 76 |
context = torch.amp.autocast('cuda') if torch.cuda.is_available() else torch.no_grad()
|
| 77 |
with context:
|
|
@@ -89,7 +88,7 @@ def separate_audio(audio_path):
|
|
| 89 |
|
| 90 |
stems = (final_output / torch.clamp(counts, min=1.0)).cpu().numpy()[0]
|
| 91 |
|
| 92 |
-
#
|
| 93 |
outputs = []
|
| 94 |
for i in range(4):
|
| 95 |
outfile = f"stem_{i}.wav"
|
|
@@ -99,156 +98,159 @@ def separate_audio(audio_path):
|
|
| 99 |
return outputs
|
| 100 |
|
| 101 |
# ==========================================
|
| 102 |
-
# 2.
|
| 103 |
# ==========================================
|
| 104 |
css = """
|
| 105 |
-
@import url('https://fonts.googleapis.com/css2?family=
|
| 106 |
|
| 107 |
:root {
|
| 108 |
-
--bg-
|
| 109 |
-
--
|
| 110 |
-
--border-
|
| 111 |
-
--
|
| 112 |
-
--
|
|
|
|
|
|
|
| 113 |
}
|
| 114 |
|
| 115 |
body, .gradio-container {
|
| 116 |
-
background-color: var(--bg-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
margin: 0; padding: 0;
|
| 120 |
-
height: 100vh; overflow: hidden;
|
| 121 |
}
|
| 122 |
|
| 123 |
-
/*
|
| 124 |
-
.
|
| 125 |
-
padding:
|
| 126 |
-
|
| 127 |
-
margin
|
| 128 |
-
display: flex;
|
| 129 |
-
align-items: center;
|
| 130 |
-
justify-content: space-between;
|
| 131 |
}
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
-
|
| 138 |
-
-webkit-text-fill-color: transparent;
|
| 139 |
-
text-shadow: 0px 5px 15px rgba(99, 102, 241, 0.3);
|
| 140 |
}
|
| 141 |
-
.
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
font-
|
| 146 |
-
|
| 147 |
-
color:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
}
|
| 149 |
|
| 150 |
-
/* PANELS */
|
| 151 |
-
.
|
| 152 |
-
background: var(--
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
padding: 30px;
|
| 157 |
-
height: 100%;
|
| 158 |
-
display: flex;
|
| 159 |
-
flex-direction: column;
|
| 160 |
-
box-shadow: 0 20px 40px rgba(0,0,0,0.4);
|
| 161 |
}
|
| 162 |
|
| 163 |
-
.
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
| 167 |
text-transform: uppercase;
|
| 168 |
-
letter-spacing:
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
gap: 10px;
|
| 173 |
}
|
| 174 |
|
| 175 |
-
/* BUTTON */
|
| 176 |
-
|
| 177 |
-
background: var(--
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
font-size: 1.1rem !important;
|
| 181 |
font-weight: 800 !important;
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
}
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
}
|
| 193 |
|
| 194 |
/* AUDIO PLAYERS */
|
| 195 |
.audio-player {
|
| 196 |
-
border: 1px solid var(--border-light) !important;
|
| 197 |
background: transparent !important;
|
| 198 |
-
border
|
|
|
|
| 199 |
margin-bottom: 15px !important;
|
| 200 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
"""
|
| 202 |
|
| 203 |
-
# ==========================================
|
| 204 |
-
# 3. LAYOUT
|
| 205 |
-
# ==========================================
|
| 206 |
with gr.Blocks(css=css, theme=gr.themes.Base()) as demo:
|
| 207 |
|
| 208 |
-
with gr.Column(
|
| 209 |
|
| 210 |
-
#
|
| 211 |
-
with gr.
|
| 212 |
gr.HTML("""
|
| 213 |
-
<div
|
| 214 |
-
<div class="
|
| 215 |
-
<div class="
|
| 216 |
</div>
|
| 217 |
""")
|
| 218 |
|
| 219 |
-
#
|
| 220 |
-
with gr.Row(equal_height=True):
|
| 221 |
|
| 222 |
-
# LEFT: INPUT
|
| 223 |
with gr.Column(scale=1):
|
| 224 |
-
with gr.Group(elem_classes="
|
| 225 |
-
gr.HTML('<div class="
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
gr.Markdown("*Optimized for: Indian Classical / Fusion*", elem_id="hint-text")
|
| 234 |
-
|
| 235 |
-
process_btn = gr.Button("⚡ INITIALIZE SEPARATION", elem_classes="primary-btn")
|
| 236 |
|
| 237 |
-
# RIGHT: OUTPUT
|
| 238 |
with gr.Column(scale=2):
|
| 239 |
-
with gr.Group(elem_classes="
|
| 240 |
-
gr.HTML('<div class="
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
out_other = gr.Audio(label="Violin / Other", interactive=False, elem_classes="audio-player")
|
| 249 |
|
| 250 |
# LOGIC
|
| 251 |
-
|
| 252 |
fn=separate_audio,
|
| 253 |
inputs=[input_audio],
|
| 254 |
outputs=[out_vocals, out_drums, out_bass, out_other]
|
|
|
|
| 9 |
from huggingface_hub import hf_hub_download
|
| 10 |
|
| 11 |
# ==========================================
|
| 12 |
+
# 1. ENGINE SETUP
|
| 13 |
# ==========================================
|
| 14 |
try:
|
| 15 |
from bs_roformer import BSRoformer
|
|
|
|
| 28 |
pass
|
| 29 |
|
| 30 |
def load_model():
|
| 31 |
+
print(">>> 📡 Connecting to Neural Engine...")
|
| 32 |
try:
|
| 33 |
checkpoint_path = hf_hub_download(
|
| 34 |
repo_id="Tachyeon/IAM-RoFormer-Model-Weights",
|
|
|
|
| 60 |
mix, sr = librosa.load(audio_path, sr=44100, mono=False)
|
| 61 |
if len(mix.shape) == 1: mix = np.stack([mix, mix], axis=0)
|
| 62 |
|
| 63 |
+
# Process
|
| 64 |
chunk_size = 44100 * 10
|
| 65 |
overlap = 44100 * 1
|
| 66 |
|
|
|
|
| 71 |
final_output = torch.zeros(1, 4, 2, length).to(DEVICE)
|
| 72 |
counts = torch.zeros(1, 4, 2, length).to(DEVICE)
|
| 73 |
|
|
|
|
| 74 |
with torch.no_grad():
|
| 75 |
context = torch.amp.autocast('cuda') if torch.cuda.is_available() else torch.no_grad()
|
| 76 |
with context:
|
|
|
|
| 88 |
|
| 89 |
stems = (final_output / torch.clamp(counts, min=1.0)).cpu().numpy()[0]
|
| 90 |
|
| 91 |
+
# Export
|
| 92 |
outputs = []
|
| 93 |
for i in range(4):
|
| 94 |
outfile = f"stem_{i}.wav"
|
|
|
|
| 98 |
return outputs
|
| 99 |
|
| 100 |
# ==========================================
|
| 101 |
+
# 2. SHARP & PUNCHY UI DESIGN (No Blur)
|
| 102 |
# ==========================================
|
| 103 |
css = """
|
| 104 |
+
@import url('https://fonts.googleapis.com/css2?family=Teko:wght@300;500;700&family=Work+Sans:wght@400;600;800&display=swap');
|
| 105 |
|
| 106 |
:root {
|
| 107 |
+
--bg-color: #050505;
|
| 108 |
+
--card-bg: #111111;
|
| 109 |
+
--border-color: #333333;
|
| 110 |
+
--highlight-cyan: #00F0FF;
|
| 111 |
+
--highlight-violet: #8F00FF;
|
| 112 |
+
--text-white: #FFFFFF;
|
| 113 |
+
--text-gray: #888888;
|
| 114 |
}
|
| 115 |
|
| 116 |
body, .gradio-container {
|
| 117 |
+
background-color: var(--bg-color) !important;
|
| 118 |
+
color: var(--text-white) !important;
|
| 119 |
+
font-family: 'Work Sans', sans-serif !important;
|
| 120 |
margin: 0; padding: 0;
|
|
|
|
| 121 |
}
|
| 122 |
|
| 123 |
+
/* CONTAINER RESET */
|
| 124 |
+
.contain {
|
| 125 |
+
padding: 30px !important;
|
| 126 |
+
max-width: 1400px !important;
|
| 127 |
+
margin: 0 auto !important;
|
|
|
|
|
|
|
|
|
|
| 128 |
}
|
| 129 |
+
|
| 130 |
+
/* HEADER STYLE */
|
| 131 |
+
.header-wrapper {
|
| 132 |
+
margin-bottom: 40px;
|
| 133 |
+
border-bottom: 2px solid var(--border-color);
|
| 134 |
+
padding-bottom: 20px;
|
|
|
|
|
|
|
| 135 |
}
|
| 136 |
+
.title-main {
|
| 137 |
+
font-family: 'Teko', sans-serif;
|
| 138 |
+
font-size: 5rem; /* Massive Title */
|
| 139 |
+
line-height: 0.9;
|
| 140 |
+
font-weight: 700;
|
| 141 |
+
text-transform: uppercase;
|
| 142 |
+
color: white;
|
| 143 |
+
letter-spacing: 2px;
|
| 144 |
+
}
|
| 145 |
+
.title-sub {
|
| 146 |
+
font-family: 'Work Sans', sans-serif;
|
| 147 |
+
color: var(--highlight-cyan);
|
| 148 |
+
font-size: 1.2rem;
|
| 149 |
+
font-weight: 600;
|
| 150 |
+
letter-spacing: 1px;
|
| 151 |
+
text-transform: uppercase;
|
| 152 |
+
margin-top: 5px;
|
| 153 |
}
|
| 154 |
|
| 155 |
+
/* SHARP CARD PANELS (No Blur) */
|
| 156 |
+
.sharp-card {
|
| 157 |
+
background-color: var(--card-bg);
|
| 158 |
+
border: 1px solid var(--border-color);
|
| 159 |
+
padding: 0px; /* Reset Padding */
|
| 160 |
+
margin-bottom: 0px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
}
|
| 162 |
|
| 163 |
+
.card-header {
|
| 164 |
+
background-color: #1A1A1A;
|
| 165 |
+
padding: 15px 20px;
|
| 166 |
+
border-bottom: 1px solid var(--border-color);
|
| 167 |
+
font-family: 'Teko', sans-serif;
|
| 168 |
+
font-size: 1.8rem;
|
| 169 |
+
color: var(--text-gray);
|
| 170 |
text-transform: uppercase;
|
| 171 |
+
letter-spacing: 1px;
|
| 172 |
+
}
|
| 173 |
+
.card-content {
|
| 174 |
+
padding: 25px;
|
|
|
|
| 175 |
}
|
| 176 |
|
| 177 |
+
/* BUTTON STYLING */
|
| 178 |
+
#run-btn {
|
| 179 |
+
background: linear-gradient(90deg, var(--highlight-violet), var(--highlight-cyan)) !important;
|
| 180 |
+
color: #000 !important;
|
| 181 |
+
font-family: 'Work Sans', sans-serif !important;
|
|
|
|
| 182 |
font-weight: 800 !important;
|
| 183 |
+
font-size: 1.2rem !important;
|
| 184 |
+
text-transform: uppercase !important;
|
| 185 |
+
border: none !important;
|
| 186 |
+
border-radius: 0px !important; /* Sharp Edges */
|
| 187 |
+
padding: 20px !important;
|
| 188 |
+
transition: all 0.2s ease-in-out !important;
|
| 189 |
}
|
| 190 |
+
#run-btn:hover {
|
| 191 |
+
filter: brightness(1.2);
|
| 192 |
+
transform: scale(1.01);
|
| 193 |
}
|
| 194 |
|
| 195 |
/* AUDIO PLAYERS */
|
| 196 |
.audio-player {
|
|
|
|
| 197 |
background: transparent !important;
|
| 198 |
+
border: 1px solid var(--border-color) !important;
|
| 199 |
+
border-radius: 0px !important;
|
| 200 |
margin-bottom: 15px !important;
|
| 201 |
}
|
| 202 |
+
|
| 203 |
+
/* LABEL OVERRIDES */
|
| 204 |
+
span.svelte-1gfkn6j {
|
| 205 |
+
color: var(--highlight-cyan) !important;
|
| 206 |
+
font-weight: 600 !important;
|
| 207 |
+
text-transform: uppercase;
|
| 208 |
+
font-size: 0.8rem;
|
| 209 |
+
}
|
| 210 |
"""
|
| 211 |
|
|
|
|
|
|
|
|
|
|
| 212 |
with gr.Blocks(css=css, theme=gr.themes.Base()) as demo:
|
| 213 |
|
| 214 |
+
with gr.Column(elem_classes="contain"):
|
| 215 |
|
| 216 |
+
# 1. HEADER AREA
|
| 217 |
+
with gr.Group(elem_classes="header-wrapper"):
|
| 218 |
gr.HTML("""
|
| 219 |
+
<div>
|
| 220 |
+
<div class="title-main">Swara Studio</div>
|
| 221 |
+
<div class="title-sub">Neural Audio Source Separation Engine</div>
|
| 222 |
</div>
|
| 223 |
""")
|
| 224 |
|
| 225 |
+
# 2. MAIN GRID
|
| 226 |
+
with gr.Row(equal_height=True, variant="compact"):
|
| 227 |
|
| 228 |
+
# LEFT COLUMN: INPUT
|
| 229 |
with gr.Column(scale=1):
|
| 230 |
+
with gr.Group(elem_classes="sharp-card"):
|
| 231 |
+
gr.HTML('<div class="card-header">Input Source</div>')
|
| 232 |
+
with gr.Column(elem_classes="card-content"):
|
| 233 |
+
input_audio = gr.Audio(
|
| 234 |
+
label="MASTER AUDIO TRACK",
|
| 235 |
+
type="filepath",
|
| 236 |
+
elem_classes="audio-player"
|
| 237 |
+
)
|
| 238 |
+
run_btn = gr.Button("RUN SEPARATION PROCESS", elem_id="run-btn")
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
+
# RIGHT COLUMN: OUTPUT
|
| 241 |
with gr.Column(scale=2):
|
| 242 |
+
with gr.Group(elem_classes="sharp-card"):
|
| 243 |
+
gr.HTML('<div class="card-header">Stem Output</div>')
|
| 244 |
+
with gr.Column(elem_classes="card-content"):
|
| 245 |
+
with gr.Row():
|
| 246 |
+
out_vocals = gr.Audio(label="VOCALS", interactive=False, elem_classes="audio-player")
|
| 247 |
+
out_drums = gr.Audio(label="DRUMS / MRIDANGAM", interactive=False, elem_classes="audio-player")
|
| 248 |
+
with gr.Row():
|
| 249 |
+
out_bass = gr.Audio(label="BASS / TANPURA", interactive=False, elem_classes="audio-player")
|
| 250 |
+
out_other = gr.Audio(label="OTHER / VIOLIN", interactive=False, elem_classes="audio-player")
|
|
|
|
| 251 |
|
| 252 |
# LOGIC
|
| 253 |
+
run_btn.click(
|
| 254 |
fn=separate_audio,
|
| 255 |
inputs=[input_audio],
|
| 256 |
outputs=[out_vocals, out_drums, out_bass, out_other]
|