Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
import librosa
|
|
|
|
| 5 |
import soundfile as sf
|
| 6 |
import os
|
| 7 |
import tempfile
|
|
@@ -11,7 +12,7 @@ import matplotlib
|
|
| 11 |
import matplotlib.pyplot as plt
|
| 12 |
from scipy import signal
|
| 13 |
from typing import Tuple, List, Any
|
| 14 |
-
import shutil
|
| 15 |
|
| 16 |
# Use a non-interactive backend for Matplotlib
|
| 17 |
matplotlib.use('Agg')
|
|
@@ -326,8 +327,7 @@ def slice_stem_real(
|
|
| 326 |
y = librosa.util.buf_to_float(y_int, dtype=np.float32)
|
| 327 |
else:
|
| 328 |
# Handle case where it's a filepath (from separate_stems)
|
| 329 |
-
|
| 330 |
-
|
| 331 |
|
| 332 |
if y.ndim == 0:
|
| 333 |
return [], ""
|
|
@@ -496,12 +496,6 @@ def slice_all_and_zip(
|
|
| 496 |
|
| 497 |
with zipfile.ZipFile(zip_path, 'w') as zf:
|
| 498 |
for name, data in valid_stems.items():
|
| 499 |
-
# Create temporary file for this stem
|
| 500 |
-
# No need to save to a temp file here, can pass the tuple directly
|
| 501 |
-
# stem_temp_dir = tempfile.mkdtemp()
|
| 502 |
-
# stem_path = os.path.join(stem_temp_dir, f"{name}.wav")
|
| 503 |
-
# sf.write(stem_path, data[1], data[0])
|
| 504 |
-
|
| 505 |
# Process stem
|
| 506 |
sliced_files, _ = slice_stem_real(
|
| 507 |
data, loop_choice, sensitivity, name,
|
|
@@ -515,11 +509,6 @@ def slice_all_and_zip(
|
|
| 515 |
arcname = os.path.join(file_type, os.path.basename(file_path))
|
| 516 |
zf.write(file_path, arcname)
|
| 517 |
|
| 518 |
-
# Clean up stem temp files
|
| 519 |
-
# shutil.rmtree(stem_temp_dir) # No temp dir created here anymore
|
| 520 |
-
|
| 521 |
-
# Note: The main temp_dir containing the zip file will be cleaned up by Gradio
|
| 522 |
-
|
| 523 |
return zip_path
|
| 524 |
|
| 525 |
except Exception as e:
|
|
@@ -664,24 +653,24 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="red"))
|
|
| 664 |
gr.Markdown("### Separated Stems")
|
| 665 |
with gr.Row():
|
| 666 |
with gr.Column():
|
| 667 |
-
|
| 668 |
slice_vocals_btn = gr.Button("Slice Vocals")
|
| 669 |
with gr.Column():
|
| 670 |
-
|
| 671 |
slice_drums_btn = gr.Button("Slice Drums")
|
| 672 |
with gr.Row():
|
| 673 |
with gr.Column():
|
| 674 |
-
|
| 675 |
slice_bass_btn = gr.Button("Slice Bass")
|
| 676 |
with gr.Column():
|
| 677 |
-
|
| 678 |
slice_other_btn = gr.Button("Slice Other")
|
| 679 |
with gr.Row():
|
| 680 |
with gr.Column():
|
| 681 |
-
|
| 682 |
slice_guitar_btn = gr.Button("Slice Guitar")
|
| 683 |
with gr.Column():
|
| 684 |
-
|
| 685 |
slice_piano_btn = gr.Button("Slice Piano")
|
| 686 |
|
| 687 |
# Gallery for previews
|
|
@@ -692,6 +681,9 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="red"))
|
|
| 692 |
object_fit="contain",
|
| 693 |
height="auto"
|
| 694 |
)
|
|
|
|
|
|
|
|
|
|
| 695 |
|
| 696 |
# --- EVENT HANDLERS ---
|
| 697 |
|
|
@@ -748,7 +740,7 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="red"))
|
|
| 748 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 749 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 750 |
],
|
| 751 |
-
outputs=[loop_gallery,
|
| 752 |
)
|
| 753 |
|
| 754 |
slice_drums_btn.click(
|
|
@@ -759,7 +751,7 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="red"))
|
|
| 759 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 760 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 761 |
],
|
| 762 |
-
outputs=[loop_gallery,
|
| 763 |
)
|
| 764 |
|
| 765 |
slice_bass_btn.click(
|
|
@@ -770,7 +762,7 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="red"))
|
|
| 770 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 771 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 772 |
],
|
| 773 |
-
outputs=[loop_gallery,
|
| 774 |
)
|
| 775 |
|
| 776 |
slice_other_btn.click(
|
|
@@ -781,7 +773,7 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="red"))
|
|
| 781 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 782 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 783 |
],
|
| 784 |
-
outputs=[loop_gallery,
|
| 785 |
)
|
| 786 |
|
| 787 |
slice_guitar_btn.click(
|
|
@@ -792,7 +784,7 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="red"))
|
|
| 792 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 793 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 794 |
],
|
| 795 |
-
outputs=[loop_gallery,
|
| 796 |
)
|
| 797 |
|
| 798 |
slice_piano_btn.click(
|
|
@@ -803,10 +795,9 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="red"))
|
|
| 803 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 804 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 805 |
],
|
| 806 |
-
outputs=[loop_gallery,
|
| 807 |
)
|
| 808 |
|
| 809 |
-
|
| 810 |
# Slice all stems and create ZIP
|
| 811 |
slice_all_btn.click(
|
| 812 |
fn=slice_all_and_zip,
|
|
@@ -827,4 +818,4 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="red"))
|
|
| 827 |
|
| 828 |
# Launch the app
|
| 829 |
if __name__ == "__main__":
|
| 830 |
-
demo.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import numpy as np
|
| 4 |
import librosa
|
| 5 |
+
import librosa.display # Added missing import
|
| 6 |
import soundfile as sf
|
| 7 |
import os
|
| 8 |
import tempfile
|
|
|
|
| 12 |
import matplotlib.pyplot as plt
|
| 13 |
from scipy import signal
|
| 14 |
from typing import Tuple, List, Any
|
| 15 |
+
import shutil
|
| 16 |
|
| 17 |
# Use a non-interactive backend for Matplotlib
|
| 18 |
matplotlib.use('Agg')
|
|
|
|
| 327 |
y = librosa.util.buf_to_float(y_int, dtype=np.float32)
|
| 328 |
else:
|
| 329 |
# Handle case where it's a filepath (from separate_stems)
|
| 330 |
+
y, sample_rate = librosa.load(stem_audio_path, sr=None) # Fixed indentation
|
|
|
|
| 331 |
|
| 332 |
if y.ndim == 0:
|
| 333 |
return [], ""
|
|
|
|
| 496 |
|
| 497 |
with zipfile.ZipFile(zip_path, 'w') as zf:
|
| 498 |
for name, data in valid_stems.items():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 499 |
# Process stem
|
| 500 |
sliced_files, _ = slice_stem_real(
|
| 501 |
data, loop_choice, sensitivity, name,
|
|
|
|
| 509 |
arcname = os.path.join(file_type, os.path.basename(file_path))
|
| 510 |
zf.write(file_path, arcname)
|
| 511 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
return zip_path
|
| 513 |
|
| 514 |
except Exception as e:
|
|
|
|
| 653 |
gr.Markdown("### Separated Stems")
|
| 654 |
with gr.Row():
|
| 655 |
with gr.Column():
|
| 656 |
+
vocals_output # Place component in layout
|
| 657 |
slice_vocals_btn = gr.Button("Slice Vocals")
|
| 658 |
with gr.Column():
|
| 659 |
+
drums_output # Place component in layout
|
| 660 |
slice_drums_btn = gr.Button("Slice Drums")
|
| 661 |
with gr.Row():
|
| 662 |
with gr.Column():
|
| 663 |
+
bass_output # Place component in layout
|
| 664 |
slice_bass_btn = gr.Button("Slice Bass")
|
| 665 |
with gr.Column():
|
| 666 |
+
other_output # Place component in layout
|
| 667 |
slice_other_btn = gr.Button("Slice Other")
|
| 668 |
with gr.Row():
|
| 669 |
with gr.Column():
|
| 670 |
+
guitar_output # Place component in layout
|
| 671 |
slice_guitar_btn = gr.Button("Slice Guitar")
|
| 672 |
with gr.Column():
|
| 673 |
+
piano_output # Place component in layout
|
| 674 |
slice_piano_btn = gr.Button("Slice Piano")
|
| 675 |
|
| 676 |
# Gallery for previews
|
|
|
|
| 681 |
object_fit="contain",
|
| 682 |
height="auto"
|
| 683 |
)
|
| 684 |
+
|
| 685 |
+
# Status textboxes for individual slicing
|
| 686 |
+
status_textbox = gr.Textbox(label="Status", visible=True)
|
| 687 |
|
| 688 |
# --- EVENT HANDLERS ---
|
| 689 |
|
|
|
|
| 740 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 741 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 742 |
],
|
| 743 |
+
outputs=[loop_gallery, status_textbox]
|
| 744 |
)
|
| 745 |
|
| 746 |
slice_drums_btn.click(
|
|
|
|
| 751 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 752 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 753 |
],
|
| 754 |
+
outputs=[loop_gallery, status_textbox]
|
| 755 |
)
|
| 756 |
|
| 757 |
slice_bass_btn.click(
|
|
|
|
| 762 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 763 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 764 |
],
|
| 765 |
+
outputs=[loop_gallery, status_textbox]
|
| 766 |
)
|
| 767 |
|
| 768 |
slice_other_btn.click(
|
|
|
|
| 773 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 774 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 775 |
],
|
| 776 |
+
outputs=[loop_gallery, status_textbox]
|
| 777 |
)
|
| 778 |
|
| 779 |
slice_guitar_btn.click(
|
|
|
|
| 784 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 785 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 786 |
],
|
| 787 |
+
outputs=[loop_gallery, status_textbox]
|
| 788 |
)
|
| 789 |
|
| 790 |
slice_piano_btn.click(
|
|
|
|
| 795 |
pan_depth_slider, level_depth_slider, modulation_rate_radio, lufs_target_slider,
|
| 796 |
attack_gain_slider, sustain_gain_slider, filter_type_radio, filter_freq_slider, filter_depth_slider
|
| 797 |
],
|
| 798 |
+
outputs=[loop_gallery, status_textbox]
|
| 799 |
)
|
| 800 |
|
|
|
|
| 801 |
# Slice all stems and create ZIP
|
| 802 |
slice_all_btn.click(
|
| 803 |
fn=slice_all_and_zip,
|
|
|
|
| 818 |
|
| 819 |
# Launch the app
|
| 820 |
if __name__ == "__main__":
|
| 821 |
+
demo.launch()
|