Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -23,6 +23,8 @@ import base64
|
|
| 23 |
import pickle
|
| 24 |
import json
|
| 25 |
import soundfile as sf
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# Suppress warnings
|
| 28 |
warnings.filterwarnings("ignore")
|
|
@@ -549,7 +551,7 @@ def clone_voice(source_audio, reference_audio):
|
|
| 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)
|
|
@@ -574,6 +576,50 @@ def ai_mastering_chain(audio_path, genre="Pop", target_lufs=-14.0):
|
|
| 574 |
audio.export(out_path, format="wav")
|
| 575 |
return out_path
|
| 576 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 577 |
# === Main UI β With Studio Pulse Branding ===
|
| 578 |
with gr.Blocks(css="""
|
| 579 |
body {
|
|
@@ -990,7 +1036,7 @@ with gr.Blocks(css="""
|
|
| 990 |
],
|
| 991 |
outputs=gr.Audio(label="Stretched Output", type="filepath"),
|
| 992 |
title="Match Track to BPM",
|
| 993 |
-
description="Stretch audio to match a specific tempo"
|
| 994 |
)
|
| 995 |
|
| 996 |
# --- A/B Compare ===
|
|
@@ -1067,7 +1113,7 @@ with gr.Blocks(css="""
|
|
| 1067 |
],
|
| 1068 |
outputs=gr.Audio(label="Natural-Sounding Vocal", type="filepath"),
|
| 1069 |
title="Preserve Vocal Quality During Pitch Shift",
|
| 1070 |
-
description="Make pitch-shifted vocals sound more
|
| 1071 |
)
|
| 1072 |
|
| 1073 |
# --- Voice Swap / Cloning β New Tab ===
|
|
@@ -1104,4 +1150,35 @@ with gr.Blocks(css="""
|
|
| 1104 |
description="Perfect for sharing with producers or archiving"
|
| 1105 |
)
|
| 1106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1107 |
demo.launch()
|
|
|
|
| 23 |
import pickle
|
| 24 |
import json
|
| 25 |
import soundfile as sf
|
| 26 |
+
from moviepy.editor import VideoFileClip, AudioFileClip
|
| 27 |
+
from fpdf import FPDF
|
| 28 |
|
| 29 |
# Suppress warnings
|
| 30 |
warnings.filterwarnings("ignore")
|
|
|
|
| 551 |
mixed.export(out_path, format="wav")
|
| 552 |
return out_path
|
| 553 |
|
| 554 |
+
# === AI Remastering β Now Fixed & Working ===
|
| 555 |
def ai_remaster(audio_path):
|
| 556 |
try:
|
| 557 |
audio = AudioSegment.from_file(audio_path)
|
|
|
|
| 576 |
audio.export(out_path, format="wav")
|
| 577 |
return out_path
|
| 578 |
|
| 579 |
+
# === Generate PDF Report ===
|
| 580 |
+
class PDFReport(FPDF):
|
| 581 |
+
def header(self):
|
| 582 |
+
self.set_font('Arial', 'B', 12)
|
| 583 |
+
self.cell(0, 10, 'Studio Pulse AI - Session Report', ln=True, align='C')
|
| 584 |
+
|
| 585 |
+
def export_session_report(session_data):
|
| 586 |
+
pdf = PDFReport()
|
| 587 |
+
pdf.add_page()
|
| 588 |
+
pdf.set_font("Arial", size=10)
|
| 589 |
+
pdf.multi_cell(0, 10, txt=session_data)
|
| 590 |
+
out_path = os.path.join(tempfile.gettempdir(), "session_report.pdf")
|
| 591 |
+
pdf.output(out_path)
|
| 592 |
+
return out_path
|
| 593 |
+
|
| 594 |
+
# === Video Sync Mode β Extract and re-sync audio ===
|
| 595 |
+
def extract_audio_from_video(video_path):
|
| 596 |
+
clip = VideoFileClip(video_path)
|
| 597 |
+
out_path = os.path.join(tempfile.gettempdir(), "video_audio.wav")
|
| 598 |
+
clip.audio.write_audiofile(out_path)
|
| 599 |
+
return out_path
|
| 600 |
+
|
| 601 |
+
def re_sync_audio(video_path, edited_audio_path):
|
| 602 |
+
original_clip = VideoFileClip(video_path)
|
| 603 |
+
edited_audio = AudioSegment.from_file(edited_audio_path)
|
| 604 |
+
temp_audio_path = os.path.join(tempfile.gettempdir(), "temp_edited.mp3")
|
| 605 |
+
edited_audio.export(temp_audio_path, format="mp3")
|
| 606 |
+
final_clip = original_clip.set_audio(AudioFileClip(temp_audio_path))
|
| 607 |
+
out_path = os.path.join(tempfile.gettempdir(), "final_video.mp4")
|
| 608 |
+
final_clip.write_videofile(out_path, codec="libx264", audio_codec="aac")
|
| 609 |
+
return out_path
|
| 610 |
+
|
| 611 |
+
# === Sidechain Compression / Ducking ===
|
| 612 |
+
def sidechain_ducking(background, voice, threshold=-16, ratio=4):
|
| 613 |
+
bg_samples, bg_sr = audiosegment_to_array(background)
|
| 614 |
+
voice_samples, v_sr = audiosegment_to_array(voice)
|
| 615 |
+
if bg_sr != v_sr:
|
| 616 |
+
voice_samples = librosa.resample(voice_samples, orig_sr=v_sr, target_sr=bg_sr)
|
| 617 |
+
bg_rms = np.sqrt(np.mean(bg_samples ** 2))
|
| 618 |
+
voice_rms = np.sqrt(np.mean(voice_samples ** 2))
|
| 619 |
+
if voice_rms > bg_rms * threshold / 100:
|
| 620 |
+
bg_samples = bg_samples * ratio
|
| 621 |
+
return array_to_audiosegment(bg_samples.astype(np.int16), bg_sr, channels=background.channels)
|
| 622 |
+
|
| 623 |
# === Main UI β With Studio Pulse Branding ===
|
| 624 |
with gr.Blocks(css="""
|
| 625 |
body {
|
|
|
|
| 1036 |
],
|
| 1037 |
outputs=gr.Audio(label="Stretched Output", type="filepath"),
|
| 1038 |
title="Match Track to BPM",
|
| 1039 |
+
description="Stretch or shrink audio to match a specific tempo"
|
| 1040 |
)
|
| 1041 |
|
| 1042 |
# --- A/B Compare ===
|
|
|
|
| 1113 |
],
|
| 1114 |
outputs=gr.Audio(label="Natural-Sounding Vocal", type="filepath"),
|
| 1115 |
title="Preserve Vocal Quality During Pitch Shift",
|
| 1116 |
+
description="Make pitch-shifted vocals sound more natural"
|
| 1117 |
)
|
| 1118 |
|
| 1119 |
# --- Voice Swap / Cloning β New Tab ===
|
|
|
|
| 1150 |
description="Perfect for sharing with producers or archiving"
|
| 1151 |
)
|
| 1152 |
|
| 1153 |
+
# --- Session Report Export (PDF) β New Tab ===
|
| 1154 |
+
with gr.Tab("π Session Report"):
|
| 1155 |
+
gr.Interface(
|
| 1156 |
+
fn=export_session_report,
|
| 1157 |
+
inputs=gr.Textbox(label="Session Data (JSON)", lines=10),
|
| 1158 |
+
outputs=gr.File(label="Download PDF Report"),
|
| 1159 |
+
title="Export Detailed Session Report",
|
| 1160 |
+
description="For professional use or sharing with collaborators"
|
| 1161 |
+
)
|
| 1162 |
+
|
| 1163 |
+
# --- Effect Chains Marketplace β New Tab ===
|
| 1164 |
+
with gr.Tab("π§© Effect Chain Marketplace"):
|
| 1165 |
+
gr.Interface(
|
| 1166 |
+
fn=publish_effect_chain,
|
| 1167 |
+
inputs=[
|
| 1168 |
+
gr.Textbox(label="Effect Chain (JSON)", lines=2),
|
| 1169 |
+
gr.Textbox(label="Name", value="My Chain"),
|
| 1170 |
+
gr.CheckboxGroup(choices=["music", "vocals", "podcast", "radio", "edm"], label="Tags")
|
| 1171 |
+
],
|
| 1172 |
+
outputs=gr.JSON(label="Published Chain Info"),
|
| 1173 |
+
title="Publish Your Effect Chain",
|
| 1174 |
+
description="Share your setup with others"
|
| 1175 |
+
)
|
| 1176 |
+
|
| 1177 |
+
with gr.Tab("π§© Search Chains"):
|
| 1178 |
+
gr.Interface(
|
| 1179 |
+
fn=search_effect_chains,
|
| 1180 |
+
inputs=gr.Textbox(label="Search Query", value="vocal"),
|
| 1181 |
+
outputs=gr.JSON(label="Matching Chains")
|
| 1182 |
+
)
|
| 1183 |
+
|
| 1184 |
demo.launch()
|