ASesYusuf1 commited on
Commit
338b675
·
verified ·
1 Parent(s): 7e310cd

Update gui.py

Browse files
Files changed (1) hide show
  1. gui.py +12 -577
gui.py CHANGED
@@ -1,582 +1,17 @@
1
- import os
2
- import sys
3
- import torch
4
- import logging
5
- from yt_dlp import YoutubeDL
6
  import gradio as gr
7
  import argparse
8
- from audio_separator.separator import Separator
9
- import numpy as np
10
- import librosa
11
- import soundfile as sf
12
- from ensemble import ensemble_files
13
- import shutil
14
 
15
- device = "cuda" if torch.cuda.is_available() else "cpu"
16
- use_autocast = device == "cuda"
 
17
 
18
- # Logging ayarları
19
- logging.basicConfig(level=logging.INFO)
20
- logger = logging.getLogger(__name__)
 
 
 
 
21
 
22
- # Model dictionaries organized by category
23
- ROFORMER_MODELS = {
24
- "Vocals": {
25
- 'MelBand Roformer | Big Beta 6X by unwa': 'melband_roformer_big_beta6x.ckpt',
26
- 'MelBand Roformer Kim | Big Beta 4 FT by unwa': 'melband_roformer_big_beta4.ckpt',
27
- 'MelBand Roformer Kim | Big Beta 5e FT by unwa': 'melband_roformer_big_beta5e.ckpt',
28
- 'MelBand Roformer | Big Beta 6 by unwa': 'melband_roformer_big_beta6.ckpt',
29
- 'MelBand Roformer | Vocals by Kimberley Jensen': 'vocals_mel_band_roformer.ckpt',
30
- 'MelBand Roformer Kim | FT 3 by unwa': 'mel_band_roformer_kim_ft3_unwa.ckpt',
31
- 'MelBand Roformer Kim | FT by unwa': 'mel_band_roformer_kim_ft_unwa.ckpt',
32
- 'MelBand Roformer Kim | FT 2 by unwa': 'mel_band_roformer_kim_ft2_unwa.ckpt',
33
- 'MelBand Roformer Kim | FT 2 Bleedless by unwa': 'mel_band_roformer_kim_ft2_bleedless_unwa.ckpt',
34
- 'MelBand Roformer | Vocals by becruily': 'mel_band_roformer_vocals_becruily.ckpt',
35
- 'MelBand Roformer | Vocals Fullness by Aname': 'mel_band_roformer_vocal_fullness_aname.ckpt',
36
- 'BS Roformer | Vocals by Gabox': 'bs_roformer_vocals_gabox.ckpt',
37
- 'MelBand Roformer | Vocals by Gabox': 'mel_band_roformer_vocals_gabox.ckpt',
38
- 'MelBand Roformer | Vocals FV1 by Gabox': 'mel_band_roformer_vocals_fv1_gabox.ckpt',
39
- 'MelBand Roformer | Vocals FV2 by Gabox': 'mel_band_roformer_vocals_fv2_gabox.ckpt',
40
- 'MelBand Roformer | Vocals FV3 by Gabox': 'mel_band_roformer_vocals_fv3_gabox.ckpt',
41
- 'MelBand Roformer | Vocals FV4 by Gabox': 'mel_band_roformer_vocals_fv4_gabox.ckpt',
42
- 'BS Roformer | Chorus Male-Female by Sucial': 'model_chorus_bs_roformer_ep_267_sdr_24.1275.ckpt',
43
- 'BS Roformer | Male-Female by aufr33': 'bs_roformer_male_female_by_aufr33_sdr_7.2889.ckpt',
44
- },
45
- "Instrumentals": {
46
- 'MelBand Roformer | FVX by Gabox': 'mel_band_roformer_instrumental_fvx_gabox.ckpt',
47
- 'MelBand Roformer | INSTV8N by Gabox': 'mel_band_roformer_instrumental_instv8n_gabox.ckpt',
48
- 'MelBand Roformer | INSTV8 by Gabox': 'mel_band_roformer_instrumental_instv8_gabox.ckpt',
49
- 'MelBand Roformer | INSTV7N by Gabox': 'mel_band_roformer_instrumental_instv7n_gabox.ckpt',
50
- 'MelBand Roformer | Instrumental Bleedless V3 by Gabox': 'mel_band_roformer_instrumental_bleedless_v3_gabox.ckpt',
51
- 'MelBand Roformer Kim | Inst V1 (E) Plus by Unwa': 'melband_roformer_inst_v1e_plus.ckpt',
52
- 'MelBand Roformer Kim | Inst V1 Plus by Unwa': 'melband_roformer_inst_v1_plus.ckpt',
53
- 'MelBand Roformer Kim | Inst V1 by Unwa': 'melband_roformer_inst_v1.ckpt',
54
- 'MelBand Roformer Kim | Inst V1 (E) by Unwa': 'melband_roformer_inst_v1e.ckpt',
55
- 'MelBand Roformer Kim | Inst V2 by Unwa': 'melband_roformer_inst_v2.ckpt',
56
- 'MelBand Roformer | Instrumental by becruily': 'mel_band_roformer_instrumental_becruily.ckpt',
57
- 'MelBand Roformer | Instrumental by Gabox': 'mel_band_roformer_instrumental_gabox.ckpt',
58
- 'MelBand Roformer | Instrumental 2 by Gabox': 'mel_band_roformer_instrumental_2_gabox.ckpt',
59
- 'MelBand Roformer | Instrumental 3 by Gabox': 'mel_band_roformer_instrumental_3_gabox.ckpt',
60
- 'MelBand Roformer | Instrumental Bleedless V1 by Gabox': 'mel_band_roformer_instrumental_bleedless_v1_gabox.ckpt',
61
- 'MelBand Roformer | Instrumental Bleedless V2 by Gabox': 'mel_band_roformer_instrumental_bleedless_v2_gabox.ckpt',
62
- 'MelBand Roformer | Instrumental Fullness V1 by Gabox': 'mel_band_roformer_instrumental_fullness_v1_gabox.ckpt',
63
- 'MelBand Roformer | Instrumental Fullness V2 by Gabox': 'mel_band_roformer_instrumental_fullness_v2_gabox.ckpt',
64
- 'MelBand Roformer | Instrumental Fullness V3 by Gabox': 'mel_band_roformer_instrumental_fullness_v3_gabox.ckpt',
65
- 'MelBand Roformer | Instrumental Fullness Noisy V4 by Gabox': 'mel_band_roformer_instrumental_fullness_noise_v4_gabox.ckpt',
66
- 'MelBand Roformer | INSTV5 by Gabox': 'mel_band_roformer_instrumental_instv5_gabox.ckpt',
67
- 'MelBand Roformer | INSTV5N by Gabox': 'mel_band_roformer_instrumental_instv5n_gabox.ckpt',
68
- 'MelBand Roformer | INSTV6 by Gabox': 'mel_band_roformer_instrumental_instv6_gabox.ckpt',
69
- 'MelBand Roformer | INSTV6N by Gabox': 'mel_band_roformer_instrumental_instv6n_gabox.ckpt',
70
- 'MelBand Roformer | INSTV7 by Gabox': 'mel_band_roformer_instrumental_instv7_gabox.ckpt',
71
- },
72
- "InstVoc Duality": {
73
- 'MelBand Roformer Kim | InstVoc Duality V1 by Unwa': 'melband_roformer_instvoc_duality_v1.ckpt',
74
- 'MelBand Roformer Kim | InstVoc Duality V2 by Unwa': 'melband_roformer_instvox_duality_v2.ckpt',
75
- },
76
- "De-Reverb": {
77
- 'BS-Roformer-De-Reverb': 'deverb_bs_roformer_8_384dim_10depth.ckpt',
78
- 'MelBand Roformer | De-Reverb by anvuew': 'dereverb_mel_band_roformer_anvuew_sdr_19.1729.ckpt',
79
- 'MelBand Roformer | De-Reverb Less Aggressive by anvuew': 'dereverb_mel_band_roformer_less_aggressive_anvuew_sdr_18.8050.ckpt',
80
- 'MelBand Roformer | De-Reverb Mono by anvuew': 'dereverb_mel_band_roformer_mono_anvuew.ckpt',
81
- 'MelBand Roformer | De-Reverb Big by Sucial': 'dereverb_big_mbr_ep_362.ckpt',
82
- 'MelBand Roformer | De-Reverb Super Big by Sucial': 'dereverb_super_big_mbr_ep_346.ckpt',
83
- 'MelBand Roformer | De-Reverb-Echo by Sucial': 'dereverb-echo_mel_band_roformer_sdr_10.0169.ckpt',
84
- 'MelBand Roformer | De-Reverb-Echo V2 by Sucial': 'dereverb-echo_mel_band_roformer_sdr_13.4843_v2.ckpt',
85
- 'MelBand Roformer | De-Reverb-Echo Fused by Sucial': 'dereverb_echo_mbr_fused.ckpt',
86
- },
87
- "Denoise": {
88
- 'Mel-Roformer-Denoise-Aufr33': 'denoise_mel_band_roformer_aufr33_sdr_27.9959.ckpt',
89
- 'Mel-Roformer-Denoise-Aufr33-Aggr': 'denoise_mel_band_roformer_aufr33_aggr_sdr_27.9768.ckpt',
90
- 'MelBand Roformer | Denoise-Debleed by Gabox': 'mel_band_roformer_denoise_debleed_gabox.ckpt',
91
- 'MelBand Roformer | Bleed Suppressor V1 by unwa-97chris': 'mel_band_roformer_bleed_suppressor_v1.ckpt',
92
- },
93
- "Karaoke": {
94
- 'Mel-Roformer-Karaoke-Aufr33-Viperx': 'mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt',
95
- 'MelBand Roformer | Karaoke by Gabox': 'mel_band_roformer_karaoke_gabox.ckpt',
96
- "MelBand Roformer | Karaoke by becruily": 'mel_band_roformer_karaoke_becruily.ckpt',
97
- },
98
- "General Purpose": {
99
- 'BS-Roformer-Viperx-1297': 'model_bs_roformer_ep_317_sdr_12.9755.ckpt',
100
- 'BS-Roformer-Viperx-1296': 'model_bs_roformer_ep_368_sdr_12.9628.ckpt',
101
- 'BS-Roformer-Viperx-1053': 'model_bs_roformer_ep_937_sdr_10.5309.ckpt',
102
- 'Mel-Roformer-Viperx-1143': 'model_mel_band_roformer_ep_3005_sdr_11.4360.ckpt',
103
- 'Mel-Roformer-Crowd-Aufr33-Viperx': 'mel_band_roformer_crowd_aufr33_viperx_sdr_8.7144.ckpt',
104
- 'MelBand Roformer Kim | SYHFT by SYH99999': 'MelBandRoformerSYHFT.ckpt',
105
- 'MelBand Roformer Kim | SYHFT V2 by SYH99999': 'MelBandRoformerSYHFTV2.ckpt',
106
- 'MelBand Roformer Kim | SYHFT V2.5 by SYH99999': 'MelBandRoformerSYHFTV2.5.ckpt',
107
- 'MelBand Roformer Kim | SYHFT V3 by SYH99999': 'MelBandRoformerSYHFTV3Epsilon.ckpt',
108
- 'MelBand Roformer Kim | Big SYHFT V1 by SYH99999': 'MelBandRoformerBigSYHFTV1.ckpt',
109
- 'MelBand Roformer | Aspiration by Sucial': 'aspiration_mel_band_roformer_sdr_18.9845.ckpt',
110
- 'MelBand Roformer | Aspiration Less Aggressive by Sucial': 'aspiration_mel_band_roformer_less_aggr_sdr_18.1201.ckpt',
111
- }
112
- }
113
-
114
- OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']
115
-
116
- # CSS (değişmedi, aynı kalıyor)
117
- CSS = """
118
- /* Modern ve Etkileşimli Tema */
119
- #app-container {
120
- max-width: 900px;
121
- width: 100%;
122
- margin: 0 auto;
123
- padding: 1rem;
124
- box-sizing: border-box;
125
- display: flex;
126
- flex-direction: column;
127
- align-items: center;
128
- min-height: 100vh;
129
- background: linear-gradient(135deg, #1a0b2e, #2e1a47);
130
- position: relative;
131
- overflow: hidden;
132
- }
133
- body {
134
- background: url('/content/logo.jpg') no-repeat center center fixed;
135
- background-size: cover;
136
- margin: 0;
137
- padding: 0;
138
- font-family: 'Roboto', sans-serif;
139
- color: #e0e0e0;
140
- display: flex;
141
- justify-content: center;
142
- }
143
- body::after {
144
- content: '';
145
- position: fixed;
146
- top: 0;
147
- left: 0;
148
- width: 100%;
149
- height: 100%;
150
- background: rgba(26, 11, 46, 0.8);
151
- z-index: -1;
152
- }
153
- .logo-container {
154
- position: fixed;
155
- top: 1rem;
156
- left: 50%;
157
- transform: translateX(-50%);
158
- z-index: 2000;
159
- }
160
- .logo-img {
161
- width: 80px;
162
- height: auto;
163
- transition: transform 0.3s ease;
164
- }
165
- .logo-img:hover {
166
- transform: scale(1.1);
167
- }
168
- .header-text {
169
- text-align: center;
170
- padding: 3rem 0 1rem;
171
- color: #ff6b6b;
172
- font-size: 2rem;
173
- font-weight: 800;
174
- text-shadow: 0 0 10px rgba(255, 107, 107, 0.7);
175
- animation: glow 2s infinite alternate;
176
- }
177
- @keyframes glow {
178
- 0% { text-shadow: 0 0 10px rgba(255, 107, 107, 0.7); }
179
- 100% { text-shadow: 0 0 20px rgba(255, 107, 107, 1); }
180
- }
181
- .dubbing-theme {
182
- background: rgba(46, 26, 71, 0.9);
183
- border-radius: 12px;
184
- padding: 1rem;
185
- box-shadow: 0 5px 20px rgba(255, 107, 107, 0.3);
186
- width: 100%;
187
- transition: transform 0.3s ease;
188
- }
189
- .dubbing-theme:hover {
190
- transform: translateY(-5px);
191
- }
192
- .footer {
193
- text-align: center;
194
- padding: 0.5rem;
195
- color: #ff6b6b;
196
- font-size: 12px;
197
- position: fixed;
198
- bottom: 0;
199
- width: 100%;
200
- max-width: 900px;
201
- background: rgba(26, 11, 46, 0.7);
202
- z-index: 1001;
203
- left: 50%;
204
- transform: translateX(-50%);
205
- }
206
- button {
207
- background: #ff6b6b !important;
208
- border: none !important;
209
- color: #fff !important;
210
- border-radius: 8px !important;
211
- padding: 8px 16px !important;
212
- font-size: 1rem !important;
213
- font-weight: 600 !important;
214
- transition: all 0.3s ease !important;
215
- box-shadow: 0 2px 8px rgba(255, 107, 107, 0.4) !important;
216
- }
217
- button:hover {
218
- transform: scale(1.05) !important;
219
- background: #ff8787 !important;
220
- box-shadow: 0 4px 12px rgba(255, 107, 107, 0.6) !important;
221
- }
222
- .compact-upload.horizontal {
223
- display: flex !important;
224
- align-items: center !important;
225
- gap: 8px !important;
226
- max-width: 300px !important;
227
- padding: 6px 10px !important;
228
- border: 2px dashed #ff6b6b !important;
229
- background: rgba(46, 26, 71, 0.7) !important;
230
- border-radius: 8px !important;
231
- color: #e0e0e0 !important;
232
- transition: border-color 0.3s ease !important;
233
- }
234
- .compact-upload.horizontal:hover {
235
- border-color: #ff8787 !important;
236
- }
237
- .compact-upload.horizontal button {
238
- padding: 4px 10px !important;
239
- font-size: 0.8rem !important;
240
- }
241
- .gr-tab {
242
- background: rgba(46, 26, 71, 0.7) !important;
243
- border-radius: 8px 8px 0 0 !important;
244
- padding: 0.5rem 1rem !important;
245
- margin: 0 2px !important;
246
- color: #e0e0e0 !important;
247
- border: 2px solid #ff6b6b !important;
248
- font-size: 1rem !important;
249
- transition: all 0.3s ease !important;
250
- }
251
- .gr-tab-selected {
252
- background: #ff6b6b !important;
253
- color: #fff !important;
254
- border: 2px solid #ff8787 !important;
255
- box-shadow: 0 2px 8px rgba(255, 107, 107, 0.5) !important;
256
- }
257
- .compact-grid {
258
- gap: 0.5rem !important;
259
- max-height: 40vh;
260
- overflow-y: auto;
261
- padding: 1rem;
262
- background: rgba(46, 26, 71, 0.7) !important;
263
- border-radius: 10px;
264
- border: 2px solid #ff6b6b !important;
265
- width: 100%;
266
- }
267
- .compact-dropdown {
268
- padding: 8px 12px !important;
269
- border-radius: 8px !important;
270
- border: 2px solid #ff6b6b !important;
271
- background: rgba(46, 26, 71, 0.7) !important;
272
- color: #e0e0e0 !important;
273
- width: 100%;
274
- font-size: 1rem !important;
275
- transition: border-color 0.3s ease !important;
276
- }
277
- .compact-dropdown:hover {
278
- border-color: #ff8787 !important;
279
- }
280
- .gr-slider input[type="range"] {
281
- -webkit-appearance: none !important;
282
- width: 100% !important;
283
- height: 6px !important;
284
- background: #ff6b6b !important;
285
- border-radius: 3px !important;
286
- outline: none !important;
287
- }
288
- .gr-slider input[type="range"]::-webkit-slider-thumb {
289
- -webkit-appearance: none !important;
290
- width: 16px !important;
291
- height: 16px !important;
292
- background: #fff !important;
293
- border: 2px solid #ff6b6b !important;
294
- border-radius: 50% !important;
295
- cursor: pointer !important;
296
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2) !important;
297
- }
298
- .gr-slider input[type="range"]::-moz-range-thumb {
299
- width: 16px !important;
300
- height: 16px !important;
301
- background: #fff !important;
302
- border: 2px solid #ff6b6b !important;
303
- border-radius: 50% !important;
304
- cursor: pointer !important;
305
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2) !important;
306
- }
307
- @media (max-width: 768px) {
308
- #app-container {
309
- max-width: 100%;
310
- padding: 0.5rem;
311
- }
312
- .header-text {
313
- font-size: 1.5rem;
314
- padding: 2rem 0 0.5rem;
315
- }
316
- .logo-img {
317
- width: 60px;
318
- }
319
- .compact-upload.horizontal {
320
- max-width: 100% !important;
321
- }
322
- .compact-grid {
323
- max-height: 30vh;
324
- }
325
- .footer {
326
- max-width: 100%;
327
- }
328
- }
329
- """
330
-
331
- # Fonksiyonlar
332
- def download_audio(url, out_dir="ytdl"):
333
- if not url:
334
- raise ValueError("No URL provided.")
335
-
336
- # ytdl klasörünü temizle
337
- if os.path.exists(out_dir):
338
- shutil.rmtree(out_dir)
339
- os.makedirs(out_dir, exist_ok=True)
340
-
341
- ydl_opts = {
342
- 'format': 'bestaudio/best',
343
- 'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'wav', 'preferredquality': '192'}],
344
- 'outtmpl': os.path.join(out_dir, '%(title)s.%(ext)s'),
345
- }
346
- try:
347
- with YoutubeDL(ydl_opts) as ydl:
348
- ydl.download([url])
349
- info_dict = ydl.extract_info(url, download=True)
350
- return ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.wav'
351
- except Exception as e:
352
- raise RuntimeError(f"Download failed: {e}")
353
-
354
- def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, pitch_shift, model_dir, output_dir, out_format, norm_thresh, amp_thresh, batch_size, exclude_stems="", progress=gr.Progress(track_tqdm=True)):
355
- if not audio:
356
- raise ValueError("No audio file provided.")
357
-
358
- # override_seg_size string olarak geliyor, boolean'a çevir
359
- override_seg_size = override_seg_size == "True"
360
-
361
- # output klasörünü temizle
362
- if os.path.exists(output_dir):
363
- shutil.rmtree(output_dir)
364
- os.makedirs(output_dir, exist_ok=True)
365
-
366
- base_name = os.path.splitext(os.path.basename(audio))[0]
367
- for category, models in ROFORMER_MODELS.items():
368
- if model_key in models:
369
- model = models[model_key]
370
- break
371
- else:
372
- raise ValueError(f"Model '{model_key}' not found.")
373
-
374
- logger.info(f"Separating {base_name} with {model_key}")
375
- try:
376
- separator = Separator(
377
- log_level=logging.INFO,
378
- model_file_dir=model_dir,
379
- output_dir=output_dir,
380
- output_format=out_format,
381
- normalization_threshold=norm_thresh,
382
- amplification_threshold=amp_thresh,
383
- use_autocast=use_autocast,
384
- mdxc_params={"segment_size": seg_size, "override_model_segment_size": override_seg_size, "batch_size": batch_size, "overlap": overlap, "pitch_shift": pitch_shift}
385
- )
386
- progress(0.2, desc="Loading model...")
387
- separator.load_model(model_filename=model)
388
- progress(0.7, desc="Separating audio...")
389
- separation = separator.separate(audio)
390
- stems = [os.path.join(output_dir, file_name) for file_name in separation]
391
-
392
- # Exclude stems filtresi
393
- if exclude_stems.strip():
394
- excluded = [s.strip().lower() for s in exclude_stems.split(',')]
395
- filtered_stems = [stem for stem in stems if not any(ex in os.path.basename(stem).lower() for ex in excluded)]
396
- return filtered_stems[0] if filtered_stems else None, filtered_stems[1] if len(filtered_stems) > 1 else None
397
- return stems[0], stems[1] if len(stems) > 1 else None
398
- except Exception as e:
399
- logger.error(f"Separation failed: {e}")
400
- raise RuntimeError(f"Separation failed: {e}")
401
-
402
- def auto_ensemble_process(audio, model_keys, seg_size, overlap, out_format, use_tta, model_dir, output_dir, norm_thresh, amp_thresh, batch_size, ensemble_method, exclude_stems="", weights=None, progress=gr.Progress()):
403
- if not audio or not model_keys:
404
- raise ValueError("Audio or models missing.")
405
-
406
- # use_tta string olarak geliyor, boolean'a çevir
407
- use_tta = use_tta == "True"
408
-
409
- # output klasörünü temizle
410
- if os.path.exists(output_dir):
411
- shutil.rmtree(output_dir)
412
- os.makedirs(output_dir, exist_ok=True)
413
-
414
- base_name = os.path.splitext(os.path.basename(audio))[0]
415
- logger.info(f"Ensemble for {base_name} with {model_keys}")
416
-
417
- all_stems = [] # Tüm modellerden kalan stem'ler burada toplanacak
418
- total_models = len(model_keys)
419
-
420
- # Her model için ayrıştırma yap
421
- for i, model_key in enumerate(model_keys):
422
- for category, models in ROFORMER_MODELS.items():
423
- if model_key in models:
424
- model = models[model_key]
425
- break
426
- else:
427
- continue
428
-
429
- separator = Separator(
430
- log_level=logging.INFO,
431
- model_file_dir=model_dir,
432
- output_dir=output_dir,
433
- output_format=out_format,
434
- normalization_threshold=norm_thresh,
435
- amplification_threshold=amp_thresh,
436
- use_autocast=use_autocast,
437
- mdxc_params={"segment_size": seg_size, "overlap": overlap, "use_tta": use_tta, "batch_size": batch_size}
438
- )
439
- progress(0.1 + (0.4 / total_models) * i, desc=f"Loading {model_key}")
440
- separator.load_model(model_filename=model)
441
- progress(0.5 + (0.4 / total_models) * i, desc=f"Separating with {model_key}")
442
- separation = separator.separate(audio)
443
- stems = [os.path.join(output_dir, file_name) for file_name in separation]
444
-
445
- # Exclude stems filtresi
446
- if exclude_stems.strip():
447
- excluded = [s.strip().lower() for s in exclude_stems.split(',')]
448
- filtered_stems = [stem for stem in stems if not any(ex in os.path.basename(stem).lower() for ex in excluded)]
449
- all_stems.extend(filtered_stems)
450
- else:
451
- all_stems.extend(stems) # Eğer exclude_stems yoksa tüm stem'leri al
452
-
453
- if not all_stems:
454
- raise ValueError("No valid stems for ensemble after exclusion.")
455
-
456
- # Weights kontrolü
457
- if weights is None or len(weights) != len(model_keys):
458
- weights = [1.0] * len(model_keys)
459
-
460
- # Tüm kalan stem'leri birleştir
461
- output_file = os.path.join(output_dir, f"{base_name}_ensemble_{ensemble_method}.{out_format}")
462
- ensemble_args = [
463
- "--files", *all_stems,
464
- "--type", ensemble_method,
465
- "--weights", *[str(w) for w in weights[:len(all_stems)]], # Stem sayısına göre weights kes
466
- "--output", output_file
467
- ]
468
- progress(0.9, desc="Running ensemble...")
469
- ensemble_files(ensemble_args)
470
-
471
- progress(1.0, desc="Ensemble complete")
472
- return output_file, f"Ensemble completed with {ensemble_method}, excluded: {exclude_stems if exclude_stems else 'None'}"
473
-
474
- def update_roformer_models(category):
475
- return gr.update(choices=list(ROFORMER_MODELS[category].keys()))
476
-
477
- def update_ensemble_models(category):
478
- return gr.update(choices=list(ROFORMER_MODELS[category].keys()))
479
-
480
- # Arayüzü bir fonksiyon olarak tanımla
481
- def create_interface():
482
- with gr.Blocks(title="🎵 SESA Fast Separation 🎵", css=CSS, elem_id="app-container") as app:
483
- gr.Markdown("<h1 class='header-text'>🎵 SESA Fast Separation 🎵</h1>")
484
-
485
- with gr.Tabs():
486
- # Settings Sekmesi
487
- with gr.Tab("⚙️ Settings"):
488
- with gr.Group(elem_classes="dubbing-theme"):
489
- gr.Markdown("### General Settings")
490
- model_file_dir = gr.Textbox(value="/tmp/audio-separator-models/", label="📂 Model Cache", placeholder="Path to model directory", interactive=True)
491
- output_dir = gr.Textbox(value="output", label="📤 Output Directory", placeholder="Where to save results", interactive=True)
492
- output_format = gr.Dropdown(value="wav", choices=OUTPUT_FORMATS, label="🎶 Output Format", interactive=True)
493
- norm_threshold = gr.Slider(0.1, 1, value=0.9, step=0.1, label="🔊 Normalization Threshold", interactive=True)
494
- amp_threshold = gr.Slider(0.1, 1, value=0.3, step=0.1, label="📈 Amplification Threshold", interactive=True)
495
- batch_size = gr.Slider(1, 16, value=4, step=1, label="⚡ Batch Size", interactive=True)
496
-
497
- # Roformer Sekmesi
498
- with gr.Tab("🎤 Roformer"):
499
- with gr.Group(elem_classes="dubbing-theme"):
500
- gr.Markdown("### Audio Separation")
501
- with gr.Row():
502
- roformer_audio = gr.Audio(label="🎧 Upload Audio", type="filepath", interactive=True)
503
- url_ro = gr.Textbox(label="🔗 Or Paste URL", placeholder="YouTube or audio URL", interactive=True)
504
- download_roformer = gr.Button("⬇️ download", variant="secondary")
505
- roformer_exclude_stems = gr.Textbox(label="🚫 Exclude Stems", placeholder="e.g., vocals, drums (comma-separated)", interactive=True)
506
- with gr.Row():
507
- roformer_category = gr.Dropdown(label="📚 Category", choices=list(ROFORMER_MODELS.keys()), value="General Purpose", interactive=True)
508
- roformer_model = gr.Dropdown(label="🛠️ Model", choices=list(ROFORMER_MODELS["General Purpose"].keys()), interactive=True)
509
- with gr.Row():
510
- roformer_seg_size = gr.Slider(32, 4000, value=256, step=32, label="📏 Segment Size", interactive=True)
511
- roformer_overlap = gr.Slider(2, 10, value=8, step=1, label="🔄 Overlap", interactive=True)
512
- with gr.Row():
513
- roformer_pitch_shift = gr.Slider(-12, 12, value=0, step=1, label="🎵 Pitch Shift", interactive=True)
514
- roformer_override_seg_size = gr.Dropdown(
515
- choices=["True", "False"],
516
- value="False",
517
- label="🔧 Override Segment Size",
518
- interactive=True
519
- )
520
- roformer_button = gr.Button("✂️ Separate Now!", variant="primary")
521
- with gr.Row():
522
- roformer_stem1 = gr.Audio(label="🎸 Stem 1", type="filepath", interactive=False)
523
- roformer_stem2 = gr.Audio(label="🥁 Stem 2", type="filepath", interactive=False)
524
-
525
- # Auto Ensemble Sekmesi
526
- with gr.Tab("🎚️ Auto Ensemble"):
527
- with gr.Group(elem_classes="dubbing-theme"):
528
- gr.Markdown("### Ensemble Processing")
529
- with gr.Row():
530
- ensemble_audio = gr.Audio(label="🎧 Upload Audio", type="filepath", interactive=True)
531
- url_ensemble = gr.Textbox(label="🔗 Or Paste URL", placeholder="YouTube or audio URL", interactive=True)
532
- download_ensemble = gr.Button("⬇️ download", variant="secondary")
533
- ensemble_exclude_stems = gr.Textbox(label="🚫 Exclude Stems", placeholder="e.g., vocals, drums (comma-separated)", interactive=True)
534
- with gr.Row():
535
- ensemble_category = gr.Dropdown(label="📚 Category", choices=list(ROFORMER_MODELS.keys()), value="Instrumentals", interactive=True)
536
- ensemble_models = gr.Dropdown(label="🛠️ Models", choices=list(ROFORMER_MODELS["Instrumentals"].keys()), multiselect=True, interactive=True)
537
- with gr.Row():
538
- ensemble_seg_size = gr.Slider(32, 4000, value=256, step=32, label="📏 Segment Size", interactive=True)
539
- ensemble_overlap = gr.Slider(2, 10, value=8, step=1, label="🔄 Overlap", interactive=True)
540
- ensemble_use_tta = gr.Dropdown(
541
- choices=["True", "False"],
542
- value="False",
543
- label="🔍 Use TTA",
544
- interactive=True
545
- )
546
- ensemble_method = gr.Dropdown(label="⚙️ Ensemble Method", choices=['avg_wave', 'median_wave', 'max_wave', 'min_wave', 'avg_fft', 'median_fft', 'max_fft', 'min_fft'], value='avg_wave', interactive=True)
547
- ensemble_weights = gr.Textbox(label="⚖️ Weights", placeholder="e.g., 1.0, 1.0 (comma-separated)", interactive=True)
548
- ensemble_button = gr.Button("🎛️ Run Ensemble!", variant="primary")
549
- ensemble_output = gr.Audio(label="🎶 Ensemble Result", type="filepath", interactive=False)
550
- ensemble_status = gr.Textbox(label="📢 Status", interactive=False)
551
-
552
- gr.HTML("<div class='footer'>Powered by Audio-Separator 🌟🎶 | Made with ❤️</div>")
553
-
554
- # Event Handlers
555
- roformer_category.change(update_roformer_models, inputs=[roformer_category], outputs=[roformer_model])
556
- download_roformer.click(fn=download_audio, inputs=[url_ro], outputs=[roformer_audio])
557
- roformer_button.click(
558
- roformer_separator,
559
- inputs=[roformer_audio, roformer_model, roformer_seg_size, roformer_override_seg_size, roformer_overlap, roformer_pitch_shift, model_file_dir, output_dir, output_format, norm_threshold, amp_threshold, batch_size, roformer_exclude_stems],
560
- outputs=[roformer_stem1, roformer_stem2]
561
- )
562
- ensemble_category.change(update_ensemble_models, inputs=[ensemble_category], outputs=[ensemble_models])
563
- download_ensemble.click(fn=download_audio, inputs=[url_ensemble], outputs=[ensemble_audio])
564
- ensemble_button.click(
565
- lambda *args: auto_ensemble_process(
566
- *args[:-1],
567
- weights=[float(w.strip()) for w in args[-1].split(',')] if args[-1] else None
568
- ),
569
- inputs=[ensemble_audio, ensemble_models, ensemble_seg_size, ensemble_overlap, output_format, ensemble_use_tta, model_file_dir, output_dir, norm_threshold, amp_threshold, batch_size, ensemble_method, ensemble_exclude_stems, ensemble_weights],
570
- outputs=[ensemble_output, ensemble_status]
571
- )
572
-
573
- return app
574
-
575
- if __name__ == "__main__":
576
- parser = argparse.ArgumentParser(description="Music Source Separation Web UI")
577
- parser.add_argument("--port", type=int, default=7860, help="Port to run the UI on")
578
- args = parser.parse_args()
579
-
580
- app = create_interface()
581
- app.launch(server_name="0.0.0.0", server_port=args.port)
582
- app.close()
 
 
 
 
 
 
1
  import gradio as gr
2
  import argparse
 
 
 
 
 
 
3
 
4
+ parser = argparse.ArgumentParser()
5
+ parser.add_argument("--port", type=int, default=7860)
6
+ args = parser.parse_args()
7
 
8
+ # Define your Gradio Blocks or Interface
9
+ app = gr.Blocks()
10
+ with app:
11
+ gr.Markdown("Hello, World!")
12
+ input_text = gr.Textbox()
13
+ output_text = gr.Textbox()
14
+ gr.Button("Submit").click(fn=lambda x: x.upper(), inputs=input_text, outputs=output_text)
15
 
16
+ # Launch with share=True for remote access or localhost for local testing
17
+ app.launch(server_name="0.0.0.0", server_port=args.port, share=True) # Or server_name="127.0.0.1" for local