tee342 commited on
Commit
564e980
Β·
verified Β·
1 Parent(s): b9afa4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -59
app.py CHANGED
@@ -23,9 +23,6 @@ import base64
23
  import pickle
24
  import json
25
  import soundfile as sf
26
- import wave
27
- import struct
28
- from moviepy.editor import VideoFileClip, AudioFileClip
29
 
30
  # Suppress warnings
31
  warnings.filterwarnings("ignore")
@@ -552,7 +549,7 @@ def clone_voice(source_audio, reference_audio):
552
  mixed.export(out_path, format="wav")
553
  return out_path
554
 
555
- # === AI Remastering – Now Working! ===
556
  def ai_remaster(audio_path):
557
  try:
558
  audio = AudioSegment.from_file(audio_path)
@@ -578,7 +575,10 @@ def ai_mastering_chain(audio_path, genre="Pop", target_lufs=-14.0):
578
  return out_path
579
 
580
  # === Generate PDF Report ===
581
- from fpdf import FPDF
 
 
 
582
 
583
  class PDFReport(FPDF):
584
  def header(self):
@@ -594,50 +594,6 @@ def export_session_report(session_data):
594
  pdf.output(out_path)
595
  return out_path
596
 
597
- # === Video Sync Mode – Extract and re-sync audio ===
598
- def extract_audio_from_video(video_path):
599
- clip = VideoFileClip(video_path)
600
- out_path = os.path.join(tempfile.gettempdir(), "video_audio.wav")
601
- clip.audio.write_audiofile(out_path)
602
- return out_path
603
-
604
- def re_sync_audio(video_path, edited_audio_path):
605
- original_clip = VideoFileClip(video_path)
606
- edited_audio = AudioSegment.from_file(edited_audio_path)
607
- temp_audio_path = os.path.join(tempfile.gettempdir(), "temp_edited.mp3")
608
- edited_audio.export(temp_audio_path, format="mp3")
609
- final_clip = original_clip.set_audio(temp_audio_path)
610
- out_path = os.path.join(tempfile.gettempdir(), "final_video.mp4")
611
- final_clip.write_videofile(out_path, codec="libx264", audio_codec="aac")
612
- return out_path
613
-
614
- # === Sidechain Compression / Ducking ===
615
- def sidechain_ducking(background, voice, threshold=-16, ratio=4):
616
- bg_samples, bg_sr = audiosegment_to_array(background)
617
- voice_samples, v_sr = audiosegment_to_array(voice)
618
- if bg_sr != v_sr:
619
- voice_samples = librosa.resample(voice_samples, orig_sr=v_sr, target_sr=bg_sr)
620
- bg_rms = np.sqrt(np.mean(bg_samples ** 2))
621
- voice_rms = np.sqrt(np.mean(voice_samples ** 2))
622
- if voice_rms > bg_rms * threshold / 100:
623
- bg_samples = bg_samples * ratio
624
- return array_to_audiosegment(bg_samples.astype(np.int16), bg_sr, channels=background.channels)
625
-
626
- # === Effect Chains Marketplace ===
627
- def publish_effect_chain(chain_json, name, tags):
628
- chain_id = base64.b64encode(chain_json.encode()).decode()
629
- return {
630
- "id": chain_id,
631
- "name": name,
632
- "tags": tags
633
- }
634
-
635
- def search_effect_chains(query):
636
- return [
637
- {"name": "Radio Ready", "tags": ["loudness", "bass", "treble"]},
638
- {"name": "Clean Vocal", "tags": ["noise", "normalize"]}
639
- ]
640
-
641
  # === Main UI – With Studio Pulse Branding ===
642
  with gr.Blocks(css="""
643
  body {
@@ -916,9 +872,7 @@ with gr.Blocks(css="""
916
  gr.Interface(
917
  fn=visualize_spectrum,
918
  inputs=gr.Audio(label="Upload Track", type="filepath"),
919
- outputs=gr.Image(label="Spectrum Analysis"),
920
- title="Real-Time Spectrum Analyzer",
921
- description="See the frequency breakdown of your audio"
922
  )
923
 
924
  # --- Loudness Graph Tab – EBU R128 Matching ===
@@ -1074,7 +1028,7 @@ with gr.Blocks(css="""
1074
  allow_flagging="never"
1075
  )
1076
 
1077
- # --- Loop Section ===
1078
  with gr.Tab("πŸ” Loop Playback"):
1079
  gr.Interface(
1080
  fn=loop_section,
@@ -1114,14 +1068,11 @@ with gr.Blocks(css="""
1114
  ### Keyboard Controls
1115
  - `Ctrl + Z`: Undo last effect
1116
  - `Ctrl + Y`: Redo
1117
- - `Spacebar`: Play/Stop
1118
- - `Ctrl + S`: Save session
1119
  - `Ctrl + O`: Open session
1120
  - `Ctrl + C`: Copy effect chain
1121
  - `Ctrl + V`: Paste effect chain
1122
- - `Ctrl + Shift + L`: Loop selection
1123
- - `Ctrl + Shift + P`: Export PDF report
1124
- - `Ctrl + Shift + M`: Export full mix ZIP
1125
  """)
1126
 
1127
  # --- Vocal Formant Correction – Now Defined! ===
@@ -1134,7 +1085,7 @@ with gr.Blocks(css="""
1134
  ],
1135
  outputs=gr.Audio(label="Natural-Sounding Vocal", type="filepath"),
1136
  title="Preserve Vocal Quality During Pitch Shift",
1137
- description="Make pitch-shifted vocals sound more natural"
1138
  )
1139
 
1140
  # --- Voice Swap / Cloning – New Tab ===
 
23
  import pickle
24
  import json
25
  import soundfile as sf
 
 
 
26
 
27
  # Suppress warnings
28
  warnings.filterwarnings("ignore")
 
549
  mixed.export(out_path, format="wav")
550
  return out_path
551
 
552
+ # === AI Remastering – Now Fixed! ===
553
  def ai_remaster(audio_path):
554
  try:
555
  audio = AudioSegment.from_file(audio_path)
 
575
  return out_path
576
 
577
  # === Generate PDF Report ===
578
+ try:
579
+ from fpdf import FPDF
580
+ except ImportError:
581
+ print("FPDF not found – skipping PDF report for now")
582
 
583
  class PDFReport(FPDF):
584
  def header(self):
 
594
  pdf.output(out_path)
595
  return out_path
596
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
597
  # === Main UI – With Studio Pulse Branding ===
598
  with gr.Blocks(css="""
599
  body {
 
872
  gr.Interface(
873
  fn=visualize_spectrum,
874
  inputs=gr.Audio(label="Upload Track", type="filepath"),
875
+ outputs=gr.Image(label="Spectrum Analysis")
 
 
876
  )
877
 
878
  # --- Loudness Graph Tab – EBU R128 Matching ===
 
1028
  allow_flagging="never"
1029
  )
1030
 
1031
+ # --- Loop Playback ===
1032
  with gr.Tab("πŸ” Loop Playback"):
1033
  gr.Interface(
1034
  fn=loop_section,
 
1068
  ### Keyboard Controls
1069
  - `Ctrl + Z`: Undo last effect
1070
  - `Ctrl + Y`: Redo
1071
+ - `Spacebar`: Play/Stop playback
1072
+ - `Ctrl + S`: Save current session
1073
  - `Ctrl + O`: Open session
1074
  - `Ctrl + C`: Copy effect chain
1075
  - `Ctrl + V`: Paste effect chain
 
 
 
1076
  """)
1077
 
1078
  # --- Vocal Formant Correction – Now Defined! ===
 
1085
  ],
1086
  outputs=gr.Audio(label="Natural-Sounding Vocal", type="filepath"),
1087
  title="Preserve Vocal Quality During Pitch Shift",
1088
+ description="Make pitch-shifted vocals sound more human"
1089
  )
1090
 
1091
  # --- Voice Swap / Cloning – New Tab ===