Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,7 +34,7 @@ def file_to_base64_audio(file_path, mime_type="audio/wav"):
|
|
| 34 |
b64 = base64.b64encode(data).decode()
|
| 35 |
return f"data:{mime_type};base64,{b64}"
|
| 36 |
|
| 37 |
-
# ===
|
| 38 |
def apply_normalize(audio):
|
| 39 |
return audio.normalize()
|
| 40 |
|
|
@@ -166,7 +166,7 @@ def auto_eq(audio, genre="Pop"):
|
|
| 166 |
}
|
| 167 |
from scipy.signal import butter, sosfilt
|
| 168 |
def band_eq(samples, sr, lowcut, highcut, gain):
|
| 169 |
-
sos = butter(10, [lowcut,
|
| 170 |
filtered = sosfilt(sos, samples)
|
| 171 |
return samples + gain * filtered
|
| 172 |
|
|
@@ -208,11 +208,13 @@ def stem_split(audio_path):
|
|
| 208 |
wav = load_track_local(audio_path, model.samplerate, channels=2)
|
| 209 |
sources = apply_model(model, wav[None])[0]
|
| 210 |
output_dir = tempfile.mkdtemp()
|
| 211 |
-
stem_paths = [
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
| 213 |
path = os.path.join(output_dir, f"{name}.wav")
|
| 214 |
save_track(path, sources[i].cpu(), model.samplerate)
|
| 215 |
-
stem_paths.append(gr.File(value=path))
|
| 216 |
return stem_paths
|
| 217 |
|
| 218 |
# === Process Audio Function β Fully Featured ===
|
|
@@ -262,7 +264,6 @@ def process_audio(audio_file, selected_effects, isolate_vocals, preset_name, exp
|
|
| 262 |
session_log = generate_session_log(audio_file, selected_effects, isolate_vocals, export_format, genre)
|
| 263 |
status = "π Done!"
|
| 264 |
return output_path, waveform_image, session_log, genre, status, history
|
| 265 |
-
|
| 266 |
except Exception as e:
|
| 267 |
status = f"β Error: {str(e)}"
|
| 268 |
return None, None, status, "", status, []
|
|
@@ -454,7 +455,7 @@ def auto_tune_vocal(audio_path, target_key="C"):
|
|
| 454 |
semitones = key_to_semitone(target_key)
|
| 455 |
tuned_audio = apply_pitch_shift(audio, semitones)
|
| 456 |
out_path = save_audiosegment_to_temp(tuned_audio, ".wav")
|
| 457 |
-
return
|
| 458 |
except Exception as e:
|
| 459 |
print(f"Auto-Tune Error: {e}")
|
| 460 |
return None
|
|
@@ -546,14 +547,9 @@ with gr.Blocks(css="""
|
|
| 546 |
color: white !important;
|
| 547 |
border-radius: 10px;
|
| 548 |
padding: 10px 20px;
|
| 549 |
-
font-weight: bold;
|
| 550 |
box-shadow: 0 0 10px #2563eb44;
|
| 551 |
border: none;
|
| 552 |
}
|
| 553 |
-
.gr-button:hover {
|
| 554 |
-
background-color: #3b82f6 !important;
|
| 555 |
-
box-shadow: 0 0 15px #3b82f6aa;
|
| 556 |
-
}
|
| 557 |
input[type="text"], select, textarea {
|
| 558 |
background-color: #334155 !important;
|
| 559 |
color: white !important;
|
|
@@ -843,7 +839,9 @@ with gr.Blocks(css="""
|
|
| 843 |
gr.Interface(
|
| 844 |
fn=generate_ableton_template,
|
| 845 |
inputs=[gr.File(label="Upload Stems", file_count="multiple")],
|
| 846 |
-
outputs=gr.File(label="DAW Template (.json/.als/.flp)")
|
|
|
|
|
|
|
| 847 |
)
|
| 848 |
|
| 849 |
# --- Export Full Mix ZIP β Added Back ===
|
|
|
|
| 34 |
b64 = base64.b64encode(data).decode()
|
| 35 |
return f"data:{mime_type};base64,{b64}"
|
| 36 |
|
| 37 |
+
# === Effect Functions ===
|
| 38 |
def apply_normalize(audio):
|
| 39 |
return audio.normalize()
|
| 40 |
|
|
|
|
| 166 |
}
|
| 167 |
from scipy.signal import butter, sosfilt
|
| 168 |
def band_eq(samples, sr, lowcut, highcut, gain):
|
| 169 |
+
sos = butter(10, [lowcut, highhighcut], btype='band', output='sos', fs=sr)
|
| 170 |
filtered = sosfilt(sos, samples)
|
| 171 |
return samples + gain * filtered
|
| 172 |
|
|
|
|
| 208 |
wav = load_track_local(audio_path, model.samplerate, channels=2)
|
| 209 |
sources = apply_model(model, wav[None])[0]
|
| 210 |
output_dir = tempfile.mkdtemp()
|
| 211 |
+
stem_paths = [
|
| 212 |
+
gr.File(value=os.path.join(output_dir, f"{name}.wav"))
|
| 213 |
+
for name in ['vocals', 'drums', 'bass', 'other']
|
| 214 |
+
]
|
| 215 |
+
for i, name in enumerate(['vocals', 'drums', 'bass', 'other']):
|
| 216 |
path = os.path.join(output_dir, f"{name}.wav")
|
| 217 |
save_track(path, sources[i].cpu(), model.samplerate)
|
|
|
|
| 218 |
return stem_paths
|
| 219 |
|
| 220 |
# === Process Audio Function β Fully Featured ===
|
|
|
|
| 264 |
session_log = generate_session_log(audio_file, selected_effects, isolate_vocals, export_format, genre)
|
| 265 |
status = "π Done!"
|
| 266 |
return output_path, waveform_image, session_log, genre, status, history
|
|
|
|
| 267 |
except Exception as e:
|
| 268 |
status = f"β Error: {str(e)}"
|
| 269 |
return None, None, status, "", status, []
|
|
|
|
| 455 |
semitones = key_to_semitone(target_key)
|
| 456 |
tuned_audio = apply_pitch_shift(audio, semitones)
|
| 457 |
out_path = save_audiosegment_to_temp(tuned_audio, ".wav")
|
| 458 |
+
return out_path
|
| 459 |
except Exception as e:
|
| 460 |
print(f"Auto-Tune Error: {e}")
|
| 461 |
return None
|
|
|
|
| 547 |
color: white !important;
|
| 548 |
border-radius: 10px;
|
| 549 |
padding: 10px 20px;
|
|
|
|
| 550 |
box-shadow: 0 0 10px #2563eb44;
|
| 551 |
border: none;
|
| 552 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 553 |
input[type="text"], select, textarea {
|
| 554 |
background-color: #334155 !important;
|
| 555 |
color: white !important;
|
|
|
|
| 839 |
gr.Interface(
|
| 840 |
fn=generate_ableton_template,
|
| 841 |
inputs=[gr.File(label="Upload Stems", file_count="multiple")],
|
| 842 |
+
outputs=gr.File(label="DAW Template (.json/.als/.flp)"),
|
| 843 |
+
title="Generate Ableton/Live/FLP Template",
|
| 844 |
+
description="Export ready-to-use templates for popular DAWs"
|
| 845 |
)
|
| 846 |
|
| 847 |
# --- Export Full Mix ZIP β Added Back ===
|