Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -26,13 +26,21 @@ import json
|
|
| 26 |
# Suppress warnings
|
| 27 |
warnings.filterwarnings("ignore")
|
| 28 |
|
|
|
|
| 29 |
try:
|
| 30 |
-
|
| 31 |
except ImportError:
|
| 32 |
-
print("Installing
|
| 33 |
import subprocess
|
| 34 |
-
subprocess.run(["pip", "install", "
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
# === Helper Functions ===
|
| 38 |
def audiosegment_to_array(audio):
|
|
@@ -441,6 +449,26 @@ def visualize_spectrum(audio_path):
|
|
| 441 |
buf.seek(0)
|
| 442 |
return Image.open(buf)
|
| 443 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
# === Main UI โ With Studio Pulse Branding ===
|
| 445 |
with gr.Blocks(css="""
|
| 446 |
body {
|
|
@@ -473,7 +501,6 @@ with gr.Blocks(css="""
|
|
| 473 |
border-radius: 12px;
|
| 474 |
padding: 15px;
|
| 475 |
box-shadow: 0 0 10px #1f7bbd44;
|
| 476 |
-
border: none;
|
| 477 |
transition: all 0.3s ease;
|
| 478 |
}
|
| 479 |
|
|
@@ -497,21 +524,6 @@ with gr.Blocks(css="""
|
|
| 497 |
box-shadow: 0 0 15px #3b82f6aa;
|
| 498 |
}
|
| 499 |
|
| 500 |
-
.gr-tabs button {
|
| 501 |
-
font-size: 16px;
|
| 502 |
-
padding: 10px 20px;
|
| 503 |
-
border-radius: 8px;
|
| 504 |
-
background: #1e293b;
|
| 505 |
-
color: white;
|
| 506 |
-
transition: all 0.3s ease;
|
| 507 |
-
}
|
| 508 |
-
|
| 509 |
-
.gr-tabs button:hover {
|
| 510 |
-
background: #3b82f6;
|
| 511 |
-
color: black;
|
| 512 |
-
box-shadow: 0 0 10px #3b82f6aa;
|
| 513 |
-
}
|
| 514 |
-
|
| 515 |
input[type="text"], input[type="number"], select, textarea {
|
| 516 |
background-color: #334155 !important;
|
| 517 |
color: white !important;
|
|
@@ -643,6 +655,16 @@ with gr.Blocks(css="""
|
|
| 643 |
clear_btn=None
|
| 644 |
)
|
| 645 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 646 |
# --- Harmonic Saturation / Exciter โ Now Included ===
|
| 647 |
with gr.Tab("๐งฌ Harmonic Saturation"):
|
| 648 |
gr.Interface(
|
|
@@ -699,8 +721,7 @@ with gr.Blocks(css="""
|
|
| 699 |
],
|
| 700 |
outputs=gr.Audio(label="Pitch-Corrected Output", type="filepath"),
|
| 701 |
title="AI Auto-Tune",
|
| 702 |
-
description="Correct vocal pitch automatically using AI"
|
| 703 |
-
allow_flagging="never"
|
| 704 |
)
|
| 705 |
|
| 706 |
# --- Frequency Spectrum Tab โ Real-time Visualizer ===
|
|
@@ -753,7 +774,8 @@ with gr.Blocks(css="""
|
|
| 753 |
],
|
| 754 |
outputs=gr.File(label="Project File (.aiproj)"),
|
| 755 |
title="Save Everything Together",
|
| 756 |
-
description="Save your session, effects, and settings in one file to reuse later."
|
|
|
|
| 757 |
)
|
| 758 |
|
| 759 |
gr.Interface(
|
|
@@ -767,29 +789,6 @@ with gr.Blocks(css="""
|
|
| 767 |
description="Load your saved session"
|
| 768 |
)
|
| 769 |
|
| 770 |
-
# --- Preset Cards Gallery โ Visual Selection ===
|
| 771 |
-
with gr.Tab("๐ Preset Gallery"):
|
| 772 |
-
gr.Markdown("### Select a preset visually")
|
| 773 |
-
preset_gallery = gr.Gallery(value=[
|
| 774 |
-
("https://picsum.photos/id/10/150/100", "Pop"),
|
| 775 |
-
("https://picsum.photos/id/20/150/100", "EDM"),
|
| 776 |
-
("https://picsum.photos/id/30/150/100", "Rock"),
|
| 777 |
-
("https://picsum.photos/id/40/150/100", "Hip-Hop"),
|
| 778 |
-
("https://picsum.photos/id/50/150/100", "R&B"),
|
| 779 |
-
("https://picsum.photos/id/60/150/100", "Soul"),
|
| 780 |
-
("https://picsum.photos/id/70/150/100", "Funk")
|
| 781 |
-
], label="Preset Cards", columns=4, height="auto")
|
| 782 |
-
|
| 783 |
-
preset_name_out = gr.Dropdown(choices=preset_names, label="Selected Preset")
|
| 784 |
-
preset_effects_out = gr.CheckboxGroup(choices=list(preset_choices["Default"]), label="Effects")
|
| 785 |
-
|
| 786 |
-
def load_preset_by_card(evt: gr.SelectData):
|
| 787 |
-
index = evt.index % len(preset_names)
|
| 788 |
-
name = preset_names[index]
|
| 789 |
-
return name, preset_choices[name]
|
| 790 |
-
|
| 791 |
-
preset_gallery.select(fn=load_preset_by_card, inputs=[], outputs=[preset_name_out, preset_effects_out])
|
| 792 |
-
|
| 793 |
# --- Prompt-Based Editing Tab โ Added Back ===
|
| 794 |
def process_prompt(audio, prompt):
|
| 795 |
return apply_noise_reduction(audio)
|
|
|
|
| 26 |
# Suppress warnings
|
| 27 |
warnings.filterwarnings("ignore")
|
| 28 |
|
| 29 |
+
# Try importing speechbrain for remastering
|
| 30 |
try:
|
| 31 |
+
from speechbrain.inference.denoisers import SEEnhance
|
| 32 |
except ImportError:
|
| 33 |
+
print("Installing SpeechBrain...")
|
| 34 |
import subprocess
|
| 35 |
+
subprocess.run(["pip", "install", "speechbrain"])
|
| 36 |
+
from speechbrain.inference.denoisers import SEEnhance
|
| 37 |
+
|
| 38 |
+
# Load denoiser model
|
| 39 |
+
try:
|
| 40 |
+
enhancer = SEEnhance.from_hparams(source="speechbrain/reverb-wpe-wsj0-wsj0mix", savedir="remaster_model")
|
| 41 |
+
except Exception as e:
|
| 42 |
+
enhancer = None
|
| 43 |
+
print("SpeechBrain model not available:", str(e))
|
| 44 |
|
| 45 |
# === Helper Functions ===
|
| 46 |
def audiosegment_to_array(audio):
|
|
|
|
| 449 |
buf.seek(0)
|
| 450 |
return Image.open(buf)
|
| 451 |
|
| 452 |
+
# === AI Remastering Tab โ New Feature ===
|
| 453 |
+
def ai_remaster(audio_path):
|
| 454 |
+
try:
|
| 455 |
+
# Step 1: Noise reduction
|
| 456 |
+
audio = AudioSegment.from_file(audio_path)
|
| 457 |
+
samples, sr = audiosegment_to_array(audio)
|
| 458 |
+
reduced = nr.reduce_noise(y=samples, sr=sr)
|
| 459 |
+
cleaned = array_to_audiosegment(reduced, sr, channels=audio.channels)
|
| 460 |
+
|
| 461 |
+
# Step 2: Vocal isolation
|
| 462 |
+
isolated_path = apply_vocal_isolation(cleaned.export(os.path.join(tempfile.gettempdir(), "cleaned.wav"), format="wav")
|
| 463 |
+
|
| 464 |
+
# Step 3: Apply mastering chain
|
| 465 |
+
mastered_path = ai_mastering_chain(isolated_path, genre="Pop", target_lufs=-14.0)
|
| 466 |
+
|
| 467 |
+
return mastered_path
|
| 468 |
+
|
| 469 |
+
except Exception as e:
|
| 470 |
+
return None
|
| 471 |
+
|
| 472 |
# === Main UI โ With Studio Pulse Branding ===
|
| 473 |
with gr.Blocks(css="""
|
| 474 |
body {
|
|
|
|
| 501 |
border-radius: 12px;
|
| 502 |
padding: 15px;
|
| 503 |
box-shadow: 0 0 10px #1f7bbd44;
|
|
|
|
| 504 |
transition: all 0.3s ease;
|
| 505 |
}
|
| 506 |
|
|
|
|
| 524 |
box-shadow: 0 0 15px #3b82f6aa;
|
| 525 |
}
|
| 526 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 527 |
input[type="text"], input[type="number"], select, textarea {
|
| 528 |
background-color: #334155 !important;
|
| 529 |
color: white !important;
|
|
|
|
| 655 |
clear_btn=None
|
| 656 |
)
|
| 657 |
|
| 658 |
+
# --- AI Remastering Tab โ New Feature ===
|
| 659 |
+
with gr.Tab("๐ฎ AI Remastering"):
|
| 660 |
+
gr.Interface(
|
| 661 |
+
fn=ai_remaster,
|
| 662 |
+
inputs=gr.Audio(label="Upload Low-Quality Recording", type="filepath"),
|
| 663 |
+
outputs=gr.Audio(label="Studio-Grade Output", type="filepath"),
|
| 664 |
+
title="Transform Low-Quality Recordings to Studio Sound",
|
| 665 |
+
description="Uses noise reduction, vocal isolation, and mastering to enhance old, low-quality audio."
|
| 666 |
+
)
|
| 667 |
+
|
| 668 |
# --- Harmonic Saturation / Exciter โ Now Included ===
|
| 669 |
with gr.Tab("๐งฌ Harmonic Saturation"):
|
| 670 |
gr.Interface(
|
|
|
|
| 721 |
],
|
| 722 |
outputs=gr.Audio(label="Pitch-Corrected Output", type="filepath"),
|
| 723 |
title="AI Auto-Tune",
|
| 724 |
+
description="Correct vocal pitch automatically using AI"
|
|
|
|
| 725 |
)
|
| 726 |
|
| 727 |
# --- Frequency Spectrum Tab โ Real-time Visualizer ===
|
|
|
|
| 774 |
],
|
| 775 |
outputs=gr.File(label="Project File (.aiproj)"),
|
| 776 |
title="Save Everything Together",
|
| 777 |
+
description="Save your session, effects, and settings in one file to reuse later.",
|
| 778 |
+
allow_flagging="never"
|
| 779 |
)
|
| 780 |
|
| 781 |
gr.Interface(
|
|
|
|
| 789 |
description="Load your saved session"
|
| 790 |
)
|
| 791 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 792 |
# --- Prompt-Based Editing Tab โ Added Back ===
|
| 793 |
def process_prompt(audio, prompt):
|
| 794 |
return apply_noise_reduction(audio)
|