Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -281,8 +281,7 @@ def process_audio(audio_file, selected_effects, isolate_vocals, preset_name, exp
|
|
| 281 |
"Stage Mode": apply_stage_mode
|
| 282 |
}
|
| 283 |
|
| 284 |
-
|
| 285 |
-
for effect_name in effects_to_apply:
|
| 286 |
if effect_name in effect_map:
|
| 287 |
audio = effect_map[effect_name](audio)
|
| 288 |
|
|
@@ -316,14 +315,14 @@ def show_waveform(audio_file):
|
|
| 316 |
audio = AudioSegment.from_file(audio_file)
|
| 317 |
samples = np.array(audio.get_array_of_samples())
|
| 318 |
plt.figure(figsize=(10, 2))
|
| 319 |
-
plt.plot(samples[:10000], color="
|
| 320 |
plt.axis("off")
|
| 321 |
buf = BytesIO()
|
| 322 |
plt.savefig(buf, format="png", bbox_inches="tight", dpi=100)
|
| 323 |
plt.close()
|
| 324 |
buf.seek(0)
|
| 325 |
return Image.open(buf)
|
| 326 |
-
except Exception
|
| 327 |
return None
|
| 328 |
|
| 329 |
def detect_genre(audio_path):
|
|
@@ -361,17 +360,9 @@ preset_choices = {
|
|
| 361 |
"π« ASMR Vocal": ["Auto Gain", "Low-Pass Filter (3000Hz)", "Noise Gate"],
|
| 362 |
"πΌ Stage Mode": ["Reverb", "Bass Boost", "Limiter"],
|
| 363 |
"π΅ Auto-Tune Style": ["Pitch Shift (+1 semitone)", "Normalize", "Treble Boost"],
|
| 364 |
-
"π· Jazz Vocal": ["Bass Boost (-200-400Hz)", "Treble Boost (-3000Hz)", "Normalize"],
|
| 365 |
-
"πΉ Jazz Piano": ["Treble Boost (4000-6000Hz)", "Normalize", "Stereo Widening"],
|
| 366 |
-
"π» Classical Strings": ["Bass Boost (100-500Hz)", "Treble Boost (3000-6000Hz)", "Reverb"],
|
| 367 |
-
"β Chillhop": ["Noise Gate", "Treble Boost (-3000Hz)", "Reverb"],
|
| 368 |
-
"π Ambient": ["Reverb", "Noise Gate", "Treble Boost (6000-12000Hz)"],
|
| 369 |
"π€ R&B Vocal": ["Noise Reduction", "Bass Boost (100-300Hz)", "Treble Boost (2000-4000Hz)"],
|
| 370 |
"π Soul Vocal": ["Noise Reduction", "Bass Boost (80-200Hz)", "Treble Boost (1500-3500Hz)"],
|
| 371 |
-
"πΊ Funk Groove": ["Bass Boost (80-200Hz)", "Treble Boost (1000-3000Hz)"
|
| 372 |
-
"πΉ Jazz Piano Solo": ["Treble Boost (2000-5000Hz)", "Normalize", "Stage Mode"],
|
| 373 |
-
"πΈ Trap EDM": ["Bass Boost (60-120Hz)", "Treble Boost (2000-5000Hz)", "Limiter"],
|
| 374 |
-
"πΈ Indie Rock": ["Bass Boost (150-400Hz)", "Treble Boost (2000-5000Hz)", "Compress Dynamic Range"]
|
| 375 |
}
|
| 376 |
|
| 377 |
preset_names = list(preset_choices.keys())
|
|
@@ -412,6 +403,7 @@ def auto_tune_vocal(audio_path, target_key="C"):
|
|
| 412 |
def visualize_spectrum(audio_path):
|
| 413 |
y, sr = torchaudio.load(audio_path)
|
| 414 |
y_np = y.numpy().flatten()
|
|
|
|
| 415 |
stft = librosa.stft(y_np)
|
| 416 |
db = librosa.amplitude_to_db(abs(stft))
|
| 417 |
|
|
@@ -429,9 +421,9 @@ def visualize_spectrum(audio_path):
|
|
| 429 |
# === Main UI β With Studio Pulse Branding ===
|
| 430 |
with gr.Blocks(css="""
|
| 431 |
body {
|
| 432 |
-
font-family: 'Segoe UI',
|
| 433 |
-
background-color:
|
| 434 |
-
color:
|
| 435 |
padding: 20px;
|
| 436 |
}
|
| 437 |
|
|
@@ -443,91 +435,91 @@ with gr.Blocks(css="""
|
|
| 443 |
|
| 444 |
.studio-header h3 {
|
| 445 |
font-size: 18px;
|
| 446 |
-
color:
|
| 447 |
margin-top: -5px;
|
| 448 |
font-style: italic;
|
| 449 |
}
|
| 450 |
|
| 451 |
-
.gr-interface {
|
| 452 |
-
background-color:
|
| 453 |
-
border-radius:
|
| 454 |
-
padding:
|
| 455 |
-
box-shadow: 0 0 10px
|
| 456 |
-
border: 1px solid
|
| 457 |
}
|
| 458 |
|
| 459 |
-
.
|
| 460 |
-
background-color:
|
| 461 |
-
color:
|
| 462 |
-
border-radius:
|
| 463 |
-
padding:
|
| 464 |
font-weight: bold;
|
| 465 |
-
|
|
|
|
|
|
|
| 466 |
}
|
| 467 |
|
| 468 |
-
.
|
| 469 |
-
background-color:
|
| 470 |
-
box-shadow: 0 0
|
| 471 |
}
|
| 472 |
|
| 473 |
.gr-tabs button {
|
| 474 |
font-size: 16px;
|
| 475 |
padding: 10px 20px;
|
| 476 |
border-radius: 8px;
|
| 477 |
-
background:
|
| 478 |
color: white;
|
| 479 |
transition: all 0.3s ease;
|
| 480 |
}
|
| 481 |
|
| 482 |
.gr-tabs button:hover {
|
| 483 |
-
background:
|
| 484 |
color: black;
|
| 485 |
-
box-shadow: 0 0 10px
|
| 486 |
}
|
| 487 |
|
| 488 |
input[type="text"], input[type="number"], select, textarea {
|
| 489 |
-
background-color:
|
| 490 |
color: white;
|
| 491 |
-
border: 1px solid
|
| 492 |
-
border-radius:
|
| 493 |
width: 100%;
|
| 494 |
-
padding: 0.75rem;
|
| 495 |
}
|
| 496 |
|
| 497 |
.gr-checkboxgroup label {
|
| 498 |
-
background:
|
| 499 |
color: white;
|
| 500 |
-
border: 1px solid
|
| 501 |
-
border-radius:
|
| 502 |
-
padding:
|
| 503 |
transition: background 0.3s;
|
| 504 |
}
|
| 505 |
|
| 506 |
.gr-checkboxgroup label:hover {
|
| 507 |
-
background:
|
| 508 |
cursor: pointer;
|
| 509 |
}
|
| 510 |
|
| 511 |
.gr-gallery__items > div {
|
| 512 |
-
border-radius:
|
| 513 |
overflow: hidden;
|
| 514 |
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
| 515 |
}
|
| 516 |
|
| 517 |
.gr-gallery__items > div:hover {
|
| 518 |
transform: scale(1.02);
|
| 519 |
-
box-shadow: 0 0 12px
|
| 520 |
}
|
| 521 |
|
| 522 |
.gr-gallery__item-label {
|
| 523 |
-
background: rgba(0, 0, 0, 0.
|
| 524 |
backdrop-filter: blur(3px);
|
| 525 |
-
|
|
|
|
| 526 |
font-size: 14px;
|
| 527 |
font-weight: bold;
|
| 528 |
text-align: center;
|
| 529 |
-
padding: 0.5rem;
|
| 530 |
-
border-radius: 0 0 0.5rem 0.5rem;
|
| 531 |
}
|
| 532 |
|
| 533 |
@keyframes float {
|
|
@@ -535,20 +527,30 @@ with gr.Blocks(css="""
|
|
| 535 |
50% { transform: translateY(-10px); }
|
| 536 |
}
|
| 537 |
|
| 538 |
-
|
| 539 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 540 |
}
|
| 541 |
""") as demo:
|
| 542 |
|
| 543 |
# Header
|
| 544 |
gr.HTML('''
|
| 545 |
-
<div class="studio-header
|
| 546 |
-
<img src="https://
|
| 547 |
-
<h3
|
| 548 |
</div>
|
| 549 |
''')
|
| 550 |
|
| 551 |
-
gr.Markdown("### Upload, edit, export β powered by AI!")
|
| 552 |
|
| 553 |
# --- Single File Studio Tab ---
|
| 554 |
with gr.Tab("π΅ Single File Studio"):
|
|
@@ -559,7 +561,7 @@ with gr.Blocks(css="""
|
|
| 559 |
preset_dropdown = gr.Dropdown(choices=preset_names, label="Select Preset", value=preset_names[0])
|
| 560 |
export_format = gr.Dropdown(choices=["MP3", "WAV"], label="Export Format", value="MP3")
|
| 561 |
isolate_vocals = gr.Checkbox(label="Isolate Vocals After Effects")
|
| 562 |
-
submit_btn = gr.Button("Process Audio"
|
| 563 |
with gr.Column(min_width=300):
|
| 564 |
output_audio = gr.Audio(label="Processed Audio", type="filepath")
|
| 565 |
waveform_img = gr.Image(label="Waveform Preview")
|
|
@@ -715,9 +717,7 @@ with gr.Blocks(css="""
|
|
| 715 |
gr.Dropdown(choices=preset_names, label="Used Preset", value=preset_names[0]),
|
| 716 |
gr.CheckboxGroup(choices=preset_choices["Default"], label="Applied Effects")
|
| 717 |
],
|
| 718 |
-
outputs=gr.File(label="Project File (.aiproj)")
|
| 719 |
-
title="Save Everything Together",
|
| 720 |
-
description="Save your session, effects, and settings in one file to reuse later."
|
| 721 |
)
|
| 722 |
|
| 723 |
gr.Interface(
|
|
@@ -735,16 +735,13 @@ with gr.Blocks(css="""
|
|
| 735 |
with gr.Tab("π Preset Gallery"):
|
| 736 |
gr.Markdown("### Select a preset visually")
|
| 737 |
preset_gallery = gr.Gallery(value=[
|
| 738 |
-
("https://
|
| 739 |
-
("https://
|
| 740 |
-
("https://
|
| 741 |
-
("https://
|
| 742 |
-
("https://
|
| 743 |
-
("https://
|
| 744 |
-
("https://
|
| 745 |
-
("https://via.placeholder.com/150x100/1e1e1e/1db954?text=Jazz", "Jazz"),
|
| 746 |
-
("https://via.placeholder.com/150x100/1e1e1e/1db954?text=Stage+Mode", "Stage Mode"),
|
| 747 |
-
("https://via.placeholder.com/150x100/1e1e1e/1db954?text=Tube+Saturation", "Tube Saturation")
|
| 748 |
], label="Preset Cards", columns=4, height="auto")
|
| 749 |
|
| 750 |
preset_name_out = gr.Dropdown(choices=preset_names, label="Selected Preset")
|
|
@@ -757,7 +754,7 @@ with gr.Blocks(css="""
|
|
| 757 |
|
| 758 |
preset_gallery.select(fn=load_preset_by_card, inputs=[], outputs=[preset_name_out, preset_effects_out])
|
| 759 |
|
| 760 |
-
# --- Prompt-Based Editing Tab β Added Back ===
|
| 761 |
def process_prompt(audio, prompt):
|
| 762 |
return apply_noise_reduction(audio)
|
| 763 |
|
|
|
|
| 281 |
"Stage Mode": apply_stage_mode
|
| 282 |
}
|
| 283 |
|
| 284 |
+
for effect_name in selected_effects:
|
|
|
|
| 285 |
if effect_name in effect_map:
|
| 286 |
audio = effect_map[effect_name](audio)
|
| 287 |
|
|
|
|
| 315 |
audio = AudioSegment.from_file(audio_file)
|
| 316 |
samples = np.array(audio.get_array_of_samples())
|
| 317 |
plt.figure(figsize=(10, 2))
|
| 318 |
+
plt.plot(samples[:10000], color="skyblue")
|
| 319 |
plt.axis("off")
|
| 320 |
buf = BytesIO()
|
| 321 |
plt.savefig(buf, format="png", bbox_inches="tight", dpi=100)
|
| 322 |
plt.close()
|
| 323 |
buf.seek(0)
|
| 324 |
return Image.open(buf)
|
| 325 |
+
except Exception:
|
| 326 |
return None
|
| 327 |
|
| 328 |
def detect_genre(audio_path):
|
|
|
|
| 360 |
"π« ASMR Vocal": ["Auto Gain", "Low-Pass Filter (3000Hz)", "Noise Gate"],
|
| 361 |
"πΌ Stage Mode": ["Reverb", "Bass Boost", "Limiter"],
|
| 362 |
"π΅ Auto-Tune Style": ["Pitch Shift (+1 semitone)", "Normalize", "Treble Boost"],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
"π€ R&B Vocal": ["Noise Reduction", "Bass Boost (100-300Hz)", "Treble Boost (2000-4000Hz)"],
|
| 364 |
"π Soul Vocal": ["Noise Reduction", "Bass Boost (80-200Hz)", "Treble Boost (1500-3500Hz)"],
|
| 365 |
+
"πΊ Funk Groove": ["Bass Boost (80-200Hz)", "Treble Boost (1000-3000Hz)"]
|
|
|
|
|
|
|
|
|
|
| 366 |
}
|
| 367 |
|
| 368 |
preset_names = list(preset_choices.keys())
|
|
|
|
| 403 |
def visualize_spectrum(audio_path):
|
| 404 |
y, sr = torchaudio.load(audio_path)
|
| 405 |
y_np = y.numpy().flatten()
|
| 406 |
+
|
| 407 |
stft = librosa.stft(y_np)
|
| 408 |
db = librosa.amplitude_to_db(abs(stft))
|
| 409 |
|
|
|
|
| 421 |
# === Main UI β With Studio Pulse Branding ===
|
| 422 |
with gr.Blocks(css="""
|
| 423 |
body {
|
| 424 |
+
font-family: 'Segoe UI', sans-serif;
|
| 425 |
+
background-color: #0d1117;
|
| 426 |
+
color: white;
|
| 427 |
padding: 20px;
|
| 428 |
}
|
| 429 |
|
|
|
|
| 435 |
|
| 436 |
.studio-header h3 {
|
| 437 |
font-size: 18px;
|
| 438 |
+
color: #8892aa;
|
| 439 |
margin-top: -5px;
|
| 440 |
font-style: italic;
|
| 441 |
}
|
| 442 |
|
| 443 |
+
.gr-box, .gr-interface {
|
| 444 |
+
background-color: #161b22 !important;
|
| 445 |
+
border-radius: 12px;
|
| 446 |
+
padding: 15px;
|
| 447 |
+
box-shadow: 0 0 10px #1f7bbd44;
|
| 448 |
+
border: 1px solid #2a3036;
|
| 449 |
}
|
| 450 |
|
| 451 |
+
.gr-button {
|
| 452 |
+
background-color: #1f7bbd !important;
|
| 453 |
+
color: white !important;
|
| 454 |
+
border-radius: 10px;
|
| 455 |
+
padding: 10px 20px;
|
| 456 |
font-weight: bold;
|
| 457 |
+
box-shadow: 0 0 10px #1f7bbd44;
|
| 458 |
+
border: none;
|
| 459 |
+
font-size: 16px;
|
| 460 |
}
|
| 461 |
|
| 462 |
+
.gr-button:hover {
|
| 463 |
+
background-color: #298eff !important;
|
| 464 |
+
box-shadow: 0 0 15px #298effaa;
|
| 465 |
}
|
| 466 |
|
| 467 |
.gr-tabs button {
|
| 468 |
font-size: 16px;
|
| 469 |
padding: 10px 20px;
|
| 470 |
border-radius: 8px;
|
| 471 |
+
background: #161b22;
|
| 472 |
color: white;
|
| 473 |
transition: all 0.3s ease;
|
| 474 |
}
|
| 475 |
|
| 476 |
.gr-tabs button:hover {
|
| 477 |
+
background: #298eff;
|
| 478 |
color: black;
|
| 479 |
+
box-shadow: 0 0 10px #298effaa;
|
| 480 |
}
|
| 481 |
|
| 482 |
input[type="text"], input[type="number"], select, textarea {
|
| 483 |
+
background-color: #21262d;
|
| 484 |
color: white;
|
| 485 |
+
border: 1px solid #30363f;
|
| 486 |
+
border-radius: 8px;
|
| 487 |
width: 100%;
|
|
|
|
| 488 |
}
|
| 489 |
|
| 490 |
.gr-checkboxgroup label {
|
| 491 |
+
background: #21262d;
|
| 492 |
color: white;
|
| 493 |
+
border: 1px solid #30363f;
|
| 494 |
+
border-radius: 8px;
|
| 495 |
+
padding: 8px;
|
| 496 |
transition: background 0.3s;
|
| 497 |
}
|
| 498 |
|
| 499 |
.gr-checkboxgroup label:hover {
|
| 500 |
+
background: #2a3036;
|
| 501 |
cursor: pointer;
|
| 502 |
}
|
| 503 |
|
| 504 |
.gr-gallery__items > div {
|
| 505 |
+
border-radius: 12px;
|
| 506 |
overflow: hidden;
|
| 507 |
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
| 508 |
}
|
| 509 |
|
| 510 |
.gr-gallery__items > div:hover {
|
| 511 |
transform: scale(1.02);
|
| 512 |
+
box-shadow: 0 0 12px #298eff44;
|
| 513 |
}
|
| 514 |
|
| 515 |
.gr-gallery__item-label {
|
| 516 |
+
background: rgba(0, 0, 0, 0.6);
|
| 517 |
backdrop-filter: blur(3px);
|
| 518 |
+
border-radius: 0 0 12px 12px;
|
| 519 |
+
padding: 10px;
|
| 520 |
font-size: 14px;
|
| 521 |
font-weight: bold;
|
| 522 |
text-align: center;
|
|
|
|
|
|
|
| 523 |
}
|
| 524 |
|
| 525 |
@keyframes float {
|
|
|
|
| 527 |
50% { transform: translateY(-10px); }
|
| 528 |
}
|
| 529 |
|
| 530 |
+
@media (max-width: 768px) {
|
| 531 |
+
.gr-column {
|
| 532 |
+
min-width: 100%;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
.gr-row {
|
| 536 |
+
flex-direction: column;
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
.gr-button {
|
| 540 |
+
width: 100%;
|
| 541 |
+
}
|
| 542 |
}
|
| 543 |
""") as demo:
|
| 544 |
|
| 545 |
# Header
|
| 546 |
gr.HTML('''
|
| 547 |
+
<div class="studio-header">
|
| 548 |
+
<img src="https://picsum.photos/id/1063/400/100" width="400" />
|
| 549 |
+
<h3>Where Your Audio Meets Intelligence</h3>
|
| 550 |
</div>
|
| 551 |
''')
|
| 552 |
|
| 553 |
+
gr.Markdown("### Upload, edit, export β powered by AI!")
|
| 554 |
|
| 555 |
# --- Single File Studio Tab ---
|
| 556 |
with gr.Tab("π΅ Single File Studio"):
|
|
|
|
| 561 |
preset_dropdown = gr.Dropdown(choices=preset_names, label="Select Preset", value=preset_names[0])
|
| 562 |
export_format = gr.Dropdown(choices=["MP3", "WAV"], label="Export Format", value="MP3")
|
| 563 |
isolate_vocals = gr.Checkbox(label="Isolate Vocals After Effects")
|
| 564 |
+
submit_btn = gr.Button("Process Audio")
|
| 565 |
with gr.Column(min_width=300):
|
| 566 |
output_audio = gr.Audio(label="Processed Audio", type="filepath")
|
| 567 |
waveform_img = gr.Image(label="Waveform Preview")
|
|
|
|
| 717 |
gr.Dropdown(choices=preset_names, label="Used Preset", value=preset_names[0]),
|
| 718 |
gr.CheckboxGroup(choices=preset_choices["Default"], label="Applied Effects")
|
| 719 |
],
|
| 720 |
+
outputs=gr.File(label="Project File (.aiproj)")
|
|
|
|
|
|
|
| 721 |
)
|
| 722 |
|
| 723 |
gr.Interface(
|
|
|
|
| 735 |
with gr.Tab("π Preset Gallery"):
|
| 736 |
gr.Markdown("### Select a preset visually")
|
| 737 |
preset_gallery = gr.Gallery(value=[
|
| 738 |
+
("https://picsum.photos/id/10/150/100", "Pop"),
|
| 739 |
+
("https://picsum.photos/id/20/150/100", "EDM"),
|
| 740 |
+
("https://picsum.photos/id/30/150/100", "Rock"),
|
| 741 |
+
("https://picsum.photos/id/40/150/100", "Hip-Hop"),
|
| 742 |
+
("https://picsum.photos/id/50/150/100", "R&B"),
|
| 743 |
+
("https://picsum.photos/id/60/150/100", "Soul"),
|
| 744 |
+
("https://picsum.photos/id/70/150/100", "Funk")
|
|
|
|
|
|
|
|
|
|
| 745 |
], label="Preset Cards", columns=4, height="auto")
|
| 746 |
|
| 747 |
preset_name_out = gr.Dropdown(choices=preset_names, label="Selected Preset")
|
|
|
|
| 754 |
|
| 755 |
preset_gallery.select(fn=load_preset_by_card, inputs=[], outputs=[preset_name_out, preset_effects_out])
|
| 756 |
|
| 757 |
+
# --- Prompt-Based Editing Tab β Added Back ===
|
| 758 |
def process_prompt(audio, prompt):
|
| 759 |
return apply_noise_reduction(audio)
|
| 760 |
|