Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,7 +23,6 @@ import base64
|
|
| 23 |
import pickle
|
| 24 |
import json
|
| 25 |
import soundfile as sf
|
| 26 |
-
from moviepy.editor import VideoFileClip
|
| 27 |
|
| 28 |
# Suppress warnings
|
| 29 |
warnings.filterwarnings("ignore")
|
|
@@ -485,7 +484,7 @@ def suggest_by_genre(audio_path):
|
|
| 485 |
genre = detect_genre(audio_path)
|
| 486 |
return preset_choices.get(genre, [])
|
| 487 |
|
| 488 |
-
# === Time-Stretch &
|
| 489 |
def stretch_to_bpm(audio_path, target_bpm=128):
|
| 490 |
y, sr = torchaudio.load(audio_path)
|
| 491 |
y_np = y.numpy().flatten()
|
|
@@ -493,28 +492,27 @@ def stretch_to_bpm(audio_path, target_bpm=128):
|
|
| 493 |
ratio = target_bpm / tempo
|
| 494 |
stretched = librosa.effects.time_stretch(y_np, ratio)
|
| 495 |
out_path = os.path.join(tempfile.gettempdir(), "stretched_output.wav")
|
| 496 |
-
sf.write(out_path, stretched, sr, format=
|
| 497 |
return out_path
|
| 498 |
|
| 499 |
-
# ===
|
| 500 |
-
def
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
| 508 |
-
|
| 509 |
-
|
| 510 |
-
|
| 511 |
-
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
|
| 515 |
-
return out_path
|
| 516 |
|
| 517 |
-
#
|
| 518 |
def mix_tracks(track1_path, track2_path, vol1, vol2):
|
| 519 |
seg1 = AudioSegment.from_file(track1_path) * vol1
|
| 520 |
seg2 = AudioSegment.from_file(track2_path) * vol2
|
|
@@ -538,13 +536,6 @@ with gr.Blocks(css="""
|
|
| 538 |
animation: float 3s ease-in-out infinite;
|
| 539 |
}
|
| 540 |
|
| 541 |
-
.studio-header h3 {
|
| 542 |
-
font-size: 18px;
|
| 543 |
-
color: #9ca3af;
|
| 544 |
-
margin-top: -5px;
|
| 545 |
-
font-style: italic;
|
| 546 |
-
}
|
| 547 |
-
|
| 548 |
@keyframes float {
|
| 549 |
0%, 100% { transform: translateY(0); }
|
| 550 |
50% { transform: translateY(-10px); }
|
|
@@ -570,7 +561,6 @@ with gr.Blocks(css="""
|
|
| 570 |
background-color: #334155 !important;
|
| 571 |
color: white !important;
|
| 572 |
border: 1px solid #475569 !important;
|
| 573 |
-
border-radius: 6px;
|
| 574 |
width: 100%;
|
| 575 |
padding: 10px;
|
| 576 |
}
|
|
@@ -600,16 +590,6 @@ with gr.Blocks(css="""
|
|
| 600 |
box-shadow: 0 0 12px #2563eb44;
|
| 601 |
}
|
| 602 |
|
| 603 |
-
.gr-gallery__item-label {
|
| 604 |
-
background: rgba(0, 0, 0, 0.7);
|
| 605 |
-
backdrop-filter: blur(3px);
|
| 606 |
-
border-radius: 0 0 12px 12px;
|
| 607 |
-
padding: 10px;
|
| 608 |
-
font-size: 14px;
|
| 609 |
-
font-weight: bold;
|
| 610 |
-
text-align: center;
|
| 611 |
-
}
|
| 612 |
-
|
| 613 |
@media (max-width: 768px) {
|
| 614 |
.gr-column {
|
| 615 |
min-width: 100%;
|
|
@@ -680,7 +660,7 @@ with gr.Blocks(css="""
|
|
| 680 |
allow_flagging="never"
|
| 681 |
)
|
| 682 |
|
| 683 |
-
# --- Remix Mode β Apply Effects to
|
| 684 |
with gr.Tab("π Remix Mode"):
|
| 685 |
with gr.Row():
|
| 686 |
with gr.Column(min_width=200):
|
|
@@ -756,6 +736,8 @@ with gr.Blocks(css="""
|
|
| 756 |
gr.Dropdown(choices=["Normalize", "Reverb", "Pitch Shift", "Saturation"], label="Effect", value="Normalize")
|
| 757 |
],
|
| 758 |
outputs=gr.Audio(label="Live Output", type="filepath"),
|
|
|
|
|
|
|
| 759 |
allow_flagging="never"
|
| 760 |
)
|
| 761 |
|
|
@@ -772,7 +754,8 @@ with gr.Blocks(css="""
|
|
| 772 |
],
|
| 773 |
outputs=gr.Audio(label="EQ-Enhanced Output", type="filepath"),
|
| 774 |
title="Custom EQ by Genre",
|
| 775 |
-
description="Apply
|
|
|
|
| 776 |
)
|
| 777 |
|
| 778 |
# --- Voice Command Mode ===
|
|
@@ -780,10 +763,12 @@ with gr.Blocks(css="""
|
|
| 780 |
gr.Interface(
|
| 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 |
)
|
| 785 |
|
| 786 |
-
# --- Multi-track Mixing Console ===
|
| 787 |
with gr.Tab("π Multi-track Mixing Console"):
|
| 788 |
gr.Interface(
|
| 789 |
fn=mix_tracks,
|
|
@@ -795,7 +780,8 @@ with gr.Blocks(css="""
|
|
| 795 |
],
|
| 796 |
outputs=gr.Audio(label="Mixed Output", type="filepath"),
|
| 797 |
title="Mix Two Tracks",
|
| 798 |
-
description="Upload two tracks and adjust volume sliders"
|
|
|
|
| 799 |
)
|
| 800 |
|
| 801 |
# --- AI Suggest Effects Based on Genre ===
|
|
@@ -806,7 +792,7 @@ with gr.Blocks(css="""
|
|
| 806 |
outputs=gr.CheckboxGroup(choices=preset_choices["Default"], label="Suggested Effects")
|
| 807 |
)
|
| 808 |
|
| 809 |
-
# --- Time-Stretch &
|
| 810 |
with gr.Tab("β± Time-Stretch & BPM Match"):
|
| 811 |
gr.Interface(
|
| 812 |
fn=stretch_to_bpm,
|
|
@@ -816,26 +802,7 @@ with gr.Blocks(css="""
|
|
| 816 |
],
|
| 817 |
outputs=gr.Audio(label="Stretched Output", type="filepath"),
|
| 818 |
title="Match Track to BPM",
|
| 819 |
-
description="Stretch
|
| 820 |
)
|
| 821 |
|
| 822 |
-
# --- Video Sync Mode ===
|
| 823 |
-
with gr.Tab("π½ Video Sync Mode"):
|
| 824 |
-
with gr.Row():
|
| 825 |
-
with gr.Column(min_width=300):
|
| 826 |
-
input_video = gr.Video(label="Upload Video", type="filepath")
|
| 827 |
-
extract_btn = gr.Button("Extract Audio")
|
| 828 |
-
extracted_audio = gr.Audio(label="Extracted Audio", type="filepath")
|
| 829 |
-
effect_checkbox_video = gr.CheckboxGroup(choices=preset_choices["Default"], label="Apply Effects")
|
| 830 |
-
process_btn_video = gr.Button("Process Audio")
|
| 831 |
-
with gr.Column(min_width=300):
|
| 832 |
-
processed_audio = gr.Audio(label="Edited Audio", type="filepath")
|
| 833 |
-
re_sync_btn = gr.Button("Sync Back to Video")
|
| 834 |
-
output_video = gr.Video(label="Final Video", type="filepath")
|
| 835 |
-
|
| 836 |
-
extract_btn.click(fn=extract_audio_from_video, inputs=input_video, outputs=extracted_audio)
|
| 837 |
-
process_btn_video.click(fn=process_audio, inputs=[extracted_audio, effect_checkbox_video, gr.Checkbox(value=False), gr.Dropdown(value="Default"), gr.Dropdown(value="MP3")],
|
| 838 |
-
outputs=[processed_audio])
|
| 839 |
-
re_sync_btn.click(fn=re_sync_audio, inputs=[input_video, processed_audio], outputs=output_video)
|
| 840 |
-
|
| 841 |
demo.launch()
|
|
|
|
| 23 |
import pickle
|
| 24 |
import json
|
| 25 |
import soundfile as sf
|
|
|
|
| 26 |
|
| 27 |
# Suppress warnings
|
| 28 |
warnings.filterwarnings("ignore")
|
|
|
|
| 484 |
genre = detect_genre(audio_path)
|
| 485 |
return preset_choices.get(genre, [])
|
| 486 |
|
| 487 |
+
# === Time-Stretch & BPM Match ===
|
| 488 |
def stretch_to_bpm(audio_path, target_bpm=128):
|
| 489 |
y, sr = torchaudio.load(audio_path)
|
| 490 |
y_np = y.numpy().flatten()
|
|
|
|
| 492 |
ratio = target_bpm / tempo
|
| 493 |
stretched = librosa.effects.time_stretch(y_np, ratio)
|
| 494 |
out_path = os.path.join(tempfile.gettempdir(), "stretched_output.wav")
|
| 495 |
+
sf.write(out_path, stretched, sr, format="WAV")
|
| 496 |
return out_path
|
| 497 |
|
| 498 |
+
# === Harmonic Saturation / Exciter β Now Included ===
|
| 499 |
+
def harmonic_saturation(audio, saturation_type="Tube", intensity=0.2):
|
| 500 |
+
samples = np.array(audio.get_array_of_samples()).astype(np.float32)
|
| 501 |
+
|
| 502 |
+
if saturation_type == "Tube":
|
| 503 |
+
saturated = np.tanh(intensity * samples)
|
| 504 |
+
elif saturation_type == "Tape":
|
| 505 |
+
saturated = np.where(samples > 0, 1 - np.exp(-intensity * samples), -1 + np.exp(intensity * samples))
|
| 506 |
+
elif saturation_type == "Console":
|
| 507 |
+
saturated = np.clip(samples, -32768, 32768) * intensity
|
| 508 |
+
elif saturation_type == "Mix Bus":
|
| 509 |
+
saturated = np.log1p(np.abs(samples)) * np.sign(samples) * intensity
|
| 510 |
+
else:
|
| 511 |
+
saturated = samples
|
| 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
|
|
|
|
| 536 |
animation: float 3s ease-in-out infinite;
|
| 537 |
}
|
| 538 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 539 |
@keyframes float {
|
| 540 |
0%, 100% { transform: translateY(0); }
|
| 541 |
50% { transform: translateY(-10px); }
|
|
|
|
| 561 |
background-color: #334155 !important;
|
| 562 |
color: white !important;
|
| 563 |
border: 1px solid #475569 !important;
|
|
|
|
| 564 |
width: 100%;
|
| 565 |
padding: 10px;
|
| 566 |
}
|
|
|
|
| 590 |
box-shadow: 0 0 12px #2563eb44;
|
| 591 |
}
|
| 592 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 593 |
@media (max-width: 768px) {
|
| 594 |
.gr-column {
|
| 595 |
min-width: 100%;
|
|
|
|
| 660 |
allow_flagging="never"
|
| 661 |
)
|
| 662 |
|
| 663 |
+
# --- Remix Mode β Apply Effects to Each Stem ===
|
| 664 |
with gr.Tab("π Remix Mode"):
|
| 665 |
with gr.Row():
|
| 666 |
with gr.Column(min_width=200):
|
|
|
|
| 736 |
gr.Dropdown(choices=["Normalize", "Reverb", "Pitch Shift", "Saturation"], label="Effect", value="Normalize")
|
| 737 |
],
|
| 738 |
outputs=gr.Audio(label="Live Output", type="filepath"),
|
| 739 |
+
title="Real-Time Audio Preview",
|
| 740 |
+
description="Preview effects before exporting",
|
| 741 |
allow_flagging="never"
|
| 742 |
)
|
| 743 |
|
|
|
|
| 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 ===
|
|
|
|
| 763 |
gr.Interface(
|
| 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 ===
|
| 772 |
with gr.Tab("π Multi-track Mixing Console"):
|
| 773 |
gr.Interface(
|
| 774 |
fn=mix_tracks,
|
|
|
|
| 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 |
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 |
],
|
| 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()
|