Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -322,9 +322,10 @@ button:hover {
|
|
| 322 |
}
|
| 323 |
"""
|
| 324 |
|
| 325 |
-
import
|
|
|
|
| 326 |
|
| 327 |
-
def download_audio(url,
|
| 328 |
ydl_opts = {
|
| 329 |
'format': 'bestaudio/best',
|
| 330 |
'postprocessors': [{
|
|
@@ -348,14 +349,19 @@ def download_audio(url, download_type, cookie_file):
|
|
| 348 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 349 |
try:
|
| 350 |
info_dict = ydl.extract_info(url, download=True)
|
| 351 |
-
file_path = ydl.prepare_filename(info_dict)
|
| 352 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 353 |
except yt_dlp.utils.ExtractorError as e:
|
| 354 |
if "Sign in to confirm you’re not a bot" in str(e):
|
| 355 |
-
return None, "Authentication failed. Please upload updated cookies from a logged-in browser session
|
| 356 |
-
return None, f"Download failed: {str(e)}", None
|
| 357 |
except Exception as e:
|
| 358 |
-
return None, f"Unexpected error: {str(e)}", None
|
| 359 |
|
| 360 |
@spaces.GPU
|
| 361 |
def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, pitch_shift, model_dir, output_dir, out_format, norm_thresh, amp_thresh, batch_size, exclude_stems="", progress=gr.Progress(track_tqdm=True)):
|
|
@@ -486,7 +492,6 @@ def update_ensemble_models(category):
|
|
| 486 |
return gr.update(choices=choices, value=[])
|
| 487 |
|
| 488 |
def create_interface():
|
| 489 |
-
"""Create the Gradio interface for music source separation."""
|
| 490 |
with gr.Blocks(title="🎵 SESA Fast Separation 🎵", css=CSS, elem_id="app-container") as app:
|
| 491 |
gr.Markdown("<h1 class='header-text'>🎵 SESA Fast Separation 🎵</h1>")
|
| 492 |
gr.Markdown("**Note**: If YouTube downloads fail, try uploading an audio file directly or use a valid cookies file.")
|
|
@@ -554,9 +559,13 @@ def create_interface():
|
|
| 554 |
|
| 555 |
# Event Handlers
|
| 556 |
roformer_category.change(update_roformer_models, inputs=[roformer_category], outputs=[roformer_model])
|
| 557 |
-
download_roformer.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 558 |
roformer_button.click(
|
| 559 |
-
roformer_separator,
|
| 560 |
inputs=[
|
| 561 |
roformer_audio, roformer_model, roformer_seg_size, roformer_override_seg_size,
|
| 562 |
roformer_overlap, roformer_pitch_shift, model_file_dir, output_dir,
|
|
@@ -565,7 +574,11 @@ def create_interface():
|
|
| 565 |
outputs=[roformer_stem1, roformer_stem2]
|
| 566 |
)
|
| 567 |
ensemble_category.change(update_ensemble_models, inputs=[ensemble_category], outputs=[ensemble_models])
|
| 568 |
-
download_ensemble.click(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 569 |
ensemble_button.click(
|
| 570 |
fn=auto_ensemble_process,
|
| 571 |
inputs=[
|
|
|
|
| 322 |
}
|
| 323 |
"""
|
| 324 |
|
| 325 |
+
import scipy.io.wavfile
|
| 326 |
+
import os
|
| 327 |
|
| 328 |
+
def download_audio(url, cookie_file):
|
| 329 |
ydl_opts = {
|
| 330 |
'format': 'bestaudio/best',
|
| 331 |
'postprocessors': [{
|
|
|
|
| 349 |
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 350 |
try:
|
| 351 |
info_dict = ydl.extract_info(url, download=True)
|
| 352 |
+
file_path = ydl.prepare_filename(info_dict).replace('.webm', '.wav') # Adjust extension after extraction
|
| 353 |
+
if not os.path.exists(file_path):
|
| 354 |
+
return None, "Downloaded file not found", None
|
| 355 |
+
# Read the audio file for gr.Audio
|
| 356 |
+
sample_rate, data = scipy.io.wavfile.read(file_path)
|
| 357 |
+
audio_data = (sample_rate, data)
|
| 358 |
+
return file_path, "Download successful", audio_data
|
| 359 |
except yt_dlp.utils.ExtractorError as e:
|
| 360 |
if "Sign in to confirm you’re not a bot" in str(e):
|
| 361 |
+
return None, "Authentication failed. Please upload updated cookies from a logged-in browser session in the respective tab.", None
|
| 362 |
+
return None, f"Download failed: {str(e)}", None
|
| 363 |
except Exception as e:
|
| 364 |
+
return None, f"Unexpected error: {str(e)}", None
|
| 365 |
|
| 366 |
@spaces.GPU
|
| 367 |
def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, pitch_shift, model_dir, output_dir, out_format, norm_thresh, amp_thresh, batch_size, exclude_stems="", progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 492 |
return gr.update(choices=choices, value=[])
|
| 493 |
|
| 494 |
def create_interface():
|
|
|
|
| 495 |
with gr.Blocks(title="🎵 SESA Fast Separation 🎵", css=CSS, elem_id="app-container") as app:
|
| 496 |
gr.Markdown("<h1 class='header-text'>🎵 SESA Fast Separation 🎵</h1>")
|
| 497 |
gr.Markdown("**Note**: If YouTube downloads fail, try uploading an audio file directly or use a valid cookies file.")
|
|
|
|
| 559 |
|
| 560 |
# Event Handlers
|
| 561 |
roformer_category.change(update_roformer_models, inputs=[roformer_category], outputs=[roformer_model])
|
| 562 |
+
download_roformer.click(
|
| 563 |
+
fn=download_audio,
|
| 564 |
+
inputs=[url_ro, cookies_ro],
|
| 565 |
+
outputs=[roformer_audio] # Now expects (sample_rate, data)
|
| 566 |
+
)
|
| 567 |
roformer_button.click(
|
| 568 |
+
fn=roformer_separator,
|
| 569 |
inputs=[
|
| 570 |
roformer_audio, roformer_model, roformer_seg_size, roformer_override_seg_size,
|
| 571 |
roformer_overlap, roformer_pitch_shift, model_file_dir, output_dir,
|
|
|
|
| 574 |
outputs=[roformer_stem1, roformer_stem2]
|
| 575 |
)
|
| 576 |
ensemble_category.change(update_ensemble_models, inputs=[ensemble_category], outputs=[ensemble_models])
|
| 577 |
+
download_ensemble.click(
|
| 578 |
+
fn=download_audio,
|
| 579 |
+
inputs=[url_ensemble, cookies_ensemble],
|
| 580 |
+
outputs=[ensemble_audio] # Now expects (sample_rate, data)
|
| 581 |
+
)
|
| 582 |
ensemble_button.click(
|
| 583 |
fn=auto_ensemble_process,
|
| 584 |
inputs=[
|