Tachyeon commited on
Commit
b22b079
·
verified ·
1 Parent(s): 001de0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +114 -112
app.py CHANGED
@@ -9,7 +9,7 @@ import sys
9
  from huggingface_hub import hf_hub_download
10
 
11
  # ==========================================
12
- # 1. BACKEND ENGINE
13
  # ==========================================
14
  try:
15
  from bs_roformer import BSRoformer
@@ -28,7 +28,7 @@ except NameError:
28
  pass
29
 
30
  def load_model():
31
- print(">>> 📡 Loading Engine...")
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
- # Config
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
- # Write
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. VIBRANT UI DESIGN (CSS)
103
  # ==========================================
104
  css = """
105
- @import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;500;800&display=swap');
106
 
107
  :root {
108
- --bg-dark: #09090b;
109
- --panel-glass: rgba(255, 255, 255, 0.03);
110
- --border-light: rgba(255, 255, 255, 0.1);
111
- --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 100%); /* Indigo to Purple */
112
- --text-glow: 0 0 20px rgba(168, 85, 247, 0.5);
 
 
113
  }
114
 
115
  body, .gradio-container {
116
- background-color: var(--bg-dark) !important;
117
- font-family: 'Outfit', sans-serif !important;
118
- color: #ffffff !important;
119
  margin: 0; padding: 0;
120
- height: 100vh; overflow: hidden;
121
  }
122
 
123
- /* HEADER */
124
- .brand-container {
125
- padding: 20px 0;
126
- border-bottom: 1px solid var(--border-light);
127
- margin-bottom: 25px;
128
- display: flex;
129
- align-items: center;
130
- justify-content: space-between;
131
  }
132
- .brand-text {
133
- font-size: 2.2rem;
134
- font-weight: 800;
135
- letter-spacing: -1px;
136
- background: var(--accent-gradient);
137
- -webkit-background-clip: text;
138
- -webkit-text-fill-color: transparent;
139
- text-shadow: 0px 5px 15px rgba(99, 102, 241, 0.3);
140
  }
141
- .version-tag {
142
- background: rgba(255,255,255,0.1);
143
- padding: 4px 12px;
144
- border-radius: 20px;
145
- font-size: 0.8rem;
146
- font-weight: 500;
147
- color: #a5b4fc;
 
 
 
 
 
 
 
 
 
 
148
  }
149
 
150
- /* PANELS */
151
- .glass-panel {
152
- background: var(--panel-glass);
153
- backdrop-filter: blur(10px);
154
- border: 1px solid var(--border-light);
155
- border-radius: 24px;
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
- .panel-title {
164
- font-size: 1.1rem;
165
- font-weight: 500;
166
- color: #94a3b8;
 
 
 
167
  text-transform: uppercase;
168
- letter-spacing: 2px;
169
- margin-bottom: 20px;
170
- display: flex;
171
- align-items: center;
172
- gap: 10px;
173
  }
174
 
175
- /* BUTTON */
176
- button.primary-btn {
177
- background: var(--accent-gradient) !important;
178
- border: none !important;
179
- color: white !important;
180
- font-size: 1.1rem !important;
181
  font-weight: 800 !important;
182
- padding: 18px !important;
183
- border-radius: 16px !important;
184
- margin-top: auto !important;
185
- cursor: pointer !important;
186
- transition: transform 0.2s, box-shadow 0.2s !important;
187
- box-shadow: 0 10px 30px -10px rgba(168, 85, 247, 0.6) !important;
188
  }
189
- button.primary-btn:hover {
190
- transform: translateY(-3px);
191
- box-shadow: 0 20px 40px -10px rgba(168, 85, 247, 0.8) !important;
192
  }
193
 
194
  /* AUDIO PLAYERS */
195
  .audio-player {
196
- border: 1px solid var(--border-light) !important;
197
  background: transparent !important;
198
- border-radius: 12px !important;
 
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(elem_id="main-container"):
209
 
210
- # HEADLINE
211
- with gr.Row(elem_classes="brand-container"):
212
  gr.HTML("""
213
- <div style="display:flex; align-items:center; width:100%; justify-content:space-between;">
214
- <div class="brand-text">SWARA STUDIO</div>
215
- <div class="version-tag">V11.0 CONSENSUS</div>
216
  </div>
217
  """)
218
 
219
- # WORKSPACE
220
- with gr.Row(equal_height=True):
221
 
222
- # LEFT: INPUT
223
  with gr.Column(scale=1):
224
- with gr.Group(elem_classes="glass-panel"):
225
- gr.HTML('<div class="panel-title">💿 INPUT SOURCE</div>')
226
-
227
- input_audio = gr.Audio(
228
- label="Upload Track",
229
- type="filepath",
230
- elem_classes="audio-player"
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="glass-panel"):
240
- gr.HTML('<div class="panel-title">🎚️ ISOLATED STEMS</div>')
241
-
242
- with gr.Row():
243
- out_vocals = gr.Audio(label="Vocals", interactive=False, elem_classes="audio-player")
244
- out_drums = gr.Audio(label="Mridangam / Drums", interactive=False, elem_classes="audio-player")
245
-
246
- with gr.Row():
247
- out_bass = gr.Audio(label="Tanpura / Bass", interactive=False, elem_classes="audio-player")
248
- out_other = gr.Audio(label="Violin / Other", interactive=False, elem_classes="audio-player")
249
 
250
  # LOGIC
251
- process_btn.click(
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]