Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -249,45 +249,48 @@ with gr.Blocks(theme=gr.themes.Default(primary_hue="blue", secondary_hue="red"))
|
|
| 249 |
gr.Markdown("### Sliced Loops / Samples (Preview)")
|
| 250 |
loop_gallery = gr.Gallery(label="Generated Loops Preview", columns=8, object_fit="contain", height="auto", preview=True)
|
| 251 |
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
def update_single_progress(p, desc=""):
|
| 259 |
-
progress_bar.update(value=p, label=desc, visible=True) # Cannot yield from nested func
|
| 260 |
-
|
| 261 |
-
files, temp_dir = slice_stem_real(stem_data, loop_choice, sensitivity, stem_name, progress_fn=update_single_progress)
|
| 262 |
-
|
| 263 |
-
if temp_dir and os.path.exists(temp_dir):
|
| 264 |
-
shutil.rmtree(temp_dir) # Clean up temp dir after preview
|
| 265 |
-
|
| 266 |
-
yield {
|
| 267 |
-
loop_gallery: gr.update(value=files),
|
| 268 |
-
status_log: log_history + f"✅ Sliced {stem_name} into {len(files) if files else 0} pieces.",
|
| 269 |
-
progress_bar: gr.update(visible=False)
|
| 270 |
-
}
|
| 271 |
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
-
|
| 274 |
-
fn=separate_stems,
|
| 275 |
-
inputs=[audio_input, stem_options],
|
| 276 |
-
outputs=[vocals_output, drums_output, bass_output, other_output, status_log, progress_bar]
|
| 277 |
-
)
|
| 278 |
|
| 279 |
-
|
|
|
|
| 280 |
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 291 |
|
| 292 |
# --- Launch the UI ---
|
| 293 |
demo.launch()
|
|
|
|
| 249 |
gr.Markdown("### Sliced Loops / Samples (Preview)")
|
| 250 |
loop_gallery = gr.Gallery(label="Generated Loops Preview", columns=8, object_fit="contain", height="auto", preview=True)
|
| 251 |
|
| 252 |
+
# --- Define Event Listeners ---
|
| 253 |
+
def slice_and_display(stem_data, loop_choice, sensitivity):
|
| 254 |
+
# This wrapper remains the same
|
| 255 |
+
log_history = f"Slicing...\n"
|
| 256 |
+
yield { status_log: log_history, progress_bar: gr.update(visible=True) } # Show progress bar
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
|
| 258 |
+
# Define how slice_stem_real updates the progress bar
|
| 259 |
+
def update_single_progress(p, desc=""):
|
| 260 |
+
progress_bar.update(value=p, label=desc, visible=True)
|
| 261 |
|
| 262 |
+
files, temp_dir = slice_stem_real(stem_data, loop_choice, sensitivity, "stem", progress_fn=update_single_progress) # Pass stem_name placeholder
|
|
|
|
|
|
|
|
|
|
|
|
|
| 263 |
|
| 264 |
+
if temp_dir and os.path.exists(temp_dir):
|
| 265 |
+
shutil.rmtree(temp_dir)
|
| 266 |
|
| 267 |
+
yield {
|
| 268 |
+
loop_gallery: gr.update(value=files),
|
| 269 |
+
status_log: log_history + f"✅ Sliced into {len(files) if files else 0} pieces.",
|
| 270 |
+
progress_bar: gr.update(visible=False) # Hide progress bar when done
|
| 271 |
+
}
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
submit_event = submit_button.click(
|
| 275 |
+
fn=separate_stems,
|
| 276 |
+
inputs=[audio_input, stem_options],
|
| 277 |
+
# Corrected outputs: progress_bar removed
|
| 278 |
+
outputs=[vocals_output, drums_output, bass_output, other_output, status_log]
|
| 279 |
+
)
|
| 280 |
+
|
| 281 |
+
stem_options.change(fn=update_output_visibility, inputs=stem_options, outputs=[vocals_output, drums_output, bass_output, other_output])
|
| 282 |
+
|
| 283 |
+
slice_vocals_btn.click(fn=slice_and_display, inputs=[vocals_output, loop_options_radio, sensitivity_slider, gr.Textbox("vocals", visible=False)], outputs=[loop_gallery, status_log, progress_bar])
|
| 284 |
+
slice_drums_btn.click(fn=slice_and_display, inputs=[drums_output, loop_options_radio, sensitivity_slider, gr.Textbox("drums", visible=False)], outputs=[loop_gallery, status_log, progress_bar])
|
| 285 |
+
slice_bass_btn.click(fn=slice_and_display, inputs=[bass_output, loop_options_radio, sensitivity_slider, gr.Textbox("bass", visible=False)], outputs=[loop_gallery, status_log, progress_bar])
|
| 286 |
+
slice_other_btn.click(fn=slice_and_display, inputs=[other_output, loop_options_radio, sensitivity_slider, gr.Textbox("other", visible=False)], outputs=[loop_gallery, status_log, progress_bar])
|
| 287 |
+
|
| 288 |
+
slice_all_event = slice_all_button.click(
|
| 289 |
+
fn=slice_all_and_zip_real,
|
| 290 |
+
inputs=[vocals_output, drums_output, bass_output, other_output, loop_options_radio, sensitivity_slider],
|
| 291 |
+
# Corrected outputs: progress_bar removed
|
| 292 |
+
outputs=[download_zip_file, download_zip_file, status_log]
|
| 293 |
+
)
|
| 294 |
|
| 295 |
# --- Launch the UI ---
|
| 296 |
demo.launch()
|