tee342 commited on
Commit
f8d969c
·
verified ·
1 Parent(s): ab42cf3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +109 -28
app.py CHANGED
@@ -55,7 +55,7 @@ def apply_reverb(audio):
55
  return audio.overlay(reverb, position=1000)
56
 
57
  def apply_pitch_shift(audio, semitones=-2):
58
- new_frame_rate = int(audio.frame_rate * (2 ** (semitones / 12)))
59
  samples = np.array(audio.get_array_of_samples())
60
  resampled = np.interp(np.arange(0, len(samples), 2 ** (semitones / 12)), np.arange(len(samples)), samples).astype(np.int16)
61
  return AudioSegment(resampled.tobytes(), frame_rate=new_frame_rate, sample_width=audio.sample_width, channels=audio.channels)
@@ -398,7 +398,7 @@ def auto_tune_vocal(audio_path, target_key="C"):
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)
@@ -458,7 +458,43 @@ def ai_remaster(audio_path):
458
  print(f"Remastering Error: {str(e)}")
459
  return None
460
 
461
- # === Main UI – With Studio Pulse Branding ===
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
462
  with gr.Blocks(css="""
463
  body {
464
  font-family: 'Segoe UI', sans-serif;
@@ -571,7 +607,7 @@ with gr.Blocks(css="""
571
  }
572
  """) as demo:
573
 
574
- # Header
575
  gr.HTML('''
576
  <div class="studio-header">
577
  <img src="logo.png" width="400" />
@@ -622,32 +658,77 @@ with gr.Blocks(css="""
622
  allow_flagging="never"
623
  )
624
 
625
- # --- Remix Mode – Stem Splitting ===
626
  with gr.Tab("🎛 Remix Mode"):
627
- gr.Interface(
628
- fn=stem_split,
629
- inputs=gr.Audio(label="Upload Music Track", type="filepath"),
630
- outputs=[
631
- gr.File(label="Vocals"),
632
- gr.File(label="Drums"),
633
- gr.File(label="Bass"),
634
- gr.File(label="Other")
635
- ],
636
- title="Split Into Drums, Bass, Vocals, and More",
637
- description="Use AI to separate musical elements like vocals, drums, and bass.",
638
- flagging_mode="never",
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 ===
653
  with gr.Tab("🧬 Harmonic Saturation"):
 
55
  return audio.overlay(reverb, position=1000)
56
 
57
  def apply_pitch_shift(audio, semitones=-2):
58
+ new_frame_rate = int(audio.frame_rate * (2 ** (semitones / 12))
59
  samples = np.array(audio.get_array_of_samples())
60
  resampled = np.interp(np.arange(0, len(samples), 2 ** (semitones / 12)), np.arange(len(samples)), samples).astype(np.int16)
61
  return AudioSegment(resampled.tobytes(), frame_rate=new_frame_rate, sample_width=audio.sample_width, channels=audio.channels)
 
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)
 
458
  print(f"Remastering Error: {str(e)}")
459
  return None
460
 
461
+ # === Apply Effects to Stems ===
462
+ def apply_effects_to_stem(stem_path, selected_effects):
463
+ try:
464
+ audio = AudioSegment.from_file(stem_path)
465
+ effect_map = {
466
+ "Noise Reduction": apply_noise_reduction,
467
+ "Normalize": apply_normalize,
468
+ "Add Reverb": apply_reverb,
469
+ "Bass Boost": apply_bass_boost,
470
+ "Treble Boost": apply_treble_boost,
471
+ "Stereo Widening": apply_stereo_widen,
472
+ "Limiter": lambda x: apply_limiter(x, limit_dB=-1),
473
+ "Compress Dynamic Range": apply_compression,
474
+ "Noise Gate": lambda x: apply_noise_gate(x, threshold=-50.0),
475
+ "Bitcrusher": lambda x: apply_bitcrush(x, bit_depth=8),
476
+ "Auto Gain": lambda x: apply_auto_gain(x, target_dB=-20),
477
+ "Vocal Distortion": lambda x: apply_vocal_distortion(x),
478
+ "Stage Mode": apply_stage_mode
479
+ }
480
+
481
+ for effect_name in selected_effects:
482
+ if effect_name in effect_map:
483
+ audio = effect_map[effect_name](audio)
484
+
485
+ out_path = os.path.join(tempfile.gettempdir(), f"remixed_{Path(stem_path).stem}_processed.wav")
486
+ audio.export(out_path, format="wav")
487
+ return out_path
488
+
489
+ except Exception as e:
490
+ print(f"Error applying effects: {e}")
491
+ return None
492
+
493
+ # === Remix Mode – Apply Effects to Each Stem ===
494
+ def remix_individual_stem(stem_path, effects):
495
+ return apply_effects_to_stem(stem_path, effects)
496
+
497
+ # --- Main UI ---
498
  with gr.Blocks(css="""
499
  body {
500
  font-family: 'Segoe UI', sans-serif;
 
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" />
 
658
  allow_flagging="never"
659
  )
660
 
661
+ # --- Remix Mode – Stem Splitting + Effects ===
662
  with gr.Tab("🎛 Remix Mode"):
663
+ with gr.Row():
664
+ with gr.Column(min_width=200):
665
+ input_audio_remix = gr.Audio(label="Upload Music Track", type="filepath")
666
+ split_button = gr.Button("Split & Load")
667
+ with gr.Column(min_width=400):
668
+ stem_outputs = [
669
+ gr.File(label="Vocals"),
670
+ gr.File(label="Drums"),
671
+ gr.File(label="Bass"),
672
+ gr.File(label="Other")
673
+ ]
674
+
675
+ split_button.click(fn=stem_split, inputs=[input_audio_remix], outputs=stem_outputs)
676
+
677
+ gr.Markdown("#### Apply Effects to Individual Stems")
678
+ with gr.Row():
679
+ with gr.Column(min_width=200):
680
+ vocals_path = gr.File(label="Vocals Track")
681
+ vocal_effects = gr.CheckboxGroup([
682
+ "Noise Reduction",
683
+ "Normalize",
684
+ "Bass Boost",
685
+ "Treble Boost",
686
+ "Reverb",
687
+ "Vocal Distortion",
688
+ "Auto Gain"
689
+ ])
690
+ btn_vocals = gr.Button("Process Vocals")
691
+ output_vocals = gr.Audio(label="Processed Vocals", type="filepath")
692
 
693
+ btn_vocals.click(fn=remix_individual_stem, inputs=[vocals_path, vocal_effects], outputs=output_vocals)
694
+
695
+ with gr.Column(min_width=200):
696
+ drums_path = gr.File(label="Drums Track")
697
+ drum_effects = gr.CheckboxGroup([
698
+ "Bass Boost",
699
+ "Compress Dynamic Range",
700
+ "Limiter",
701
+ "Bitcrusher",
702
+ "Stereo Widening"
703
+ ])
704
+ btn_drums = gr.Button("Process Drums")
705
+ output_drums = gr.Audio(label="Processed Drums", type="filepath")
706
+
707
+ btn_drums.click(fn=remix_individual_stem, inputs=[drums_path, drum_effects], outputs=output_drums)
708
+
709
+ with gr.Column(min_width=200):
710
+ bass_path = gr.File(label="Bass Track")
711
+ bass_effects = gr.CheckboxGroup([
712
+ "Bass Boost",
713
+ "Saturation (Tape)",
714
+ "Limiter"
715
+ ])
716
+ btn_bass = gr.Button("Process Bass")
717
+ output_bass = gr.Audio(label="Processed Bass", type="filepath")
718
+
719
+ btn_bass.click(fn=remix_individual_stem, inputs=[bass_path, bass_effects], outputs=output_bass)
720
+
721
+ with gr.Column(min_width=200):
722
+ other_path = gr.File(label="Other Track")
723
+ other_effects = gr.CheckboxGroup([
724
+ "Noise Gate",
725
+ "Reverb",
726
+ "Treble Boost"
727
+ ])
728
+ btn_other = gr.Button("Process Other")
729
+ output_other = gr.Audio(label="Processed Other", type="filepath")
730
+
731
+ btn_other.click(fn=remix_individual_stem, inputs=[other_path, other_effects], outputs=output_other)
732
 
733
  # --- Harmonic Saturation / Exciter – Now Included ===
734
  with gr.Tab("🧬 Harmonic Saturation"):