ASesYusuf1 commited on
Commit
67568d2
Β·
verified Β·
1 Parent(s): 88bba59

Update gui.py

Browse files
Files changed (1) hide show
  1. gui.py +17 -25
gui.py CHANGED
@@ -46,7 +46,7 @@ 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
50
  ROFORMER_MODELS = {
51
  "Vocals": {
52
  'MelBand Roformer | Big Beta 6X by unwa': 'melband_roformer_big_beta6x.ckpt',
@@ -120,7 +120,7 @@ ROFORMER_MODELS = {
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',
@@ -140,7 +140,7 @@ ROFORMER_MODELS = {
140
 
141
  OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']
142
 
143
- # CSS for UI styling (unchanged from previous)
144
  CSS = """
145
  /* Modern ve Etkileşimli Tema */
146
  #app-container {
@@ -355,8 +355,8 @@ button:hover {
355
  """
356
 
357
  # Functions
358
- def download_audio(url, out_dir="ytdl"):
359
- """Download audio from a URL using yt-dlp."""
360
  if not url or not validators.url(url):
361
  raise ValueError("Invalid or missing URL.")
362
 
@@ -368,10 +368,15 @@ def download_audio(url, out_dir="ytdl"):
368
  'format': 'bestaudio/best',
369
  'postprocessors': [{'key': 'FFmpegExtractAudio', 'preferredcodec': 'wav', 'preferredquality': '192'}],
370
  'outtmpl': os.path.join(out_dir, '%(title)s.%(ext)s'),
 
 
 
 
 
 
371
  }
372
  try:
373
  with YoutubeDL(ydl_opts) as ydl:
374
- ydl.download([url])
375
  info_dict = ydl.extract_info(url, download=True)
376
  return ydl.prepare_filename(info_dict).rsplit('.', 1)[0] + '.wav'
377
  except Exception as e:
@@ -516,7 +521,7 @@ def create_interface():
516
  with gr.Group(elem_classes="dubbing-theme"):
517
  gr.Markdown("### General Settings")
518
  model_file_dir = gr.Textbox(value="/tmp/audio-separator-models/", label="πŸ“‚ Model Cache", placeholder="Path to model directory", interactive=True)
519
- output_dir = gr.Textbox(value="output+*6", label="πŸ“€ Output Directory", placeholder="Where to save results", interactive=True)
520
  output_format = gr.Dropdown(value="wav", choices=OUTPUT_FORMATS, label="🎢 Output Format", interactive=True)
521
  norm_threshold = gr.Slider(0.1, 1.0, value=0.9, step=0.1, label="πŸ”Š Normalization Threshold", interactive=True)
522
  amp_threshold = gr.Slider(0.1, 1.0, value=0.3, step=0.1, label="πŸ“ˆ Amplification Threshold", interactive=True)
@@ -529,6 +534,7 @@ def create_interface():
529
  with gr.Row():
530
  roformer_audio = gr.Audio(label="🎧 Upload Audio", type="filepath", interactive=True)
531
  url_ro = gr.Textbox(label="πŸ”— Or Paste URL", placeholder="YouTube or audio URL", interactive=True)
 
532
  download_roformer = gr.Button("⬇️ Download", variant="secondary")
533
  roformer_exclude_stems = gr.Textbox(label="🚫 Exclude Stems", placeholder="e.g., vocals, drums (comma-separated)", interactive=True)
534
  with gr.Row():
@@ -552,6 +558,7 @@ def create_interface():
552
  with gr.Row():
553
  ensemble_audio = gr.Audio(label="🎧 Upload Audio", type="filepath", interactive=True)
554
  url_ensemble = gr.Textbox(label="πŸ”— Or Paste URL", placeholder="YouTube or audio URL", interactive=True)
 
555
  download_ensemble = gr.Button("⬇️ Download", variant="secondary")
556
  ensemble_exclude_stems = gr.Textbox(label="🚫 Exclude Stems", placeholder="e.g., vocals, drums (comma-separated)", interactive=True)
557
  with gr.Row():
@@ -571,7 +578,7 @@ def create_interface():
571
 
572
  # Event Handlers
573
  roformer_category.change(update_roformer_models, inputs=[roformer_category], outputs=[roformer_model])
574
- download_roformer.click(fn=download_audio, inputs=[url_ro], outputs=[roformer_audio])
575
  roformer_button.click(
576
  roformer_separator,
577
  inputs=[
@@ -582,7 +589,7 @@ def create_interface():
582
  outputs=[roformer_stem1, roformer_stem2]
583
  )
584
  ensemble_category.change(update_ensemble_models, inputs=[ensemble_category], outputs=[ensemble_models])
585
- download_ensemble.click(fn=download_audio, inputs=[url_ensemble], outputs=[ensemble_audio])
586
  ensemble_button.click(
587
  fn=auto_ensemble_process,
588
  inputs=[
@@ -594,19 +601,4 @@ def create_interface():
594
  outputs=[ensemble_output, ensemble_status]
595
  )
596
 
597
- return app
598
-
599
- if __name__ == "__main__":
600
- parser = argparse.ArgumentParser(description="Music Source Separation Web UI")
601
- parser.add_argument("--port", type=int, default=7860, help="Port to run the UI on")
602
- args = parser.parse_args()
603
-
604
- app = create_interface()
605
- try:
606
- # For Hugging Face Spaces
607
- app.launch(server_name="0.0.0.0", server_port=args.port, share=True)
608
- except Exception as e:
609
- logger.error(f"Failed to launch app: {e}")
610
- raise
611
- finally:
612
- app.close()
 
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',
 
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',
 
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 {
 
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
 
 
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',
372
+ 'geo_bypass': True,
373
+ 'force_ipv4': True,
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:
 
521
  with gr.Group(elem_classes="dubbing-theme"):
522
  gr.Markdown("### General Settings")
523
  model_file_dir = gr.Textbox(value="/tmp/audio-separator-models/", label="πŸ“‚ Model Cache", placeholder="Path to model directory", interactive=True)
524
+ output_dir = gr.Textbox(value="output", label="πŸ“€ Output Directory", placeholder="Where to save results", interactive=True)
525
  output_format = gr.Dropdown(value="wav", choices=OUTPUT_FORMATS, label="🎢 Output Format", interactive=True)
526
  norm_threshold = gr.Slider(0.1, 1.0, value=0.9, step=0.1, label="πŸ”Š Normalization Threshold", interactive=True)
527
  amp_threshold = gr.Slider(0.1, 1.0, value=0.3, step=0.1, label="πŸ“ˆ Amplification Threshold", interactive=True)
 
534
  with gr.Row():
535
  roformer_audio = gr.Audio(label="🎧 Upload Audio", type="filepath", interactive=True)
536
  url_ro = gr.Textbox(label="πŸ”— Or Paste URL", placeholder="YouTube or audio URL", interactive=True)
537
+ cookies_ro = gr.File(label="πŸͺ Cookies File", file_types=[".txt"], interactive=True)
538
  download_roformer = gr.Button("⬇️ Download", variant="secondary")
539
  roformer_exclude_stems = gr.Textbox(label="🚫 Exclude Stems", placeholder="e.g., vocals, drums (comma-separated)", interactive=True)
540
  with gr.Row():
 
558
  with gr.Row():
559
  ensemble_audio = gr.Audio(label="🎧 Upload Audio", type="filepath", interactive=True)
560
  url_ensemble = gr.Textbox(label="πŸ”— Or Paste URL", placeholder="YouTube or audio URL", interactive=True)
561
+ cookies_ensemble = gr.File(label="πŸͺ Cookies File", file_types=[".txt"], interactive=True)
562
  download_ensemble = gr.Button("⬇️ Download", variant="secondary")
563
  ensemble_exclude_stems = gr.Textbox(label="🚫 Exclude Stems", placeholder="e.g., vocals, drums (comma-separated)", interactive=True)
564
  with gr.Row():
 
578
 
579
  # Event Handlers
580
  roformer_category.change(update_roformer_models, inputs=[roformer_category], outputs=[roformer_model])
581
+ download_roformer.click(fn=download_audio, inputs=[url_ro, cookies_ro], outputs=[roformer_audio])
582
  roformer_button.click(
583
  roformer_separator,
584
  inputs=[
 
589
  outputs=[roformer_stem1, roformer_stem2]
590
  )
591
  ensemble_category.change(update_ensemble_models, inputs=[ensemble_category], outputs=[ensemble_models])
592
+ download_ensemble.click(fn=download_audio, inputs=[url_ensemble, cookies_ensemble], outputs=[ensemble_audio])
593
  ensemble_button.click(
594
  fn=auto_ensemble_process,
595
  inputs=[
 
601
  outputs=[ensemble_output, ensemble_status]
602
  )
603
 
604
+ return app