tee342 commited on
Commit
ab42cf3
ยท
verified ยท
1 Parent(s): 6301707

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -64
app.py CHANGED
@@ -26,22 +26,6 @@ import json
26
  # Suppress warnings
27
  warnings.filterwarnings("ignore")
28
 
29
- # Try importing speechbrain for remastering
30
- try:
31
- from speechbrain.inference.denoisers import SEEnhance
32
- except ImportError:
33
- print("Installing SpeechBrain...")
34
- import subprocess
35
- subprocess.run(["pip", "install", "speechbrain"])
36
- from speechbrain.inference.denoisers import SEEnhance
37
-
38
- # Load denoiser model (if available)
39
- try:
40
- enhancer = SEEnhance.from_hparams(source="speechbrain/reverb-wpe-wsj0-wsj0mix", savedir="remaster_model")
41
- except Exception as e:
42
- enhancer = None
43
- print("SpeechBrain model not available:", str(e))
44
-
45
  # === Helper Functions ===
46
  def audiosegment_to_array(audio):
47
  return np.array(audio.get_array_of_samples()), audio.frame_rate
@@ -414,7 +398,7 @@ def auto_tune_vocal(audio_path, target_key="C"):
414
  try:
415
  # Load audio
416
  audio = AudioSegment.from_file(audio_path)
417
-
418
  # Apply pitch correction
419
  semitones = key_to_semitone(target_key)
420
  tuned_audio = apply_pitch_shift(audio, semitones)
@@ -449,7 +433,7 @@ def visualize_spectrum(audio_path):
449
  buf.seek(0)
450
  return Image.open(buf)
451
 
452
- # === AI Remastering Tab โ€“ New Feature ===
453
  def ai_remaster(audio_path):
454
  try:
455
  # Step 1: Noise reduction
@@ -509,10 +493,6 @@ with gr.Blocks(css="""
509
  transition: all 0.3s ease;
510
  }
511
 
512
- .gr-box:hover, .gr-interface:hover {
513
- box-shadow: 0 0 15px #1f7bbd88;
514
- }
515
-
516
  .gr-button {
517
  background-color: #2563eb !important;
518
  color: white !important;
@@ -521,7 +501,6 @@ with gr.Blocks(css="""
521
  font-weight: bold;
522
  box-shadow: 0 0 10px #2563eb44;
523
  border: none;
524
- font-size: 16px;
525
  }
526
 
527
  .gr-button:hover {
@@ -529,21 +508,6 @@ with gr.Blocks(css="""
529
  box-shadow: 0 0 15px #3b82f6aa;
530
  }
531
 
532
- .gr-tabs button {
533
- font-size: 16px;
534
- padding: 10px 20px;
535
- border-radius: 8px;
536
- background: #1e293b;
537
- color: white;
538
- transition: all 0.3s ease;
539
- }
540
-
541
- .gr-tabs button:hover {
542
- background: #3b82f6;
543
- color: black;
544
- box-shadow: 0 0 10px #3b82f6aa;
545
- }
546
-
547
  input[type="text"], input[type="number"], select, textarea {
548
  background-color: #334155 !important;
549
  color: white !important;
@@ -607,7 +571,7 @@ with gr.Blocks(css="""
607
  }
608
  """) as demo:
609
 
610
- # Header with logo and tagline
611
  gr.HTML('''
612
  <div class="studio-header">
613
  <img src="logo.png" width="400" />
@@ -675,14 +639,14 @@ with gr.Blocks(css="""
675
  clear_btn=None
676
  )
677
 
678
- # --- AI Remastering Tab โ€“ Now Fixed & Working ===
679
  with gr.Tab("๐Ÿ”ฎ AI Remastering"):
680
  gr.Interface(
681
  fn=ai_remaster,
682
  inputs=gr.Audio(label="Upload Low-Quality Recording", type="filepath"),
683
  outputs=gr.Audio(label="Studio-Grade Output", type="filepath"),
684
  title="Transform Low-Quality Recordings to Studio Sound",
685
- description="Uses noise reduction, vocal isolation, and mastering to enhance old or low-quality audio."
686
  )
687
 
688
  # --- Harmonic Saturation / Exciter โ€“ Now Included ===
@@ -806,29 +770,6 @@ with gr.Blocks(css="""
806
  description="Load your saved session"
807
  )
808
 
809
- # --- Preset Cards Gallery โ€“ Visual Selection ===
810
- with gr.Tab("๐ŸŽ› Preset Gallery"):
811
- gr.Markdown("### Select a preset visually")
812
- preset_gallery = gr.Gallery(value=[
813
- ("https://picsum.photos/id/10/150/100", "Pop"),
814
- ("https://picsum.photos/id/20/150/100", "EDM"),
815
- ("https://picsum.photos/id/30/150/100", "Rock"),
816
- ("https://picsum.photos/id/40/150/100", "Hip-Hop"),
817
- ("https://picsum.photos/id/50/150/100", "R&B"),
818
- ("https://picsum.photos/id/60/150/100", "Soul"),
819
- ("https://picsum.photos/id/70/150/100", "Funk")
820
- ], label="Preset Cards", columns=4, height="auto")
821
-
822
- preset_name_out = gr.Dropdown(choices=preset_names, label="Selected Preset")
823
- preset_effects_out = gr.CheckboxGroup(choices=list(preset_choices["Default"]), label="Effects")
824
-
825
- def load_preset_by_card(evt: gr.SelectData):
826
- index = evt.index % len(preset_names)
827
- name = preset_names[index]
828
- return name, preset_choices[name]
829
-
830
- preset_gallery.select(fn=load_preset_by_card, inputs=[], outputs=[preset_name_out, preset_effects_out])
831
-
832
  # --- Prompt-Based Editing Tab โ€“ Added Back ===
833
  def process_prompt(audio, prompt):
834
  return apply_noise_reduction(audio)
 
26
  # Suppress warnings
27
  warnings.filterwarnings("ignore")
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  # === Helper Functions ===
30
  def audiosegment_to_array(audio):
31
  return np.array(audio.get_array_of_samples()), audio.frame_rate
 
398
  try:
399
  # Load audio
400
  audio = AudioSegment.from_file(audio_path)
401
+
402
  # Apply pitch correction
403
  semitones = key_to_semitone(target_key)
404
  tuned_audio = apply_pitch_shift(audio, semitones)
 
433
  buf.seek(0)
434
  return Image.open(buf)
435
 
436
+ # === AI Remastering Tab โ€“ New Feature (Without SpeechBrain) ===
437
  def ai_remaster(audio_path):
438
  try:
439
  # Step 1: Noise reduction
 
493
  transition: all 0.3s ease;
494
  }
495
 
 
 
 
 
496
  .gr-button {
497
  background-color: #2563eb !important;
498
  color: white !important;
 
501
  font-weight: bold;
502
  box-shadow: 0 0 10px #2563eb44;
503
  border: none;
 
504
  }
505
 
506
  .gr-button:hover {
 
508
  box-shadow: 0 0 15px #3b82f6aa;
509
  }
510
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
511
  input[type="text"], input[type="number"], select, textarea {
512
  background-color: #334155 !important;
513
  color: white !important;
 
571
  }
572
  """) as demo:
573
 
574
+ # Header
575
  gr.HTML('''
576
  <div class="studio-header">
577
  <img src="logo.png" width="400" />
 
639
  clear_btn=None
640
  )
641
 
642
+ # --- AI Remastering Tab โ€“ Now Fixed & Simplified ===
643
  with gr.Tab("๐Ÿ”ฎ AI Remastering"):
644
  gr.Interface(
645
  fn=ai_remaster,
646
  inputs=gr.Audio(label="Upload Low-Quality Recording", type="filepath"),
647
  outputs=gr.Audio(label="Studio-Grade Output", type="filepath"),
648
  title="Transform Low-Quality Recordings to Studio Sound",
649
+ description="Uses noise reduction, vocal isolation, and mastering to enhance old recordings."
650
  )
651
 
652
  # --- Harmonic Saturation / Exciter โ€“ Now Included ===
 
770
  description="Load your saved session"
771
  )
772
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
773
  # --- Prompt-Based Editing Tab โ€“ Added Back ===
774
  def process_prompt(audio, prompt):
775
  return apply_noise_reduction(audio)