Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -149,6 +149,35 @@ def auto_eq(audio, genre="Pop"):
|
|
| 149 |
|
| 150 |
return array_to_audiosegment(samples.astype(np.int16), sr, channels=audio.channels)
|
| 151 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 152 |
# === Real-Time EQ Sliders ===
|
| 153 |
def real_time_eq(audio, low_gain=0, mid_gain=0, high_gain=0):
|
| 154 |
samples, sr = audiosegment_to_array(audio)
|
|
@@ -177,17 +206,21 @@ genre_preset_map = {
|
|
| 177 |
"Hip-Hop": ["Deep Bass", "Vocal Presence", "Saturation"]
|
| 178 |
}
|
| 179 |
|
| 180 |
-
def suggest_preset_by_genre(
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
# === Create Karaoke Video from Audio + Lyrics ===
|
| 184 |
def create_karaoke_video(audio_path, lyrics, bg_image=None):
|
| 185 |
-
# Placeholder for video generation
|
| 186 |
print(f"Creating karaoke video with lyrics: {lyrics}")
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
return out_path
|
| 191 |
|
| 192 |
# === Vocal Isolation Helpers ===
|
| 193 |
def load_track_local(path, sample_rate, channels=2):
|
|
@@ -515,10 +548,32 @@ def visualize_spectrum(audio_path):
|
|
| 515 |
buf.seek(0)
|
| 516 |
return Image.open(buf)
|
| 517 |
|
| 518 |
-
# === Real-Time EQ
|
| 519 |
def real_time_eq_slider(audio, low_gain, mid_gain, high_gain):
|
| 520 |
return real_time_eq(audio, low_gain, mid_gain, high_gain)
|
| 521 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
# === UI ===
|
| 523 |
effect_options = [
|
| 524 |
"Noise Reduction",
|
|
@@ -807,34 +862,12 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
|
|
| 807 |
with gr.Tab("☁️ Cloud Project Sync"):
|
| 808 |
gr.Markdown("Save your projects online and resume them from any device.")
|
| 809 |
|
| 810 |
-
project_id = gr.Textbox(label="Project ID (optional)")
|
| 811 |
-
project_name = gr.Textbox(label="Project Name")
|
| 812 |
-
project_data = gr.State()
|
| 813 |
-
|
| 814 |
-
def cloud_save_project(audio, preset, effects, name, project_id=""):
|
| 815 |
-
# Simulated cloud saving
|
| 816 |
-
project_data = {
|
| 817 |
-
"audio": AudioSegment.from_file(audio).raw_data,
|
| 818 |
-
"preset": preset,
|
| 819 |
-
"effects": effects
|
| 820 |
-
}
|
| 821 |
-
project_path = os.path.join(tempfile.gettempdir(), f"{name}.aiproj")
|
| 822 |
-
with open(project_path, "wb") as f:
|
| 823 |
-
pickle.dump(project_data, f)
|
| 824 |
-
return project_path, f"✅ Saved as '{name}'"
|
| 825 |
-
|
| 826 |
-
def cloud_load_project(project_id):
|
| 827 |
-
# Simulated cloud loading
|
| 828 |
-
if not project_id:
|
| 829 |
-
return None, None, None
|
| 830 |
-
return "Sample Loaded", ["Noise Reduction", "Normalize"], ["Default"]
|
| 831 |
-
|
| 832 |
gr.Interface(
|
| 833 |
fn=cloud_save_project,
|
| 834 |
inputs=[
|
| 835 |
gr.File(label="Upload Audio", type="filepath"),
|
| 836 |
gr.Dropdown(choices=preset_names, label="Select Preset", value=preset_names[0]),
|
| 837 |
-
gr.CheckboxGroup(choices=effect_options, label="Effects"),
|
| 838 |
gr.Textbox(label="Project Name"),
|
| 839 |
gr.Textbox(label="Project ID (Optional)")
|
| 840 |
],
|
|
@@ -865,7 +898,7 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
|
|
| 865 |
fn=suggest_preset_by_genre,
|
| 866 |
inputs=gr.Audio(label="Upload Track", type="filepath"),
|
| 867 |
outputs=gr.Dropdown(choices=preset_names, label="Recommended Preset"),
|
| 868 |
-
title="AI
|
| 869 |
description="Upload a track and let AI recommend the best preset based on genre."
|
| 870 |
)
|
| 871 |
|
|
@@ -876,7 +909,7 @@ with gr.Blocks(title="AI Audio Studio", css="style.css") as demo:
|
|
| 876 |
inputs=[
|
| 877 |
gr.Audio(label="Upload Track", type="filepath"),
|
| 878 |
gr.Textbox(label="Lyrics", lines=10),
|
| 879 |
-
gr.File(label="Background (Optional)")
|
| 880 |
],
|
| 881 |
outputs=gr.Video(label="Karaoke Video"),
|
| 882 |
title="Make Karaoke Videos from Audio + Lyrics",
|
|
|
|
| 149 |
|
| 150 |
return array_to_audiosegment(samples.astype(np.int16), sr, channels=audio.channels)
|
| 151 |
|
| 152 |
+
# === Prompt-Based Editing ===
|
| 153 |
+
def process_prompt(audio_path, prompt):
|
| 154 |
+
audio = AudioSegment.from_file(audio_path)
|
| 155 |
+
|
| 156 |
+
if "noise" in prompt.lower() or "clean" in prompt.lower():
|
| 157 |
+
audio = apply_noise_reduction(audio)
|
| 158 |
+
|
| 159 |
+
if "normalize" in prompt.lower() or "loud" in prompt.lower():
|
| 160 |
+
audio = apply_normalize(audio)
|
| 161 |
+
|
| 162 |
+
if "bass" in prompt.lower() and ("boost" in prompt.lower()):
|
| 163 |
+
audio = apply_bass_boost(audio)
|
| 164 |
+
|
| 165 |
+
if "treble" in prompt.lower() or "high" in prompt.lower():
|
| 166 |
+
audio = apply_treble_boost(audio)
|
| 167 |
+
|
| 168 |
+
if "echo" in prompt.lower() or "reverb" in prompt.lower():
|
| 169 |
+
audio = apply_reverb(audio)
|
| 170 |
+
|
| 171 |
+
if "pitch" in prompt.lower() and "correct" in prompt.lower():
|
| 172 |
+
audio = apply_pitch_shift(audio, 0) # Placeholder
|
| 173 |
+
|
| 174 |
+
if "harmony" in prompt.lower() or "double" in prompt.lower():
|
| 175 |
+
audio = apply_harmony(audio)
|
| 176 |
+
|
| 177 |
+
out_path = os.path.join(tempfile.gettempdir(), "prompt_output.wav")
|
| 178 |
+
audio.export(out_path, format="wav")
|
| 179 |
+
return out_path
|
| 180 |
+
|
| 181 |
# === Real-Time EQ Sliders ===
|
| 182 |
def real_time_eq(audio, low_gain=0, mid_gain=0, high_gain=0):
|
| 183 |
samples, sr = audiosegment_to_array(audio)
|
|
|
|
| 206 |
"Hip-Hop": ["Deep Bass", "Vocal Presence", "Saturation"]
|
| 207 |
}
|
| 208 |
|
| 209 |
+
def suggest_preset_by_genre(audio_path):
|
| 210 |
+
try:
|
| 211 |
+
y, sr = torchaudio.load(audio_path)
|
| 212 |
+
mfccs = librosa.feature.mfcc(y=y.numpy().flatten(), sr=sr, n_mfcc=13).mean(axis=1).reshape(1, -1)
|
| 213 |
+
genre = "Pop"
|
| 214 |
+
return genre_preset_map.get(genre, ["Default"])
|
| 215 |
+
except Exception:
|
| 216 |
+
return ["Default"]
|
| 217 |
|
| 218 |
# === Create Karaoke Video from Audio + Lyrics ===
|
| 219 |
def create_karaoke_video(audio_path, lyrics, bg_image=None):
|
|
|
|
| 220 |
print(f"Creating karaoke video with lyrics: {lyrics}")
|
| 221 |
+
return apply_auto_gain(AudioSegment.from_file(audio_path)).export(
|
| 222 |
+
os.path.join(tempfile.gettempdir(), "karaoke_output.wav"), format="wav"
|
| 223 |
+
)
|
|
|
|
| 224 |
|
| 225 |
# === Vocal Isolation Helpers ===
|
| 226 |
def load_track_local(path, sample_rate, channels=2):
|
|
|
|
| 548 |
buf.seek(0)
|
| 549 |
return Image.open(buf)
|
| 550 |
|
| 551 |
+
# === Real-Time EQ Slider Wrapper ===
|
| 552 |
def real_time_eq_slider(audio, low_gain, mid_gain, high_gain):
|
| 553 |
return real_time_eq(audio, low_gain, mid_gain, high_gain)
|
| 554 |
|
| 555 |
+
# === Cloud Project Sync (Premium Feature) ===
|
| 556 |
+
def cloud_save_project(audio, preset, effects, project_name, project_id=""):
|
| 557 |
+
project_data = {
|
| 558 |
+
"audio": audio,
|
| 559 |
+
"preset": preset,
|
| 560 |
+
"effects": effects
|
| 561 |
+
}
|
| 562 |
+
project_path = os.path.join(tempfile.gettempdir(), f"{project_name}.aiproj")
|
| 563 |
+
with open(project_path, "wb") as f:
|
| 564 |
+
pickle.dump(project_data, f)
|
| 565 |
+
return project_path, f"✅ '{project_name}' saved to cloud"
|
| 566 |
+
|
| 567 |
+
def cloud_load_project(project_id):
|
| 568 |
+
if not project_id:
|
| 569 |
+
return None, None, None
|
| 570 |
+
try:
|
| 571 |
+
with open(project_id, "rb") as f:
|
| 572 |
+
data = pickle.load(f)
|
| 573 |
+
return data["audio"], data["preset"], data["effects"]
|
| 574 |
+
except Exception:
|
| 575 |
+
return None, None, None
|
| 576 |
+
|
| 577 |
# === UI ===
|
| 578 |
effect_options = [
|
| 579 |
"Noise Reduction",
|
|
|
|
| 862 |
with gr.Tab("☁️ Cloud Project Sync"):
|
| 863 |
gr.Markdown("Save your projects online and resume them from any device.")
|
| 864 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 865 |
gr.Interface(
|
| 866 |
fn=cloud_save_project,
|
| 867 |
inputs=[
|
| 868 |
gr.File(label="Upload Audio", type="filepath"),
|
| 869 |
gr.Dropdown(choices=preset_names, label="Select Preset", value=preset_names[0]),
|
| 870 |
+
gr.CheckboxGroup(choices=effect_options, label="Effects Applied"),
|
| 871 |
gr.Textbox(label="Project Name"),
|
| 872 |
gr.Textbox(label="Project ID (Optional)")
|
| 873 |
],
|
|
|
|
| 898 |
fn=suggest_preset_by_genre,
|
| 899 |
inputs=gr.Audio(label="Upload Track", type="filepath"),
|
| 900 |
outputs=gr.Dropdown(choices=preset_names, label="Recommended Preset"),
|
| 901 |
+
title="Let AI Recommend Best Preset",
|
| 902 |
description="Upload a track and let AI recommend the best preset based on genre."
|
| 903 |
)
|
| 904 |
|
|
|
|
| 909 |
inputs=[
|
| 910 |
gr.Audio(label="Upload Track", type="filepath"),
|
| 911 |
gr.Textbox(label="Lyrics", lines=10),
|
| 912 |
+
gr.File(label="Background (Optional)"),
|
| 913 |
],
|
| 914 |
outputs=gr.Video(label="Karaoke Video"),
|
| 915 |
title="Make Karaoke Videos from Audio + Lyrics",
|