tee342 commited on
Commit
1fe71c8
Β·
verified Β·
1 Parent(s): 259826c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -63
app.py CHANGED
@@ -22,7 +22,6 @@ from TTS.api import TTS
22
  import base64
23
  import pickle
24
  import json
25
- from moviepy.editor import TextClip, CompositeVideoClip, ColorClip, AudioFileClip
26
 
27
  # Suppress warnings
28
  warnings.filterwarnings("ignore")
@@ -264,7 +263,6 @@ def process_audio(audio_file, selected_effects, isolate_vocals, preset_name, exp
264
  "Normalize": apply_normalize,
265
  "Noise Gate": lambda x: apply_noise_gate(x, threshold=-50.0),
266
  "Limiter": lambda x: apply_limiter(x, limit_dB=-1),
267
- "Flanger": lambda x: apply_phaser(x, rate=1.2, depth=0.9, mix=0.7),
268
  "Bitcrusher": lambda x: apply_bitcrush(x, bit_depth=8),
269
  "Auto Gain": lambda x: apply_auto_gain(x, target_dB=-20),
270
  "Vocal Distortion": lambda x: apply_vocal_distortion(x),
@@ -369,7 +367,7 @@ def batch_process_audio(files, selected_effects, isolate_vocals, preset_name, ex
369
  results.append(processed_path)
370
  session_logs.append(log)
371
 
372
- zip_path = os.path.join(output_dir, "batch_output.zip")
373
  with zipfile.ZipFile(zip_path, 'w') as zipf:
374
  for i, res in enumerate(results):
375
  filename = f"processed_{i}.{export_format.lower()}"
@@ -384,36 +382,15 @@ def batch_process_audio(files, selected_effects, isolate_vocals, preset_name, ex
384
  # === Vocal Pitch Correction – Auto-Tune Style ===
385
  def auto_tune_vocal(audio_path, target_key="C"):
386
  try:
387
- # Placeholder for real-time pitch detection
388
  return apply_pitch_shift(AudioSegment.from_file(audio_path), 0.2)
389
  except Exception as e:
390
  return None
391
 
392
- # === Create Karaoke Video from Audio + Lyrics ===
393
- def create_karaoke_video(audio_path, lyrics, bg_image=None):
394
- try:
395
- from moviepy.editor import TextClip, CompositeVideoClip, ColorClip, AudioFileClip
396
-
397
- audio = AudioFileClip(audio_path)
398
- video = ColorClip(size=(1280, 720), color=(0, 0, 0), duration=audio.duration_seconds)
399
- words = [(word.strip(), i * 3, (i+1)*3) for i, word in enumerate(lyrics.split())]
400
-
401
- text_clips = [
402
- TextClip(word, fontsize=60, color='white').set_position('center').set_duration(end - start).set_start(start)
403
- for word, start, end in words
404
- ]
405
-
406
- final_video = CompositeVideoClip([video] + text_clips).set_audio(audio)
407
- out_path = os.path.join(tempfile.gettempdir(), "karaoke.mp4")
408
- final_video.write_videofile(out_path, codec="libx264", audio_codec="aac")
409
- return out_path
410
- except Exception as e:
411
- return f"⚠️ Failed: {str(e)}"
412
-
413
  # === Real-Time Spectrum Analyzer + Live EQ Preview ===
414
  def visualize_spectrum(audio_path):
415
  y, sr = torchaudio.load(audio_path)
416
  y_np = y.numpy().flatten()
 
417
  stft = librosa.stft(y_np)
418
  db = librosa.amplitude_to_db(abs(stft))
419
 
@@ -501,30 +478,6 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
501
  clear_btn=None
502
  )
503
 
504
- # --- Preset Cards Gallery – Visual Selection ===
505
- with gr.Tab("πŸŽ› Preset Gallery"):
506
- gr.Markdown("### Select a preset visually")
507
- preset_gallery = gr.Gallery(value=[
508
- ("images/pop_card.png", "Pop"),
509
- ("images/edm_card.png", "EDM"),
510
- ("images/rock_card.png", "Rock"),
511
- ("images/hiphop_card.png", "Hip-Hop"),
512
- ("images/acoustic_card.png", "Acoustic"),
513
- ("images/stage_mode_card.png", "Stage Mode"),
514
- ("images/vocal_distortion_card.png", "Vocal Distortion"),
515
- ("images/tube_saturation_card.png", "Tube Saturation")
516
- ], label="Preset Cards", columns=4, height="auto")
517
-
518
- preset_name_out = gr.Dropdown(choices=preset_names, label="Selected Preset")
519
- preset_effects_out = gr.CheckboxGroup(choices=list(preset_choices["Default"]), label="Effects")
520
-
521
- def load_preset_by_card(evt: gr.SelectData):
522
- index = evt.index % len(preset_names)
523
- name = preset_names[index]
524
- return name, preset_choices[name]
525
-
526
- preset_gallery.select(fn=load_preset_by_card, inputs=[], outputs=[preset_name_out, preset_effects_out])
527
-
528
  # --- Vocal Doubler / Harmonizer – Added ===
529
  with gr.Tab("🎧 Vocal Doubler / Harmonizer"):
530
  gr.Interface(
@@ -570,20 +523,6 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
570
  description="Correct vocal pitch automatically"
571
  )
572
 
573
- # --- Karaoke Video Creator – Added Back ===
574
- with gr.Tab("πŸ“Ή Create Karaoke Video"):
575
- gr.Interface(
576
- fn=create_karaoke_video,
577
- inputs=[
578
- gr.Audio(label="Upload Track", type="filepath"),
579
- gr.Textbox(label="Lyrics", lines=10),
580
- gr.File(label="Background (Optional)")
581
- ],
582
- outputs=gr.Video(label="Karaoke Video"),
583
- title="Make Karaoke Videos from Audio + Lyrics",
584
- description="Generate karaoke-style videos with real-time sync."
585
- )
586
-
587
  # --- Real-Time Spectrum Analyzer + Live EQ Preview – Added Back ===
588
  with gr.Tab("πŸ“Š Frequency Spectrum"):
589
  gr.Interface(
@@ -648,6 +587,30 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
648
  description="Load your saved session"
649
  )
650
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
651
  # --- Prompt-Based Editing Tab – Added Back ===
652
  def process_prompt(audio, prompt):
653
  return apply_noise_reduction(audio)
 
22
  import base64
23
  import pickle
24
  import json
 
25
 
26
  # Suppress warnings
27
  warnings.filterwarnings("ignore")
 
263
  "Normalize": apply_normalize,
264
  "Noise Gate": lambda x: apply_noise_gate(x, threshold=-50.0),
265
  "Limiter": lambda x: apply_limiter(x, limit_dB=-1),
 
266
  "Bitcrusher": lambda x: apply_bitcrush(x, bit_depth=8),
267
  "Auto Gain": lambda x: apply_auto_gain(x, target_dB=-20),
268
  "Vocal Distortion": lambda x: apply_vocal_distortion(x),
 
367
  results.append(processed_path)
368
  session_logs.append(log)
369
 
370
+ zip_path = os.path.join(tempfile.gettempdir(), "batch_output.zip")
371
  with zipfile.ZipFile(zip_path, 'w') as zipf:
372
  for i, res in enumerate(results):
373
  filename = f"processed_{i}.{export_format.lower()}"
 
382
  # === Vocal Pitch Correction – Auto-Tune Style ===
383
  def auto_tune_vocal(audio_path, target_key="C"):
384
  try:
 
385
  return apply_pitch_shift(AudioSegment.from_file(audio_path), 0.2)
386
  except Exception as e:
387
  return None
388
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
389
  # === Real-Time Spectrum Analyzer + Live EQ Preview ===
390
  def visualize_spectrum(audio_path):
391
  y, sr = torchaudio.load(audio_path)
392
  y_np = y.numpy().flatten()
393
+
394
  stft = librosa.stft(y_np)
395
  db = librosa.amplitude_to_db(abs(stft))
396
 
 
478
  clear_btn=None
479
  )
480
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
481
  # --- Vocal Doubler / Harmonizer – Added ===
482
  with gr.Tab("🎧 Vocal Doubler / Harmonizer"):
483
  gr.Interface(
 
523
  description="Correct vocal pitch automatically"
524
  )
525
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
  # --- Real-Time Spectrum Analyzer + Live EQ Preview – Added Back ===
527
  with gr.Tab("πŸ“Š Frequency Spectrum"):
528
  gr.Interface(
 
587
  description="Load your saved session"
588
  )
589
 
590
+ # --- Preset Cards Gallery – Visual Selection ===
591
+ with gr.Tab("πŸŽ› Preset Gallery"):
592
+ gr.Markdown("### Select a preset visually")
593
+ preset_gallery = gr.Gallery(value=[
594
+ ("images/pop_card.png", "Pop"),
595
+ ("images/edm_card.png", "EDM"),
596
+ ("images/rock_card.png", "Rock"),
597
+ ("images/hiphop_card.png", "Hip-Hop"),
598
+ ("images/acoustic_card.png", "Acoustic"),
599
+ ("images/stage_mode_card.png", "Stage Mode"),
600
+ ("images/vocal_distortion_card.png", "Vocal Distortion"),
601
+ ("images/tube_saturation_card.png", "Tube Saturation")
602
+ ], label="Preset Cards", columns=4, height="auto")
603
+
604
+ preset_name_out = gr.Dropdown(choices=preset_names, label="Selected Preset")
605
+ preset_effects_out = gr.CheckboxGroup(choices=list(preset_choices["Default"]), label="Effects")
606
+
607
+ def load_preset_by_card(evt: gr.SelectData):
608
+ index = evt.index % len(preset_names)
609
+ name = preset_names[index]
610
+ return name, preset_choices[name]
611
+
612
+ preset_gallery.select(fn=load_preset_by_card, inputs=[], outputs=[preset_name_out, preset_effects_out])
613
+
614
  # --- Prompt-Based Editing Tab – Added Back ===
615
  def process_prompt(audio, prompt):
616
  return apply_noise_reduction(audio)