tee342 commited on
Commit
0b9c3a0
Β·
verified Β·
1 Parent(s): 9ce4a0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -18
app.py CHANGED
@@ -27,6 +27,23 @@ import soundfile as sf
27
  # Suppress warnings
28
  warnings.filterwarnings("ignore")
29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  # === Helper Functions ===
31
  def audiosegment_to_array(audio):
32
  return np.array(audio.get_array_of_samples()), audio.frame_rate
@@ -231,7 +248,8 @@ def process_audio(audio_file, selected_effects, isolate_vocals, preset_name, exp
231
  audio = AudioSegment.from_file(audio_file)
232
  status = "πŸ›  Applying effects..."
233
 
234
- effect_map = {
 
235
  "Noise Reduction": apply_noise_reduction,
236
  "Compress Dynamic Range": apply_compression,
237
  "Add Reverb": apply_reverb,
@@ -249,8 +267,8 @@ def process_audio(audio_file, selected_effects, isolate_vocals, preset_name, exp
249
 
250
  effects_to_apply = selected_effects
251
  for effect_name in effects_to_apply:
252
- if effect_name in effect_map:
253
- audio = effect_map[effect_name](audio)
254
 
255
  status = "πŸ’Ύ Saving final audio..."
256
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
@@ -412,7 +430,7 @@ def ai_remaster(audio_path):
412
  def apply_effects_to_stem(stem_path, selected_effects):
413
  try:
414
  audio = AudioSegment.from_file(stem_path)
415
- effect_map = {
416
  "Noise Reduction": apply_noise_reduction,
417
  "Normalize": apply_normalize,
418
  "Add Reverb": apply_reverb,
@@ -426,8 +444,8 @@ def apply_effects_to_stem(stem_path, selected_effects):
426
  }
427
 
428
  for effect_name in selected_effects:
429
- if effect_name in effect_map:
430
- audio = effect_map[effect_name](audio)
431
 
432
  out_path = os.path.join(tempfile.gettempdir(), f"remixed_{Path(stem_path).stem}_processed.wav")
433
  audio.export(out_path, format="wav")
@@ -442,15 +460,15 @@ def live_effect_preview(stream, selected_effect):
442
  try:
443
  samples, sr = stream
444
  audio = array_to_audiosegment(samples, sr, channels=1)
445
- effect_map = {
446
  "Reverb": apply_reverb,
447
  "Pitch Shift": lambda x: apply_pitch_shift(x),
448
  "Saturation": lambda x: harmonic_saturation(x, saturation_type="Tube", intensity=0.2),
449
  "Normalize": apply_normalize
450
  }
451
 
452
- if selected_effect in effect_map:
453
- processed = effect_map[selected_effect](audio)
454
  else:
455
  processed = audio
456
 
@@ -512,7 +530,7 @@ def harmonic_saturation(audio, saturation_type="Tube", intensity=0.2):
512
 
513
  return array_to_audiosegment(saturated.astype(np.int16), audio.frame_rate, channels=audio.channels)
514
 
515
- # --- Multi-track Mixing Console – Now Simplified ===
516
  def mix_tracks(track1_path, track2_path, vol1, vol2):
517
  seg1 = AudioSegment.from_file(track1_path) * vol1
518
  seg2 = AudioSegment.from_file(track2_path) * vol2
@@ -754,8 +772,7 @@ with gr.Blocks(css="""
754
  ],
755
  outputs=gr.Audio(label="EQ-Enhanced Output", type="filepath"),
756
  title="Custom EQ by Genre",
757
- description="Apply genre-based EQ filtering",
758
- allow_flagging="never"
759
  )
760
 
761
  # --- Voice Command Mode ===
@@ -764,8 +781,8 @@ with gr.Blocks(css="""
764
  fn=voice_to_effect,
765
  inputs=gr.Textbox(label="Describe What You Want", lines=5),
766
  outputs=gr.CheckboxGroup(choices=list(effect_map.keys())),
767
- title="Tell Us What You Want – We’ll Apply It",
768
- description="Say things like 'add reverb' or 'boost bass'"
769
  )
770
 
771
  # --- Multi-track Mixing Console – Now Fixed ===
@@ -780,8 +797,7 @@ with gr.Blocks(css="""
780
  ],
781
  outputs=gr.Audio(label="Mixed Output", type="filepath"),
782
  title="Mix Two Tracks",
783
- description="Upload two tracks and adjust volume sliders",
784
- allow_flagging="never"
785
  )
786
 
787
  # --- AI Suggest Effects Based on Genre ===
@@ -792,7 +808,7 @@ with gr.Blocks(css="""
792
  outputs=gr.CheckboxGroup(choices=preset_choices["Default"], label="Suggested Effects")
793
  )
794
 
795
- # --- Time-Stretch & Beat Matching ===
796
  with gr.Tab("⏱ Time-Stretch & BPM Match"):
797
  gr.Interface(
798
  fn=stretch_to_bpm,
@@ -802,7 +818,7 @@ with gr.Blocks(css="""
802
  ],
803
  outputs=gr.Audio(label="Stretched Output", type="filepath"),
804
  title="Match Track to BPM",
805
- description="Stretch audio to match a specific tempo"
806
  )
807
 
808
  demo.launch()
 
27
  # Suppress warnings
28
  warnings.filterwarnings("ignore")
29
 
30
+ # === Effect Map (Now Global) ===
31
+ effect_map = {
32
+ "Noise Reduction": "apply_noise_reduction",
33
+ "Compress Dynamic Range": "apply_compression",
34
+ "Add Reverb": "apply_reverb",
35
+ "Pitch Shift": "apply_pitch_shift",
36
+ "Echo": "apply_echo",
37
+ "Stereo Widening": "apply_stereo_widen",
38
+ "Bass Boost": "apply_bass_boost",
39
+ "Treble Boost": "apply_treble_boost",
40
+ "Normalize": "apply_normalize",
41
+ "Limiter": "apply_limiter",
42
+ "Auto Gain": "apply_auto_gain",
43
+ "Vocal Distortion": "apply_vocal_distortion",
44
+ "Stage Mode": "apply_stage_mode"
45
+ }
46
+
47
  # === Helper Functions ===
48
  def audiosegment_to_array(audio):
49
  return np.array(audio.get_array_of_samples()), audio.frame_rate
 
248
  audio = AudioSegment.from_file(audio_file)
249
  status = "πŸ›  Applying effects..."
250
 
251
+ global effect_map_real
252
+ effect_map_real = {
253
  "Noise Reduction": apply_noise_reduction,
254
  "Compress Dynamic Range": apply_compression,
255
  "Add Reverb": apply_reverb,
 
267
 
268
  effects_to_apply = selected_effects
269
  for effect_name in effects_to_apply:
270
+ if effect_name in effect_map_real:
271
+ audio = effect_map_real[effect_name](audio)
272
 
273
  status = "πŸ’Ύ Saving final audio..."
274
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
 
430
  def apply_effects_to_stem(stem_path, selected_effects):
431
  try:
432
  audio = AudioSegment.from_file(stem_path)
433
+ effect_map_real = {
434
  "Noise Reduction": apply_noise_reduction,
435
  "Normalize": apply_normalize,
436
  "Add Reverb": apply_reverb,
 
444
  }
445
 
446
  for effect_name in selected_effects:
447
+ if effect_name in effect_map_real:
448
+ audio = effect_map_real[effect_name](audio)
449
 
450
  out_path = os.path.join(tempfile.gettempdir(), f"remixed_{Path(stem_path).stem}_processed.wav")
451
  audio.export(out_path, format="wav")
 
460
  try:
461
  samples, sr = stream
462
  audio = array_to_audiosegment(samples, sr, channels=1)
463
+ effect_map_real = {
464
  "Reverb": apply_reverb,
465
  "Pitch Shift": lambda x: apply_pitch_shift(x),
466
  "Saturation": lambda x: harmonic_saturation(x, saturation_type="Tube", intensity=0.2),
467
  "Normalize": apply_normalize
468
  }
469
 
470
+ if selected_effect in effect_map_real:
471
+ processed = effect_map_real[selected_effect](audio)
472
  else:
473
  processed = audio
474
 
 
530
 
531
  return array_to_audiosegment(saturated.astype(np.int16), audio.frame_rate, channels=audio.channels)
532
 
533
+ # --- Multi-track Mixing Console – Now Fixed ===
534
  def mix_tracks(track1_path, track2_path, vol1, vol2):
535
  seg1 = AudioSegment.from_file(track1_path) * vol1
536
  seg2 = AudioSegment.from_file(track2_path) * vol2
 
772
  ],
773
  outputs=gr.Audio(label="EQ-Enhanced Output", type="filepath"),
774
  title="Custom EQ by Genre",
775
+ description="Apply custom EQ based on genre"
 
776
  )
777
 
778
  # --- Voice Command Mode ===
 
781
  fn=voice_to_effect,
782
  inputs=gr.Textbox(label="Describe What You Want", lines=5),
783
  outputs=gr.CheckboxGroup(choices=list(effect_map.keys())),
784
+ title="Tell Us What You Want – We'll Apply It",
785
+ description="Say things like 'remove noise' or 'boost bass'"
786
  )
787
 
788
  # --- Multi-track Mixing Console – Now Fixed ===
 
797
  ],
798
  outputs=gr.Audio(label="Mixed Output", type="filepath"),
799
  title="Mix Two Tracks",
800
+ description="Upload two tracks and adjust volume sliders"
 
801
  )
802
 
803
  # --- AI Suggest Effects Based on Genre ===
 
808
  outputs=gr.CheckboxGroup(choices=preset_choices["Default"], label="Suggested Effects")
809
  )
810
 
811
+ # --- Time-Stretch & BPM Match ===
812
  with gr.Tab("⏱ Time-Stretch & BPM Match"):
813
  gr.Interface(
814
  fn=stretch_to_bpm,
 
818
  ],
819
  outputs=gr.Audio(label="Stretched Output", type="filepath"),
820
  title="Match Track to BPM",
821
+ description="Stretch audio to match target tempo"
822
  )
823
 
824
  demo.launch()