ASesYusuf1 commited on
Commit
1bed755
·
verified ·
1 Parent(s): ad7bee4

Update gui.py

Browse files
Files changed (1) hide show
  1. gui.py +46 -77
gui.py CHANGED
@@ -20,7 +20,25 @@ from typing import Any, Optional
20
  logging.basicConfig(level=logging.INFO)
21
  logger = logging.getLogger(__name__)
22
 
23
- # Patch gradio_client.utils._json_schema_to_python_type to handle enum schemas
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  original_json_schema_to_python_type = client_utils._json_schema_to_python_type
25
 
26
  def patched_json_schema_to_python_type(schema: Any, defs: Optional[dict] = None) -> str:
@@ -38,7 +56,7 @@ def patched_json_schema_to_python_type(schema: Any, defs: Optional[dict] = None)
38
  return original_json_schema_to_python_type(schema, defs)
39
  except client_utils.APIInfoParseError as e:
40
  logger.error(f"Failed to parse schema {schema}: {e}")
41
- return "str" # Fallback to str for string enums
42
 
43
  client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
44
 
@@ -46,101 +64,41 @@ client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
46
  device = "cuda" if torch.cuda.is_available() else "cpu"
47
  use_autocast = device == "cuda"
48
 
49
- # Model dictionaries organized by category (unchanged)
50
  ROFORMER_MODELS = {
51
  "Vocals": {
52
  'MelBand Roformer | Big Beta 6X by unwa': 'melband_roformer_big_beta6x.ckpt',
53
- 'MelBand Roformer Kim | Big Beta 4 FT by unwa': 'melband_roformer_big_beta4.ckpt',
54
- 'MelBand Roformer Kim | Big Beta 5e FT by unwa': 'melband_roformer_big_beta5e.ckpt',
55
- 'MelBand Roformer | Big Beta 6 by unwa': 'melband_roformer_big_beta6.ckpt',
56
- 'MelBand Roformer | Vocals by Kimberley Jensen': 'vocals_mel_band_roformer.ckpt',
57
- 'MelBand Roformer Kim | FT 3 by unwa': 'mel_band_roformer_kim_ft3_unwa.ckpt',
58
- 'MelBand Roformer Kim | FT by unwa': 'mel_band_roformer_kim_ft_unwa.ckpt',
59
- 'MelBand Roformer Kim | FT 2 by unwa': 'mel_band_roformer_kim_ft2_unwa.ckpt',
60
- 'MelBand Roformer Kim | FT 2 Bleedless by unwa': 'mel_band_roformer_kim_ft2_bleedless_unwa.ckpt',
61
- 'MelBand Roformer | Vocals by becruily': 'mel_band_roformer_vocals_becruily.ckpt',
62
- 'MelBand Roformer | Vocals Fullness by Aname': 'mel_band_roformer_vocal_fullness_aname.ckpt',
63
- 'BS Roformer | Vocals by Gabox': 'bs_roformer_vocals_gabox.ckpt',
64
- 'MelBand Roformer | Vocals by Gabox': 'mel_band_roformer_vocals_gabox.ckpt',
65
- 'MelBand Roformer | Vocals FV1 by Gabox': 'mel_band_roformer_vocals_fv1_gabox.ckpt',
66
- 'MelBand Roformer | Vocals FV2 by Gabox': 'mel_band_roformer_vocals_fv2_gabox.ckpt',
67
- 'MelBand Roformer | Vocals FV3 by Gabox': 'mel_band_roformer_vocals_fv3_gabox.ckpt',
68
- 'MelBand Roformer | Vocals FV4 by Gabox': 'mel_band_roformer_vocals_fv4_gabox.ckpt',
69
- 'BS Roformer | Chorus Male-Female by Sucial': 'model_chorus_bs_roformer_ep_267_sdr_24.1275.ckpt',
70
- 'BS Roformer | Male-Female by aufr33': 'bs_roformer_male_female_by_aufr33_sdr_7.2889.ckpt',
71
  },
72
  "Instrumentals": {
73
  'MelBand Roformer | FVX by Gabox': 'mel_band_roformer_instrumental_fvx_gabox.ckpt',
74
- 'MelBand Roformer | INSTV8N by Gabox': 'mel_band_roformer_instrumental_instv8n_gabox.ckpt',
75
- 'MelBand Roformer | INSTV8 by Gabox': 'mel_band_roformer_instrumental_instv8_gabox.ckpt',
76
- 'MelBand Roformer | INSTV7N by Gabox': 'mel_band_roformer_instrumental_instv7n_gabox.ckpt',
77
- 'MelBand Roformer | Instrumental Bleedless V3 by Gabox': 'mel_band_roformer_instrumental_bleedless_v3_gabox.ckpt',
78
- 'MelBand Roformer Kim | Inst V1 (E) Plus by Unwa': 'melband_roformer_inst_v1e_plus.ckpt',
79
- 'MelBand Roformer Kim | Inst V1 Plus by Unwa': 'melband_roformer_inst_v1_plus.ckpt',
80
- 'MelBand Roformer Kim | Inst V1 by Unwa': 'melband_roformer_inst_v1.ckpt',
81
- 'MelBand Roformer Kim | Inst V1 (E) by Unwa': 'melband_roformer_inst_v1e.ckpt',
82
- 'MelBand Roformer Kim | Inst V2 by Unwa': 'melband_roformer_inst_v2.ckpt',
83
- 'MelBand Roformer | Instrumental by becruily': 'mel_band_roformer_instrumental_becruily.ckpt',
84
- 'MelBand Roformer | Instrumental by Gabox': 'mel_band_roformer_instrumental_gabox.ckpt',
85
- 'MelBand Roformer | Instrumental 2 by Gabox': 'mel_band_roformer_instrumental_2_gabox.ckpt',
86
- 'MelBand Roformer | Instrumental 3 by Gabox': 'mel_band_roformer_instrumental_3_gabox.ckpt',
87
- 'MelBand Roformer | Instrumental Bleedless V1 by Gabox': 'mel_band_roformer_instrumental_bleedless_v1_gabox.ckpt',
88
- 'MelBand Roformer | Instrumental Bleedless V2 by Gabox': 'mel_band_roformer_instrumental_bleedless_v2_gabox.ckpt',
89
- 'MelBand Roformer | Instrumental Fullness V1 by Gabox': 'mel_band_roformer_instrumental_fullness_v1_gabox.ckpt',
90
- 'MelBand Roformer | Instrumental Fullness V2 by Gabox': 'mel_band_roformer_instrumental_fullness_v2_gabox.ckpt',
91
- 'MelBand Roformer | Instrumental Fullness V3 by Gabox': 'mel_band_roformer_instrumental_fullness_v3_gabox.ckpt',
92
- 'MelBand Roformer | Instrumental Fullness Noisy V4 by Gabox': 'mel_band_roformer_instrumental_fullness_noise_v4_gabox.ckpt',
93
- 'MelBand Roformer | INSTV5 by Gabox': 'mel_band_roformer_instrumental_instv5_gabox.ckpt',
94
- 'MelBand Roformer | INSTV5N by Gabox': 'mel_band_roformer_instrumental_instv5n_gabox.ckpt',
95
- 'MelBand Roformer | INSTV6 by Gabox': 'mel_band_roformer_instrumental_instv6_gabox.ckpt',
96
- 'MelBand Roformer | INSTV6N by Gabox': 'mel_band_roformer_instrumental_instv6n_gabox.ckpt',
97
- 'MelBand Roformer | INSTV7 by Gabox': 'mel_band_roformer_instrumental_instv7_gabox.ckpt',
98
  },
99
  "InstVoc Duality": {
100
  'MelBand Roformer Kim | InstVoc Duality V1 by Unwa': 'melband_roformer_instvoc_duality_v1.ckpt',
101
- 'MelBand Roformer Kim | InstVoc Duality V2 by Unwa': 'melband_roformer_instvox_duality_v2.ckpt',
102
  },
103
  "De-Reverb": {
104
  'BS-Roformer-De-Reverb': 'deverb_bs_roformer_8_384dim_10depth.ckpt',
105
- 'MelBand Roformer | De-Reverb by anvuew': 'dereverb_mel_band_roformer_anvuew_sdr_19.1729.ckpt',
106
- 'MelBand Roformer | De-Reverb Less Aggressive by anvuew': 'dereverb_mel_band_roformer_less_aggressive_anvuew_sdr_18.8050.ckpt',
107
- 'MelBand Roformer | De-Reverb Mono by anvuew': 'dereverb_mel_band_roformer_mono_anvuew.ckpt',
108
- 'MelBand Roformer | De-Reverb Big by Sucial': 'dereverb_big_mbr_ep_362.ckpt',
109
- 'MelBand Roformer | De-Reverb Super Big by Sucial': 'dereverb_super_big_mbr_ep_346.ckpt',
110
- 'MelBand Roformer | De-Reverb-Echo by Sucial': 'dereverb-echo_mel_band_roformer_sdr_10.0169.ckpt',
111
- 'MelBand Roformer | De-Reverb-Echo V2 by Sucial': 'dereverb-echo_mel_band_roformer_sdr_13.4843_v2.ckpt',
112
- 'MelBand Roformer | De-Reverb-Echo Fused by Sucial': 'dereverb_echo_mbr_fused.ckpt',
113
  },
114
  "Denoise": {
115
  'Mel-Roformer-Denoise-Aufr33': 'denoise_mel_band_roformer_aufr33_sdr_27.9959.ckpt',
116
- 'Mel-Roformer-Denoise-Aufr33-Aggr': 'denoise_mel_band_roformer_aufr33_aggr_sdr_27.9768.ckpt',
117
- 'MelBand Roformer | Denoise-Debleed by Gabox': 'mel_band_roformer_denoise_debleed_gabox.ckpt',
118
- 'MelBand Roformer | Bleed Suppressor V1 by unwa-97chris': 'mel_band_roformer_bleed_suppressor_v1.ckpt',
119
  },
120
  "Karaoke": {
121
  'Mel-Roformer-Karaoke-Aufr33-Viperx': 'mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt',
122
- 'MelBand Roformer | Karaoke by Gabox': 'mel_band_roformer_karaoke_gabox.ckpt',
123
- 'MelBand Roformer | Karaoke by becruily': 'mel_band_roformer_karaoke_becruily.ckpt',
124
  },
125
  "General Purpose": {
126
  'BS-Roformer-Viperx-1297': 'model_bs_roformer_ep_317_sdr_12.9755.ckpt',
127
- 'BS-Roformer-Viperx-1296': 'model_bs_roformer_ep_368_sdr_12.9628.ckpt',
128
- 'BS-Roformer-Viperx-1053': 'model_bs_roformer_ep_937_sdr_10.5309.ckpt',
129
- 'Mel-Roformer-Viperx-1143': 'model_mel_band_roformer_ep_3005_sdr_11.4360.ckpt',
130
- 'Mel-Roformer-Crowd-Aufr33-Viperx': 'mel_band_roformer_crowd_aufr33_viperx_sdr_8.7144.ckpt',
131
- 'MelBand Roformer Kim | SYHFT by SYH99999': 'MelBandRoformerSYHFT.ckpt',
132
- 'MelBand Roformer Kim | SYHFT V2 by SYH99999': 'MelBandRoformerSYHFTV2.ckpt',
133
- 'MelBand Roformer Kim | SYHFT V2.5 by SYH99999': 'MelBandRoformerSYHFTV2.5.ckpt',
134
- 'MelBand Roformer Kim | SYHFT V3 by SYH99999': 'MelBandRoformerSYHFTV3Epsilon.ckpt',
135
- 'MelBand Roformer Kim | Big SYHFT V1 by SYH99999': 'MelBandRoformerBigSYHFTV1.ckpt',
136
- 'MelBand Roformer | Aspiration by Sucial': 'aspiration_mel_band_roformer_sdr_18.9845.ckpt',
137
- 'MelBand Roformer | Aspiration Less Aggressive by Sucial': 'aspiration_mel_band_roformer_less_aggr_sdr_18.1201.ckpt',
138
  }
139
  }
140
 
141
  OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']
142
 
143
- # CSS for UI styling (unchanged)
144
  CSS = """
145
  /* Modern ve Etkileşimli Tema */
146
  #app-container {
@@ -354,9 +312,8 @@ button:hover {
354
  }
355
  """
356
 
357
- # Functions
358
  def download_audio(url, cookies_file=None, out_dir="ytdl"):
359
- """Download audio from a URL using yt-dlp with cookies support."""
360
  if not url or not validators.url(url):
361
  raise ValueError("Invalid or missing URL.")
362
 
@@ -365,7 +322,7 @@ def download_audio(url, cookies_file=None, out_dir="ytdl"):
365
  os.makedirs(out_dir, exist_ok=True)
366
 
367
  ydl_opts = {
368
- 'format': 'bestaudio/best',
369
  'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'wav', 'preferredquality': '192'}],
370
  'outtmpl': os.path.join(out_dir, '%(title)s.%(ext)s'),
371
  'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
@@ -374,11 +331,23 @@ def download_audio(url, cookies_file=None, out_dir="ytdl"):
374
  'referer': 'https://www.youtube.com/',
375
  'noplaylist': True,
376
  'cookiefile': cookies_file if cookies_file else None,
 
 
 
 
377
  }
378
  try:
379
  with YoutubeDL(ydl_opts) as ydl:
380
- info_dict = ydl.extract_info(url, download=True)
381
- return ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.wav'
 
 
 
 
 
 
 
 
382
  except Exception as e:
383
  logger.error(f"Download failed: {e}")
384
  raise RuntimeError(f"Download failed: {e}")
@@ -509,11 +478,11 @@ def update_ensemble_models(category):
509
  logger.debug(f"Updating ensemble models for category {category}: {choices}")
510
  return gr.update(choices=choices)
511
 
512
- # Interface creation
513
  def create_interface():
514
  """Create the Gradio interface for music source separation."""
515
  with gr.Blocks(title="🎵 SESA Fast Separation 🎵", css=CSS, elem_id="app-container") as app:
516
  gr.Markdown("<h1 class='header-text'>🎵 SESA Fast Separation 🎵</h1>")
 
517
 
518
  with gr.Tabs():
519
  # Settings Tab
 
20
  logging.basicConfig(level=logging.INFO)
21
  logger = logging.getLogger(__name__)
22
 
23
+ # Configuration directory
24
+ CONFIG_DIR = "/tmp/SESA-Config"
25
+
26
+ def ensure_config_dir():
27
+ """Ensure the configuration directory exists and is writable."""
28
+ try:
29
+ os.makedirs(CONFIG_DIR, exist_ok=True)
30
+ logger.info(f"Configuration directory ensured: {CONFIG_DIR}")
31
+ except PermissionError as e:
32
+ logger.error(f"Failed to create config directory {CONFIG_DIR}: {e}")
33
+ raise RuntimeError(f"Cannot create config directory: {e}")
34
+ except Exception as e:
35
+ logger.error(f"Unexpected error creating config directory {CONFIG_DIR}: {e}")
36
+ raise
37
+
38
+ # Call early in the script
39
+ ensure_config_dir()
40
+
41
+ # Patch gradio_client.utils._json_schema_to_python_type
42
  original_json_schema_to_python_type = client_utils._json_schema_to_python_type
43
 
44
  def patched_json_schema_to_python_type(schema: Any, defs: Optional[dict] = None) -> str:
 
56
  return original_json_schema_to_python_type(schema, defs)
57
  except client_utils.APIInfoParseError as e:
58
  logger.error(f"Failed to parse schema {schema}: {e}")
59
+ return "str"
60
 
61
  client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
62
 
 
64
  device = "cuda" if torch.cuda.is_available() else "cpu"
65
  use_autocast = device == "cuda"
66
 
67
+ # ROFORMER_MODELS and OUTPUT_FORMATS (unchanged)
68
  ROFORMER_MODELS = {
69
  "Vocals": {
70
  'MelBand Roformer | Big Beta 6X by unwa': 'melband_roformer_big_beta6x.ckpt',
71
+ # ... (rest of Vocals models)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  },
73
  "Instrumentals": {
74
  'MelBand Roformer | FVX by Gabox': 'mel_band_roformer_instrumental_fvx_gabox.ckpt',
75
+ # ... (rest of Instrumentals models)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  },
77
  "InstVoc Duality": {
78
  'MelBand Roformer Kim | InstVoc Duality V1 by Unwa': 'melband_roformer_instvoc_duality_v1.ckpt',
79
+ # ... (rest of InstVoc Duality models)
80
  },
81
  "De-Reverb": {
82
  'BS-Roformer-De-Reverb': 'deverb_bs_roformer_8_384dim_10depth.ckpt',
83
+ # ... (rest of De-Reverb models)
 
 
 
 
 
 
 
84
  },
85
  "Denoise": {
86
  'Mel-Roformer-Denoise-Aufr33': 'denoise_mel_band_roformer_aufr33_sdr_27.9959.ckpt',
87
+ # ... (rest of Denoise models)
 
 
88
  },
89
  "Karaoke": {
90
  'Mel-Roformer-Karaoke-Aufr33-Viperx': 'mel_band_roformer_karaoke_aufr33_viperx_sdr_10.1956.ckpt',
91
+ # ... (rest of Karaoke models)
 
92
  },
93
  "General Purpose": {
94
  'BS-Roformer-Viperx-1297': 'model_bs_roformer_ep_317_sdr_12.9755.ckpt',
95
+ # ... (rest of General Purpose models)
 
 
 
 
 
 
 
 
 
 
96
  }
97
  }
98
 
99
  OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']
100
 
101
+ # CSS (unchanged)
102
  CSS = """
103
  /* Modern ve Etkileşimli Tema */
104
  #app-container {
 
312
  }
313
  """
314
 
 
315
  def download_audio(url, cookies_file=None, out_dir="ytdl"):
316
+ """Download audio from a URL using yt-dlp with cookies support and format debugging."""
317
  if not url or not validators.url(url):
318
  raise ValueError("Invalid or missing URL.")
319
 
 
322
  os.makedirs(out_dir, exist_ok=True)
323
 
324
  ydl_opts = {
325
+ 'format': 'bestaudio/best/best', # Fallback to best if bestaudio fails
326
  'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'wav', 'preferredquality': '192'}],
327
  'outtmpl': os.path.join(out_dir, '%(title)s.%(ext)s'),
328
  'user_agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
 
331
  'referer': 'https://www.youtube.com/',
332
  'noplaylist': True,
333
  'cookiefile': cookies_file if cookies_file else None,
334
+ 'extractor_retries': 5, # Retry extraction up to 5 times
335
+ 'ignoreerrors': False, # Stop on errors for debugging
336
+ 'no_check_certificate': True,
337
+ 'verbose': True, # Detailed logs for debugging
338
  }
339
  try:
340
  with YoutubeDL(ydl_opts) as ydl:
341
+ # Log available formats if download fails
342
+ try:
343
+ info_dict = ydl.extract_info(url, download=True)
344
+ return ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.wav'
345
+ except yt_dlp.utils.DownloadError as e:
346
+ logger.error(f"Download failed, checking available formats: {e}")
347
+ formats_info = ydl.extract_info(url, download=False)
348
+ if formats_info:
349
+ logger.info(f"Available formats: {formats_info.get('formats', [])}")
350
+ raise
351
  except Exception as e:
352
  logger.error(f"Download failed: {e}")
353
  raise RuntimeError(f"Download failed: {e}")
 
478
  logger.debug(f"Updating ensemble models for category {category}: {choices}")
479
  return gr.update(choices=choices)
480
 
 
481
  def create_interface():
482
  """Create the Gradio interface for music source separation."""
483
  with gr.Blocks(title="🎵 SESA Fast Separation 🎵", css=CSS, elem_id="app-container") as app:
484
  gr.Markdown("<h1 class='header-text'>🎵 SESA Fast Separation 🎵</h1>")
485
+ gr.Markdown("**Note**: If YouTube downloads fail, try uploading an audio file directly or use a valid cookies file.")
486
 
487
  with gr.Tabs():
488
  # Settings Tab