Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,9 @@ import base64
|
|
| 23 |
import pickle
|
| 24 |
import json
|
| 25 |
import soundfile as sf
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Suppress warnings
|
| 28 |
warnings.filterwarnings("ignore")
|
|
@@ -203,7 +206,7 @@ def stem_split(audio_path):
|
|
| 203 |
stem_paths = []
|
| 204 |
|
| 205 |
for i, name in enumerate(['drums', 'bass', 'other', 'vocals']):
|
| 206 |
-
path = os.path.join(
|
| 207 |
save_track(path, sources[i].cpu(), model.samplerate)
|
| 208 |
stem_paths.append(gr.File(value=path))
|
| 209 |
|
|
@@ -254,7 +257,7 @@ def process_audio(audio_file, selected_effects, isolate_vocals, preset_name, exp
|
|
| 254 |
|
| 255 |
waveform_image = show_waveform(output_path)
|
| 256 |
genre = detect_genre(output_path)
|
| 257 |
-
session_log = generate_session_log(audio_file,
|
| 258 |
|
| 259 |
status = "๐ Done!"
|
| 260 |
return output_path, waveform_image, session_log, genre, status, history
|
|
@@ -526,12 +529,81 @@ def formant_correct(audio, shift=1.0):
|
|
| 526 |
corrected = librosa.effects.pitch_shift(samples, sr=sr, n_steps=shift)
|
| 527 |
return array_to_audiosegment(corrected.astype(np.int16), sr, channels=audio.channels)
|
| 528 |
|
| 529 |
-
# ===
|
| 530 |
-
def
|
| 531 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 532 |
|
| 533 |
-
|
| 534 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 535 |
|
| 536 |
# === Main UI โ With Studio Pulse Branding ===
|
| 537 |
with gr.Blocks(css="""
|
|
@@ -721,7 +793,7 @@ with gr.Blocks(css="""
|
|
| 721 |
output_other = gr.Audio(label="Processed Other", type="filepath")
|
| 722 |
btn_other.click(fn=apply_effects_to_stem, inputs=[other_path, other_effects], outputs=output_other)
|
| 723 |
|
| 724 |
-
# --- AI Remastering Tab โ
|
| 725 |
with gr.Tab("๐ฎ AI Remastering"):
|
| 726 |
gr.Interface(
|
| 727 |
fn=ai_remaster,
|
|
@@ -742,8 +814,7 @@ with gr.Blocks(css="""
|
|
| 742 |
],
|
| 743 |
outputs=gr.Audio(label="Warm Output", type="filepath"),
|
| 744 |
title="Add Analog-Style Warmth",
|
| 745 |
-
description="Enhance clarity and presence using saturation styles like Tube or Tape."
|
| 746 |
-
allow_flagging="never"
|
| 747 |
)
|
| 748 |
|
| 749 |
# --- Vocal Doubler / Harmonizer โ Added ===
|
|
@@ -796,7 +867,6 @@ with gr.Blocks(css="""
|
|
| 796 |
y_np = y.numpy().flatten()
|
| 797 |
stft = librosa.stft(y_np)
|
| 798 |
db = librosa.amplitude_to_db(abs(stft))
|
| 799 |
-
|
| 800 |
plt.figure(figsize=(10, 4))
|
| 801 |
img = librosa.display.specshow(db, sr=sr, x_axis="time", y_axis="hz", cmap="magma")
|
| 802 |
plt.colorbar(img, format="%+2.0f dB")
|
|
@@ -812,9 +882,7 @@ with gr.Blocks(css="""
|
|
| 812 |
gr.Interface(
|
| 813 |
fn=visualize_spectrum,
|
| 814 |
inputs=gr.Audio(label="Upload Track", type="filepath"),
|
| 815 |
-
outputs=gr.Image(label="Spectrum Analysis")
|
| 816 |
-
title="Real-Time Spectrum Analyzer",
|
| 817 |
-
description="See the frequency breakdown of your audio"
|
| 818 |
)
|
| 819 |
|
| 820 |
# --- Loudness Graph Tab โ EBU R128 Matching ===
|
|
@@ -970,7 +1038,7 @@ with gr.Blocks(css="""
|
|
| 970 |
allow_flagging="never"
|
| 971 |
)
|
| 972 |
|
| 973 |
-
# --- Loop
|
| 974 |
with gr.Tab("๐ Loop Playback"):
|
| 975 |
gr.Interface(
|
| 976 |
fn=loop_section,
|
|
@@ -988,7 +1056,7 @@ with gr.Blocks(css="""
|
|
| 988 |
# --- Share Effect Chain Tab โ Now Defined! ===
|
| 989 |
with gr.Tab("๐ Share Effect Chain"):
|
| 990 |
gr.Interface(
|
| 991 |
-
fn=
|
| 992 |
inputs=gr.CheckboxGroup(choices=preset_choices["Default"]),
|
| 993 |
outputs=gr.Textbox(label="Share Code", lines=2),
|
| 994 |
title="Copy/Paste Effect Chain",
|
|
@@ -997,7 +1065,7 @@ with gr.Blocks(css="""
|
|
| 997 |
|
| 998 |
with gr.Tab("๐ฅ Load Shared Chain"):
|
| 999 |
gr.Interface(
|
| 1000 |
-
fn=
|
| 1001 |
inputs=gr.Textbox(label="Paste Shared Code", lines=2),
|
| 1002 |
outputs=gr.CheckboxGroup(choices=preset_choices["Default"], label="Loaded Effects"),
|
| 1003 |
title="Restore From Shared Chain",
|
|
@@ -1010,14 +1078,14 @@ with gr.Blocks(css="""
|
|
| 1010 |
### Keyboard Controls
|
| 1011 |
- `Ctrl + Z`: Undo last effect
|
| 1012 |
- `Ctrl + Y`: Redo
|
| 1013 |
-
- `Spacebar`: Play/Stop
|
| 1014 |
- `Ctrl + S`: Save current session
|
| 1015 |
- `Ctrl + O`: Open session
|
| 1016 |
- `Ctrl + C`: Copy effect chain
|
| 1017 |
- `Ctrl + V`: Paste effect chain
|
| 1018 |
- `Ctrl + Shift + L`: Loop selection
|
| 1019 |
-
- `Ctrl + Shift + P`: Export PDF report
|
| 1020 |
-
- `Ctrl + Shift + M`: Export full mix ZIP
|
| 1021 |
""")
|
| 1022 |
|
| 1023 |
# --- Vocal Formant Correction โ Now Defined! ===
|
|
@@ -1033,4 +1101,64 @@ with gr.Blocks(css="""
|
|
| 1033 |
description="Make pitch-shifted vocals sound more human"
|
| 1034 |
)
|
| 1035 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1036 |
demo.launch()
|
|
|
|
| 23 |
import pickle
|
| 24 |
import json
|
| 25 |
import soundfile as sf
|
| 26 |
+
import wave
|
| 27 |
+
import struct
|
| 28 |
+
from fpdf import FPDF
|
| 29 |
|
| 30 |
# Suppress warnings
|
| 31 |
warnings.filterwarnings("ignore")
|
|
|
|
| 206 |
stem_paths = []
|
| 207 |
|
| 208 |
for i, name in enumerate(['drums', 'bass', 'other', 'vocals']):
|
| 209 |
+
path = os.path.join(outputfile_dir, f"{name}.wav")
|
| 210 |
save_track(path, sources[i].cpu(), model.samplerate)
|
| 211 |
stem_paths.append(gr.File(value=path))
|
| 212 |
|
|
|
|
| 257 |
|
| 258 |
waveform_image = show_waveform(output_path)
|
| 259 |
genre = detect_genre(output_path)
|
| 260 |
+
session_log = generate_session_log(audio_file, selected_effects, isolate_vocals, export_format, genre)
|
| 261 |
|
| 262 |
status = "๐ Done!"
|
| 263 |
return output_path, waveform_image, session_log, genre, status, history
|
|
|
|
| 529 |
corrected = librosa.effects.pitch_shift(samples, sr=sr, n_steps=shift)
|
| 530 |
return array_to_audiosegment(corrected.astype(np.int16), sr, channels=audio.channels)
|
| 531 |
|
| 532 |
+
# === DAW Template Generator ===
|
| 533 |
+
def generate_ableton_template(stems):
|
| 534 |
+
# Simulate template metadata
|
| 535 |
+
template = {
|
| 536 |
+
"format": "Ableton Live",
|
| 537 |
+
"stems": [os.path.basename(s) for s in stems],
|
| 538 |
+
"effects": ["Reverb", "EQ", "Compression"],
|
| 539 |
+
"tempo": 128,
|
| 540 |
+
"title": "Studio Pulse Project"
|
| 541 |
+
}
|
| 542 |
+
out_path = os.path.join(tempfile.gettempdir(), "ableton_template.json")
|
| 543 |
+
with open(out_path, "w") as f:
|
| 544 |
+
json.dump(template, f, indent=2)
|
| 545 |
+
return out_path
|
| 546 |
+
|
| 547 |
+
# === Multi-stem ZIP Export ===
|
| 548 |
+
def export_full_mix(stems, final_mix):
|
| 549 |
+
zip_path = os.path.join(tempfile.gettempdir(), "full_export.zip")
|
| 550 |
+
with zipfile.ZipFile(zip_path, "w") as zipf:
|
| 551 |
+
for i, stem in enumerate(stems):
|
| 552 |
+
zipf.write(stem, f"stem_{i}.wav")
|
| 553 |
+
zipf.write(final_mix, "final_mix.wav")
|
| 554 |
+
return zip_path
|
| 555 |
+
|
| 556 |
+
# === Export Session Report (PDF) ===
|
| 557 |
+
class PDFReport(FPDF):
|
| 558 |
+
def header(self):
|
| 559 |
+
self.set_font('Arial', 'B', 12)
|
| 560 |
+
self.cell(0, 10, 'Studio Pulse Session Report', ln=True, align='C')
|
| 561 |
+
|
| 562 |
+
def export_session_report(session_data):
|
| 563 |
+
pdf = PDFReport()
|
| 564 |
+
pdf.add_page()
|
| 565 |
+
pdf.set_font("Arial", size=10)
|
| 566 |
+
pdf.multi_cell(0, 10, txt=session_data)
|
| 567 |
+
out_path = os.path.join(tempfile.gettempdir(), "session_report.pdf")
|
| 568 |
+
pdf.output(out_path)
|
| 569 |
+
return out_path
|
| 570 |
|
| 571 |
+
# === AI Sound Design (Text-to-Sound) ===
|
| 572 |
+
def text_to_sound(prompt):
|
| 573 |
+
# Placeholder logic
|
| 574 |
+
tts = TTS(model="tts_models/en/vctk/vits")
|
| 575 |
+
out_path = os.path.join(tempfile.gettempdir(), "generated_sound.wav")
|
| 576 |
+
tts.tts_to_file(text=prompt, speaker="p225", file_path=out_path)
|
| 577 |
+
return out_path
|
| 578 |
+
|
| 579 |
+
# === Video Sync Mode ===
|
| 580 |
+
def extract_audio_from_video(video_path):
|
| 581 |
+
clip = VideoFileClip(video_path)
|
| 582 |
+
out_path = os.path.join(tempfile.gettempdir(), "video_audio.wav")
|
| 583 |
+
clip.audio.write_audiofile(out_path)
|
| 584 |
+
return out_path
|
| 585 |
+
|
| 586 |
+
def re_sync_audio(video_path, edited_audio_path):
|
| 587 |
+
original_clip = VideoFileClip(video_path)
|
| 588 |
+
edited_audio = AudioSegment.from_file(edited_audio_path)
|
| 589 |
+
temp_audio_path = os.path.join(tempfile.gettempdir(), "temp_edited.mp3")
|
| 590 |
+
edited_audio.export(temp_audio_path, format="mp3")
|
| 591 |
+
final_clip = original_clip.set_audio(temp_audio_path)
|
| 592 |
+
out_path = os.path.join(tempfile.gettempdir(), "final_video.mp4")
|
| 593 |
+
final_clip.write_videofile(out_path, codec="libx264", audio_codec="aac")
|
| 594 |
+
return out_path
|
| 595 |
+
|
| 596 |
+
# === Sidechain Compression / Ducking ===
|
| 597 |
+
def sidechain_ducking(background, voice, threshold=-16, ratio=4):
|
| 598 |
+
bg_samples, bg_sr = audiosegment_to_array(background)
|
| 599 |
+
voice_samples, v_sr = audiosegment_to_array(voice)
|
| 600 |
+
if bg_sr != v_sr:
|
| 601 |
+
voice_samples = librosa.resample(voice_samples, orig_sr=v_sr, target_sr=bg_sr)
|
| 602 |
+
bg_rms = np.sqrt(np.mean(bg_samples ** 2))
|
| 603 |
+
voice_rms = np.sqrt(np.mean(voice_samples ** 2))
|
| 604 |
+
if voice_rms > bg_rms * threshold / 100:
|
| 605 |
+
bg_samples = bg_samples * ratio
|
| 606 |
+
return array_to_audiosegment(bg_samples.astype(np.int16), bg_sr, channels=background.channels)
|
| 607 |
|
| 608 |
# === Main UI โ With Studio Pulse Branding ===
|
| 609 |
with gr.Blocks(css="""
|
|
|
|
| 793 |
output_other = gr.Audio(label="Processed Other", type="filepath")
|
| 794 |
btn_other.click(fn=apply_effects_to_stem, inputs=[other_path, other_effects], outputs=output_other)
|
| 795 |
|
| 796 |
+
# --- AI Remastering Tab โ New Feature (Fixed) ===
|
| 797 |
with gr.Tab("๐ฎ AI Remastering"):
|
| 798 |
gr.Interface(
|
| 799 |
fn=ai_remaster,
|
|
|
|
| 814 |
],
|
| 815 |
outputs=gr.Audio(label="Warm Output", type="filepath"),
|
| 816 |
title="Add Analog-Style Warmth",
|
| 817 |
+
description="Enhance clarity and presence using saturation styles like Tube or Tape."
|
|
|
|
| 818 |
)
|
| 819 |
|
| 820 |
# --- Vocal Doubler / Harmonizer โ Added ===
|
|
|
|
| 867 |
y_np = y.numpy().flatten()
|
| 868 |
stft = librosa.stft(y_np)
|
| 869 |
db = librosa.amplitude_to_db(abs(stft))
|
|
|
|
| 870 |
plt.figure(figsize=(10, 4))
|
| 871 |
img = librosa.display.specshow(db, sr=sr, x_axis="time", y_axis="hz", cmap="magma")
|
| 872 |
plt.colorbar(img, format="%+2.0f dB")
|
|
|
|
| 882 |
gr.Interface(
|
| 883 |
fn=visualize_spectrum,
|
| 884 |
inputs=gr.Audio(label="Upload Track", type="filepath"),
|
| 885 |
+
outputs=gr.Image(label="Spectrum Analysis")
|
|
|
|
|
|
|
| 886 |
)
|
| 887 |
|
| 888 |
# --- Loudness Graph Tab โ EBU R128 Matching ===
|
|
|
|
| 1038 |
allow_flagging="never"
|
| 1039 |
)
|
| 1040 |
|
| 1041 |
+
# --- Loop Playback ===
|
| 1042 |
with gr.Tab("๐ Loop Playback"):
|
| 1043 |
gr.Interface(
|
| 1044 |
fn=loop_section,
|
|
|
|
| 1056 |
# --- Share Effect Chain Tab โ Now Defined! ===
|
| 1057 |
with gr.Tab("๐ Share Effect Chain"):
|
| 1058 |
gr.Interface(
|
| 1059 |
+
fn=lambda x: json.dumps(x),
|
| 1060 |
inputs=gr.CheckboxGroup(choices=preset_choices["Default"]),
|
| 1061 |
outputs=gr.Textbox(label="Share Code", lines=2),
|
| 1062 |
title="Copy/Paste Effect Chain",
|
|
|
|
| 1065 |
|
| 1066 |
with gr.Tab("๐ฅ Load Shared Chain"):
|
| 1067 |
gr.Interface(
|
| 1068 |
+
fn=json.loads,
|
| 1069 |
inputs=gr.Textbox(label="Paste Shared Code", lines=2),
|
| 1070 |
outputs=gr.CheckboxGroup(choices=preset_choices["Default"], label="Loaded Effects"),
|
| 1071 |
title="Restore From Shared Chain",
|
|
|
|
| 1078 |
### Keyboard Controls
|
| 1079 |
- `Ctrl + Z`: Undo last effect
|
| 1080 |
- `Ctrl + Y`: Redo
|
| 1081 |
+
- `Spacebar`: Play/Stop playback
|
| 1082 |
- `Ctrl + S`: Save current session
|
| 1083 |
- `Ctrl + O`: Open session
|
| 1084 |
- `Ctrl + C`: Copy effect chain
|
| 1085 |
- `Ctrl + V`: Paste effect chain
|
| 1086 |
- `Ctrl + Shift + L`: Loop selection
|
| 1087 |
+
- `Ctrl + Shift + P`: Export to PDF report
|
| 1088 |
+
- `Ctrl + Shift + M`: Export full mix ZIP
|
| 1089 |
""")
|
| 1090 |
|
| 1091 |
# --- Vocal Formant Correction โ Now Defined! ===
|
|
|
|
| 1101 |
description="Make pitch-shifted vocals sound more human"
|
| 1102 |
)
|
| 1103 |
|
| 1104 |
+
# --- DAW Template Export ===
|
| 1105 |
+
with gr.Tab("๐ DAW Template Export"):
|
| 1106 |
+
gr.Interface(
|
| 1107 |
+
fn=generate_ableton_template,
|
| 1108 |
+
inputs=[gr.File(label="Upload Stems", file_count="multiple")],
|
| 1109 |
+
outputs=gr.File(label="DAW Template (.json/.als/.flp)")
|
| 1110 |
+
)
|
| 1111 |
+
|
| 1112 |
+
# --- Export Full Mix ZIP ===
|
| 1113 |
+
with gr.Tab("๐ Export Full Mix ZIP"):
|
| 1114 |
+
gr.Interface(
|
| 1115 |
+
fn=export_full_mix,
|
| 1116 |
+
inputs=[
|
| 1117 |
+
gr.File(label="Stems", file_count="multiple"),
|
| 1118 |
+
gr.File(label="Final Mix")
|
| 1119 |
+
],
|
| 1120 |
+
outputs=gr.File(label="Full Mix Archive (.zip)"),
|
| 1121 |
+
title="Export Stems + Final Mix Together",
|
| 1122 |
+
description="Perfect for sharing with producers or archiving"
|
| 1123 |
+
)
|
| 1124 |
+
|
| 1125 |
+
# --- AI Sound Design โ Text to Audio Generation ===
|
| 1126 |
+
with gr.Tab("๐ง AI Sound Design"):
|
| 1127 |
+
gr.Interface(
|
| 1128 |
+
fn=text_to_sound,
|
| 1129 |
+
inputs=gr.Textbox(label="Describe a Sound", lines=5),
|
| 1130 |
+
outputs=gr.Audio(label="Generated Sound", type="filepath"),
|
| 1131 |
+
title="Generate Sounds from Text",
|
| 1132 |
+
description="Describe a sound โ AI generates it"
|
| 1133 |
+
)
|
| 1134 |
+
|
| 1135 |
+
# --- Session Report Export (PDF) ===
|
| 1136 |
+
with gr.Tab("๐ Session Report"):
|
| 1137 |
+
gr.Interface(
|
| 1138 |
+
fn=export_session_report,
|
| 1139 |
+
inputs=gr.Textbox(label="Session Data (JSON)", lines=10),
|
| 1140 |
+
outputs=gr.File(label="Download PDF Report"),
|
| 1141 |
+
title="Export Detailed Session Report",
|
| 1142 |
+
description="For professional use or sharing with collaborators"
|
| 1143 |
+
)
|
| 1144 |
+
|
| 1145 |
+
# --- Video Sync Mode โ Now Included ===
|
| 1146 |
+
with gr.Tab("๐ฝ Video Sync Mode"):
|
| 1147 |
+
with gr.Row():
|
| 1148 |
+
with gr.Column(min_width=300):
|
| 1149 |
+
input_video = gr.Video(label="Upload Video", type="filepath")
|
| 1150 |
+
extract_btn = gr.Button("Extract Audio")
|
| 1151 |
+
extracted_audio = gr.Audio(label="Extracted Audio", type="filepath")
|
| 1152 |
+
effect_checkbox_video = gr.CheckboxGroup(choices=preset_choices["Default"], label="Apply Effects")
|
| 1153 |
+
process_btn_video = gr.Button("Process Audio")
|
| 1154 |
+
with gr.Column(min_width=300):
|
| 1155 |
+
processed_audio = gr.Audio(label="Edited Audio", type="filepath")
|
| 1156 |
+
re_sync_btn = gr.Button("Sync Back to Video")
|
| 1157 |
+
output_video = gr.Video(label="Final Video", type="filepath")
|
| 1158 |
+
|
| 1159 |
+
extract_btn.click(fn=extract_audio_from_video, inputs=input_video, outputs=extracted_audio)
|
| 1160 |
+
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")],
|
| 1161 |
+
outputs=[processed_audio])
|
| 1162 |
+
re_sync_btn.click(fn=re_sync_audio, inputs=[input_video, processed_audio], outputs=output_video)
|
| 1163 |
+
|
| 1164 |
demo.launch()
|