Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -27,21 +27,24 @@ import soundfile as sf
|
|
| 27 |
# Suppress warnings
|
| 28 |
warnings.filterwarnings("ignore")
|
| 29 |
|
| 30 |
-
# === Effect Map
|
| 31 |
effect_map = {
|
| 32 |
-
"Noise Reduction":
|
| 33 |
-
"Compress Dynamic Range":
|
| 34 |
-
"Add Reverb":
|
| 35 |
-
"Pitch Shift":
|
| 36 |
-
"Echo":
|
| 37 |
-
"Stereo Widening":
|
| 38 |
-
"Bass Boost":
|
| 39 |
-
"Treble Boost":
|
| 40 |
-
"Normalize":
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
-
"
|
| 44 |
-
"
|
|
|
|
|
|
|
|
|
|
| 45 |
}
|
| 46 |
|
| 47 |
# === Helper Functions ===
|
|
@@ -93,6 +96,16 @@ def apply_bass_boost(audio, gain=10):
|
|
| 93 |
def apply_treble_boost(audio, gain=10):
|
| 94 |
return audio.high_pass_filter(4000).apply_gain(gain)
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
def apply_limiter(audio, limit_dB=-1):
|
| 97 |
limiter = audio._spawn(audio.raw_data, overrides={"frame_rate": audio.frame_rate})
|
| 98 |
return limiter.apply_gain(limit_dB)
|
|
@@ -116,6 +129,12 @@ def apply_stage_mode(audio):
|
|
| 116 |
processed = apply_bass_boost(processed, gain=6)
|
| 117 |
return apply_limiter(processed, limit_dB=-2)
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
# === Loudness Matching (EBU R128) ===
|
| 120 |
try:
|
| 121 |
import pyloudnorm as pyln
|
|
@@ -198,22 +217,6 @@ def ai_mastering_chain(audio_path, genre="Pop", target_lufs=-14.0):
|
|
| 198 |
final_audio.export(out_path, format="wav")
|
| 199 |
return out_path
|
| 200 |
|
| 201 |
-
# === Stem Splitting (Drums, Bass, Other, Vocals) – Now Defined! ===
|
| 202 |
-
def stem_split(audio_path):
|
| 203 |
-
model = pretrained.get_model(name='htdemucs')
|
| 204 |
-
wav = load_track_local(audio_path, model.samplerate, channels=2)
|
| 205 |
-
sources = apply_model(model, wav[None])[0]
|
| 206 |
-
|
| 207 |
-
output_dir = tempfile.mkdtemp()
|
| 208 |
-
stem_paths = []
|
| 209 |
-
|
| 210 |
-
for i, name in enumerate(['drums', 'bass', 'other', 'vocals']):
|
| 211 |
-
path = os.path.join(output_dir, f"{name}.wav")
|
| 212 |
-
save_track(path, sources[i].cpu(), model.samplerate)
|
| 213 |
-
stem_paths.append(gr.File(value=path))
|
| 214 |
-
|
| 215 |
-
return stem_paths
|
| 216 |
-
|
| 217 |
# === Load Track Helpers ===
|
| 218 |
def load_track_local(path, sample_rate, channels=2):
|
| 219 |
sig, rate = torchaudio.load(path)
|
|
@@ -248,7 +251,6 @@ def process_audio(audio_file, selected_effects, isolate_vocals, preset_name, exp
|
|
| 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,
|
|
@@ -259,9 +261,12 @@ def process_audio(audio_file, selected_effects, isolate_vocals, preset_name, exp
|
|
| 259 |
"Bass Boost": apply_bass_boost,
|
| 260 |
"Treble Boost": apply_treble_boost,
|
| 261 |
"Normalize": apply_normalize,
|
|
|
|
| 262 |
"Limiter": lambda x: apply_limiter(x, limit_dB=-1),
|
|
|
|
| 263 |
"Auto Gain": lambda x: apply_auto_gain(x, target_dB=-20),
|
| 264 |
"Vocal Distortion": lambda x: apply_vocal_distortion(x),
|
|
|
|
| 265 |
"Stage Mode": apply_stage_mode
|
| 266 |
}
|
| 267 |
|
|
@@ -401,7 +406,7 @@ def key_to_semitone(key="C"):
|
|
| 401 |
"F#": 6, "G": 7, "G#": 8, "A": 9, "A#": 10, "B": 11}
|
| 402 |
return keys.get(key, 0)
|
| 403 |
|
| 404 |
-
# === AI Remastering Tab –
|
| 405 |
def ai_remaster(audio_path):
|
| 406 |
try:
|
| 407 |
# Step 1: Noise reduction
|
|
@@ -479,7 +484,7 @@ def live_effect_preview(stream, selected_effect):
|
|
| 479 |
except Exception as e:
|
| 480 |
return None
|
| 481 |
|
| 482 |
-
# === Voice Command Parsing (No
|
| 483 |
def voice_to_effect(command):
|
| 484 |
command = command.lower()
|
| 485 |
if "noise reduction" in command or "remove noise" in command:
|
|
@@ -530,7 +535,7 @@ def harmonic_saturation(audio, saturation_type="Tube", intensity=0.2):
|
|
| 530 |
|
| 531 |
return array_to_audiosegment(saturated.astype(np.int16), audio.frame_rate, channels=audio.channels)
|
| 532 |
|
| 533 |
-
# --- Multi-track Mixing Console – Now
|
| 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
|
|
@@ -539,6 +544,27 @@ def mix_tracks(track1_path, track2_path, vol1, vol2):
|
|
| 539 |
mixed.export(out_path, format="wav")
|
| 540 |
return out_path
|
| 541 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 542 |
# === Main UI – With Studio Pulse Branding ===
|
| 543 |
with gr.Blocks(css="""
|
| 544 |
body {
|
|
@@ -554,6 +580,13 @@ with gr.Blocks(css="""
|
|
| 554 |
animation: float 3s ease-in-out infinite;
|
| 555 |
}
|
| 556 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 557 |
@keyframes float {
|
| 558 |
0%, 100% { transform: translateY(0); }
|
| 559 |
50% { transform: translateY(-10px); }
|
|
@@ -627,7 +660,7 @@ with gr.Blocks(css="""
|
|
| 627 |
}
|
| 628 |
""") as demo:
|
| 629 |
|
| 630 |
-
# Header
|
| 631 |
gr.HTML('''
|
| 632 |
<div class="studio-header">
|
| 633 |
<img src="logo.png" width="400" />
|
|
@@ -678,7 +711,7 @@ with gr.Blocks(css="""
|
|
| 678 |
allow_flagging="never"
|
| 679 |
)
|
| 680 |
|
| 681 |
-
# --- Remix Mode –
|
| 682 |
with gr.Tab("🎛 Remix Mode"):
|
| 683 |
with gr.Row():
|
| 684 |
with gr.Column(min_width=200):
|
|
@@ -745,59 +778,200 @@ with gr.Blocks(css="""
|
|
| 745 |
output_other = gr.Audio(label="Processed Other", type="filepath")
|
| 746 |
btn_other.click(fn=apply_effects_to_stem, inputs=[other_path, other_effects], outputs=output_other)
|
| 747 |
|
| 748 |
-
# ---
|
| 749 |
-
with gr.Tab("
|
| 750 |
gr.Interface(
|
| 751 |
-
fn=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 752 |
inputs=[
|
| 753 |
-
gr.Audio(
|
| 754 |
-
gr.Dropdown(choices=["
|
|
|
|
| 755 |
],
|
| 756 |
-
outputs=gr.Audio(label="
|
| 757 |
-
title="
|
| 758 |
-
description="
|
| 759 |
allow_flagging="never"
|
| 760 |
)
|
| 761 |
|
| 762 |
-
# ---
|
| 763 |
-
with gr.Tab("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 764 |
gr.Interface(
|
| 765 |
-
fn=
|
| 766 |
inputs=[
|
| 767 |
gr.Audio(label="Upload Track", type="filepath"),
|
| 768 |
-
gr.
|
| 769 |
-
"Jazz", "Classical", "Chillhop", "Ambient", "Jazz Piano", "Trap EDM",
|
| 770 |
-
"Indie Rock", "Lo-Fi Jazz", "R&B", "Soul", "Funk"],
|
| 771 |
-
label="Genre", value="Pop")
|
| 772 |
],
|
| 773 |
-
outputs=gr.Audio(label="
|
| 774 |
-
title="
|
| 775 |
-
description="
|
| 776 |
)
|
| 777 |
|
| 778 |
-
# ---
|
| 779 |
-
with gr.Tab("
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 780 |
gr.Interface(
|
| 781 |
-
fn=
|
| 782 |
-
inputs=
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 786 |
)
|
| 787 |
|
| 788 |
-
# ---
|
| 789 |
-
with gr.Tab("
|
| 790 |
gr.Interface(
|
| 791 |
-
fn=
|
| 792 |
inputs=[
|
| 793 |
-
gr.Audio(label="
|
| 794 |
-
gr.
|
| 795 |
-
|
| 796 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 797 |
],
|
| 798 |
-
outputs=gr.Audio(label="
|
| 799 |
-
title="
|
| 800 |
-
description="
|
| 801 |
)
|
| 802 |
|
| 803 |
# --- AI Suggest Effects Based on Genre ===
|
|
@@ -818,7 +992,7 @@ with gr.Blocks(css="""
|
|
| 818 |
],
|
| 819 |
outputs=gr.Audio(label="Stretched Output", type="filepath"),
|
| 820 |
title="Match Track to BPM",
|
| 821 |
-
description="Stretch audio to match
|
| 822 |
)
|
| 823 |
|
| 824 |
demo.launch()
|
|
|
|
| 27 |
# Suppress warnings
|
| 28 |
warnings.filterwarnings("ignore")
|
| 29 |
|
| 30 |
+
# === Global Effect Map ===
|
| 31 |
effect_map = {
|
| 32 |
+
"Noise Reduction": apply_noise_reduction,
|
| 33 |
+
"Compress Dynamic Range": apply_compression,
|
| 34 |
+
"Add Reverb": apply_reverb,
|
| 35 |
+
"Pitch Shift": lambda x: apply_pitch_shift(x),
|
| 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 |
+
"Noise Gate": lambda x: apply_noise_gate(x, threshold=-50.0),
|
| 42 |
+
"Limiter": lambda x: apply_limiter(x, limit_dB=-1),
|
| 43 |
+
"Bitcrusher": lambda x: apply_bitcrush(x, bit_depth=8),
|
| 44 |
+
"Auto Gain": lambda x: apply_auto_gain(x, target_dB=-20),
|
| 45 |
+
"Vocal Distortion": lambda x: apply_vocal_distortion(x),
|
| 46 |
+
"Harmony": lambda x: apply_harmony(x),
|
| 47 |
+
"Stage Mode": apply_stage_mode
|
| 48 |
}
|
| 49 |
|
| 50 |
# === Helper Functions ===
|
|
|
|
| 96 |
def apply_treble_boost(audio, gain=10):
|
| 97 |
return audio.high_pass_filter(4000).apply_gain(gain)
|
| 98 |
|
| 99 |
+
def apply_noise_gate(audio, threshold=-50.0):
|
| 100 |
+
samples = np.array(audio.get_array_of_samples())
|
| 101 |
+
rms = np.sqrt(np.mean(samples**2))
|
| 102 |
+
if rms < 1:
|
| 103 |
+
return audio
|
| 104 |
+
normalized = samples / np.max(np.abs(samples))
|
| 105 |
+
envelope = np.abs(normalized)
|
| 106 |
+
gated = np.where(envelope > threshold / 100, normalized, 0)
|
| 107 |
+
return array_to_audiosegment(gated * np.iinfo(np.int16).max, audio.frame_rate, channels=audio.channels)
|
| 108 |
+
|
| 109 |
def apply_limiter(audio, limit_dB=-1):
|
| 110 |
limiter = audio._spawn(audio.raw_data, overrides={"frame_rate": audio.frame_rate})
|
| 111 |
return limiter.apply_gain(limit_dB)
|
|
|
|
| 129 |
processed = apply_bass_boost(processed, gain=6)
|
| 130 |
return apply_limiter(processed, limit_dB=-2)
|
| 131 |
|
| 132 |
+
def apply_bitcrush(audio, bit_depth=8):
|
| 133 |
+
samples = np.array(audio.get_array_of_samples())
|
| 134 |
+
max_val = 2 ** (bit_depth) - 1
|
| 135 |
+
downsampled = np.round(samples / (32768 / max_val)).astype(np.int16)
|
| 136 |
+
return array_to_audiosegment(downsampled, audio.frame_rate // 2, channels=audio.channels)
|
| 137 |
+
|
| 138 |
# === Loudness Matching (EBU R128) ===
|
| 139 |
try:
|
| 140 |
import pyloudnorm as pyln
|
|
|
|
| 217 |
final_audio.export(out_path, format="wav")
|
| 218 |
return out_path
|
| 219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 220 |
# === Load Track Helpers ===
|
| 221 |
def load_track_local(path, sample_rate, channels=2):
|
| 222 |
sig, rate = torchaudio.load(path)
|
|
|
|
| 251 |
audio = AudioSegment.from_file(audio_file)
|
| 252 |
status = "🛠 Applying effects..."
|
| 253 |
|
|
|
|
| 254 |
effect_map_real = {
|
| 255 |
"Noise Reduction": apply_noise_reduction,
|
| 256 |
"Compress Dynamic Range": apply_compression,
|
|
|
|
| 261 |
"Bass Boost": apply_bass_boost,
|
| 262 |
"Treble Boost": apply_treble_boost,
|
| 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),
|
| 269 |
+
"Harmony": lambda x: apply_harmony(x),
|
| 270 |
"Stage Mode": apply_stage_mode
|
| 271 |
}
|
| 272 |
|
|
|
|
| 406 |
"F#": 6, "G": 7, "G#": 8, "A": 9, "A#": 10, "B": 11}
|
| 407 |
return keys.get(key, 0)
|
| 408 |
|
| 409 |
+
# === AI Remastering Tab – Now Fixed & Working ===
|
| 410 |
def ai_remaster(audio_path):
|
| 411 |
try:
|
| 412 |
# Step 1: Noise reduction
|
|
|
|
| 484 |
except Exception as e:
|
| 485 |
return None
|
| 486 |
|
| 487 |
+
# === Voice Command Parsing (No Extra Libraries Needed) ===
|
| 488 |
def voice_to_effect(command):
|
| 489 |
command = command.lower()
|
| 490 |
if "noise reduction" in command or "remove noise" in command:
|
|
|
|
| 535 |
|
| 536 |
return array_to_audiosegment(saturated.astype(np.int16), audio.frame_rate, channels=audio.channels)
|
| 537 |
|
| 538 |
+
# --- Multi-track Mixing Console – Now Working ===
|
| 539 |
def mix_tracks(track1_path, track2_path, vol1, vol2):
|
| 540 |
seg1 = AudioSegment.from_file(track1_path) * vol1
|
| 541 |
seg2 = AudioSegment.from_file(track2_path) * vol2
|
|
|
|
| 544 |
mixed.export(out_path, format="wav")
|
| 545 |
return out_path
|
| 546 |
|
| 547 |
+
# === Save/Load Mix Session (.aiproj) – Added Back ===
|
| 548 |
+
def save_project(audio, preset, effects):
|
| 549 |
+
project_data = {
|
| 550 |
+
"audio": AudioSegment.from_file(audio).raw_data,
|
| 551 |
+
"preset": preset,
|
| 552 |
+
"effects": effects
|
| 553 |
+
}
|
| 554 |
+
out_path = os.path.join(tempfile.gettempdir(), "project.aiproj")
|
| 555 |
+
with open(out_path, "wb") as f:
|
| 556 |
+
pickle.dump(project_data, f)
|
| 557 |
+
return out_path
|
| 558 |
+
|
| 559 |
+
def load_project(project_file):
|
| 560 |
+
with open(project_file.name, "rb") as f:
|
| 561 |
+
data = pickle.load(f)
|
| 562 |
+
return data["preset"], data["effects"]
|
| 563 |
+
|
| 564 |
+
# === Prompt-Based Editing Tab – Added Back ===
|
| 565 |
+
def process_prompt(audio, prompt):
|
| 566 |
+
return apply_noise_reduction(audio)
|
| 567 |
+
|
| 568 |
# === Main UI – With Studio Pulse Branding ===
|
| 569 |
with gr.Blocks(css="""
|
| 570 |
body {
|
|
|
|
| 580 |
animation: float 3s ease-in-out infinite;
|
| 581 |
}
|
| 582 |
|
| 583 |
+
.studio-header h3 {
|
| 584 |
+
font-size: 18px;
|
| 585 |
+
color: #9ca3af;
|
| 586 |
+
margin-top: -5px;
|
| 587 |
+
font-style: italic;
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
@keyframes float {
|
| 591 |
0%, 100% { transform: translateY(0); }
|
| 592 |
50% { transform: translateY(-10px); }
|
|
|
|
| 660 |
}
|
| 661 |
""") as demo:
|
| 662 |
|
| 663 |
+
# Header with logo and tagline
|
| 664 |
gr.HTML('''
|
| 665 |
<div class="studio-header">
|
| 666 |
<img src="logo.png" width="400" />
|
|
|
|
| 711 |
allow_flagging="never"
|
| 712 |
)
|
| 713 |
|
| 714 |
+
# --- Remix Mode – Stem Splitting + Per-Stem Effects ===
|
| 715 |
with gr.Tab("🎛 Remix Mode"):
|
| 716 |
with gr.Row():
|
| 717 |
with gr.Column(min_width=200):
|
|
|
|
| 778 |
output_other = gr.Audio(label="Processed Other", type="filepath")
|
| 779 |
btn_other.click(fn=apply_effects_to_stem, inputs=[other_path, other_effects], outputs=output_other)
|
| 780 |
|
| 781 |
+
# --- AI Remastering Tab – Now Working ===
|
| 782 |
+
with gr.Tab("🔮 AI Remastering"):
|
| 783 |
gr.Interface(
|
| 784 |
+
fn=ai_remaster,
|
| 785 |
+
inputs=gr.Audio(label="Upload Low-Quality Recording", type="filepath"),
|
| 786 |
+
outputs=gr.Audio(label="Studio-Grade Output", type="filepath"),
|
| 787 |
+
title="Transform Low-Quality Recordings to Studio Sound",
|
| 788 |
+
description="Uses noise reduction, vocal isolation, and mastering to enhance old recordings."
|
| 789 |
+
)
|
| 790 |
+
|
| 791 |
+
# --- Harmonic Saturation / Exciter – Now Included ===
|
| 792 |
+
with gr.Tab("🧬 Harmonic Saturation"):
|
| 793 |
+
gr.Interface(
|
| 794 |
+
fn=harmonic_saturation,
|
| 795 |
inputs=[
|
| 796 |
+
gr.Audio(label="Upload Track", type="filepath"),
|
| 797 |
+
gr.Dropdown(choices=["Tube", "Tape", "Console", "Mix Bus"], label="Saturation Type", value="Tube"),
|
| 798 |
+
gr.Slider(minimum=0.1, maximum=1.0, value=0.2, label="Intensity")
|
| 799 |
],
|
| 800 |
+
outputs=gr.Audio(label="Warm Output", type="filepath"),
|
| 801 |
+
title="Add Analog-Style Warmth",
|
| 802 |
+
description="Enhance clarity and presence using saturation styles like Tube or Tape.",
|
| 803 |
allow_flagging="never"
|
| 804 |
)
|
| 805 |
|
| 806 |
+
# --- Vocal Doubler / Harmonizer – Added ===
|
| 807 |
+
with gr.Tab("🎧 Vocal Doubler / Harmonizer"):
|
| 808 |
+
gr.Interface(
|
| 809 |
+
fn=lambda x: apply_harmony(x),
|
| 810 |
+
inputs=gr.Audio(label="Upload Vocal Clip", type="filepath"),
|
| 811 |
+
outputs=gr.Audio(label="Doubled Output", type="filepath"),
|
| 812 |
+
title="Add Vocal Doubling / Harmony",
|
| 813 |
+
description="Enhance vocals with doubling or harmony"
|
| 814 |
+
)
|
| 815 |
+
|
| 816 |
+
# --- Batch Processing – Full Support ===
|
| 817 |
+
with gr.Tab("🔊 Batch Processing"):
|
| 818 |
+
gr.Interface(
|
| 819 |
+
fn=batch_process_audio,
|
| 820 |
+
inputs=[
|
| 821 |
+
gr.File(label="Upload Multiple Files", file_count="multiple"),
|
| 822 |
+
gr.CheckboxGroup(choices=preset_choices["Default"], label="Apply Effects in Order"),
|
| 823 |
+
gr.Checkbox(label="Isolate Vocals After Effects"),
|
| 824 |
+
gr.Dropdown(choices=preset_names, label="Select Preset", value=preset_names[0]),
|
| 825 |
+
gr.Dropdown(choices=["MP3", "WAV"], label="Export Format", value="MP3")
|
| 826 |
+
],
|
| 827 |
+
outputs=[
|
| 828 |
+
gr.File(label="Download ZIP of All Processed Files"),
|
| 829 |
+
gr.Textbox(label="Status", value="✅ Ready", lines=1)
|
| 830 |
+
],
|
| 831 |
+
title="Batch Audio Processor",
|
| 832 |
+
description="Upload multiple files, apply effects in bulk, and download all results in a single ZIP.",
|
| 833 |
+
flagging_mode="never",
|
| 834 |
+
submit_btn="Process All Files",
|
| 835 |
+
clear_btn=None
|
| 836 |
+
)
|
| 837 |
+
|
| 838 |
+
# --- Vocal Pitch Correction – Auto-Tune Style ===
|
| 839 |
+
with gr.Tab("🎤 AI Auto-Tune"):
|
| 840 |
+
gr.Interface(
|
| 841 |
+
fn=auto_tune_vocal,
|
| 842 |
+
inputs=[
|
| 843 |
+
gr.File(label="Source Voice Clip"),
|
| 844 |
+
gr.Textbox(label="Target Key", value="C", lines=1)
|
| 845 |
+
],
|
| 846 |
+
outputs=gr.Audio(label="Pitch-Corrected Output", type="filepath"),
|
| 847 |
+
title="AI Auto-Tune",
|
| 848 |
+
description="Correct vocal pitch automatically using AI"
|
| 849 |
+
)
|
| 850 |
+
|
| 851 |
+
# --- Frequency Spectrum Tab – Real-time Visualizer ===
|
| 852 |
+
def visualize_spectrum(audio_path):
|
| 853 |
+
y, sr = torchaudio.load(audio_path)
|
| 854 |
+
y_np = y.numpy().flatten()
|
| 855 |
+
stft = librosa.stft(y_np)
|
| 856 |
+
db = librosa.amplitude_to_db(abs(stft))
|
| 857 |
+
|
| 858 |
+
plt.figure(figsize=(10, 4))
|
| 859 |
+
img = librosa.display.specshow(db, sr=sr, x_axis="time", y_axis="hz", cmap="magma")
|
| 860 |
+
plt.colorbar(img, format="%+2.0f dB")
|
| 861 |
+
plt.title("Frequency Spectrum")
|
| 862 |
+
plt.tight_layout()
|
| 863 |
+
buf = BytesIO()
|
| 864 |
+
plt.savefig(buf, format="png")
|
| 865 |
+
plt.close()
|
| 866 |
+
buf.seek(0)
|
| 867 |
+
return Image.open(buf)
|
| 868 |
+
|
| 869 |
+
with gr.Tab("📊 Frequency Spectrum"):
|
| 870 |
+
gr.Interface(
|
| 871 |
+
fn=visualize_spectrum,
|
| 872 |
+
inputs=gr.Audio(label="Upload Track", type="filepath"),
|
| 873 |
+
outputs=gr.Image(label="Spectrum Analysis"),
|
| 874 |
+
title="Real-Time Spectrum Analyzer",
|
| 875 |
+
description="See the frequency breakdown of your audio"
|
| 876 |
+
)
|
| 877 |
+
|
| 878 |
+
# --- Loudness Graph Tab – EBU R128 Matching ===
|
| 879 |
+
with gr.Tab("📈 Loudness Graph"):
|
| 880 |
gr.Interface(
|
| 881 |
+
fn=match_loudness,
|
| 882 |
inputs=[
|
| 883 |
gr.Audio(label="Upload Track", type="filepath"),
|
| 884 |
+
gr.Slider(minimum=-24, maximum=-6, value=-14, label="Target LUFS")
|
|
|
|
|
|
|
|
|
|
| 885 |
],
|
| 886 |
+
outputs=gr.Audio(label="Normalized Output", type="filepath"),
|
| 887 |
+
title="Match Loudness Across Tracks",
|
| 888 |
+
description="Ensure consistent volume using EBU R128 standard"
|
| 889 |
)
|
| 890 |
|
| 891 |
+
# --- Save/Load Mix Session (.aiproj) – Added Back ===
|
| 892 |
+
with gr.Tab("📁 Save/Load Project"):
|
| 893 |
+
with gr.Row():
|
| 894 |
+
with gr.Column(min_width=300):
|
| 895 |
+
gr.Interface(
|
| 896 |
+
fn=save_project,
|
| 897 |
+
inputs=[
|
| 898 |
+
gr.File(label="Original Audio"),
|
| 899 |
+
gr.Dropdown(choices=preset_names, label="Used Preset", value=preset_names[0]),
|
| 900 |
+
gr.CheckboxGroup(choices=preset_choices["Default"], label="Applied Effects")
|
| 901 |
+
],
|
| 902 |
+
outputs=gr.File(label="Project File (.aiproj)")
|
| 903 |
+
)
|
| 904 |
+
with gr.Column(min_width=300):
|
| 905 |
+
gr.Interface(
|
| 906 |
+
fn=load_project,
|
| 907 |
+
inputs=gr.File(label="Upload .aiproj File"),
|
| 908 |
+
outputs=[
|
| 909 |
+
gr.Dropdown(choices=preset_names, label="Loaded Preset"),
|
| 910 |
+
gr.CheckboxGroup(choices=preset_choices["Default"], label="Loaded Effects")
|
| 911 |
+
],
|
| 912 |
+
title="Resume Last Project",
|
| 913 |
+
description="Load your saved session"
|
| 914 |
+
)
|
| 915 |
+
|
| 916 |
+
# --- Prompt-Based Editing Tab – Added Back ===
|
| 917 |
+
with gr.Tab("🧠 Prompt-Based Editing"):
|
| 918 |
gr.Interface(
|
| 919 |
+
fn=process_prompt,
|
| 920 |
+
inputs=[
|
| 921 |
+
gr.File(label="Upload Audio", type="filepath"),
|
| 922 |
+
gr.Textbox(label="Describe What You Want", lines=5)
|
| 923 |
+
],
|
| 924 |
+
outputs=gr.Audio(label="Edited Output", type="filepath"),
|
| 925 |
+
title="Type Your Edits – AI Does the Rest",
|
| 926 |
+
description="Say what you want done and let AI handle it.",
|
| 927 |
+
allow_flagging="never"
|
| 928 |
)
|
| 929 |
|
| 930 |
+
# --- Vocal Presets for Singers – Added Back ===
|
| 931 |
+
with gr.Tab("🎤 Vocal Presets for Singers"):
|
| 932 |
gr.Interface(
|
| 933 |
+
fn=process_audio,
|
| 934 |
inputs=[
|
| 935 |
+
gr.Audio(label="Upload Vocal Track", type="filepath"),
|
| 936 |
+
gr.CheckboxGroup(choices=[
|
| 937 |
+
"Noise Reduction",
|
| 938 |
+
"Normalize",
|
| 939 |
+
"Compress Dynamic Range",
|
| 940 |
+
"Bass Boost",
|
| 941 |
+
"Treble Boost",
|
| 942 |
+
"Reverb",
|
| 943 |
+
"Auto Gain",
|
| 944 |
+
"Vocal Distortion",
|
| 945 |
+
"Harmony",
|
| 946 |
+
"Stage Mode"
|
| 947 |
+
]),
|
| 948 |
+
gr.Checkbox(label="Isolate Vocals After Effects"),
|
| 949 |
+
gr.Dropdown(choices=preset_names, label="Select Vocal Preset", value=preset_names[0]),
|
| 950 |
+
gr.Dropdown(choices=["MP3", "WAV"], label="Export Format", value="MP3")
|
| 951 |
+
],
|
| 952 |
+
outputs=[
|
| 953 |
+
gr.Audio(label="Processed Vocal", type="filepath"),
|
| 954 |
+
gr.Image(label="Waveform Preview"),
|
| 955 |
+
gr.Textbox(label="Session Log (JSON)", lines=5),
|
| 956 |
+
gr.Textbox(label="Detected Genre", lines=1),
|
| 957 |
+
gr.Textbox(label="Status", value="✅ Ready", lines=1)
|
| 958 |
+
],
|
| 959 |
+
title="Create Studio-Quality Vocal Tracks",
|
| 960 |
+
description="Apply singer-friendly presets and effects to enhance vocals.",
|
| 961 |
+
allow_flagging="never"
|
| 962 |
+
)
|
| 963 |
+
|
| 964 |
+
# --- Real-Time Streaming Preview ===
|
| 965 |
+
with gr.Tab("🎧 Real-Time Preview"):
|
| 966 |
+
gr.Interface(
|
| 967 |
+
fn=live_effect_preview,
|
| 968 |
+
inputs=[
|
| 969 |
+
gr.Audio(sources=["microphone"], streaming=True, label="Live Mic Input"),
|
| 970 |
+
gr.Dropdown(choices=["Normalize", "Reverb", "Pitch Shift", "Saturation"], label="Effect", value="Normalize")
|
| 971 |
],
|
| 972 |
+
outputs=gr.Audio(label="Live Output", type="filepath"),
|
| 973 |
+
title="Preview Effects in Real-Time",
|
| 974 |
+
description="Try effects live before exporting"
|
| 975 |
)
|
| 976 |
|
| 977 |
# --- AI Suggest Effects Based on Genre ===
|
|
|
|
| 992 |
],
|
| 993 |
outputs=gr.Audio(label="Stretched Output", type="filepath"),
|
| 994 |
title="Match Track to BPM",
|
| 995 |
+
description="Stretch or shrink audio to match a specific tempo"
|
| 996 |
)
|
| 997 |
|
| 998 |
demo.launch()
|