Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -15,6 +15,7 @@ import gradio_client.utils as client_utils
|
|
| 15 |
import validators
|
| 16 |
import matchering as mg
|
| 17 |
from typing import Any, Optional
|
|
|
|
| 18 |
|
| 19 |
# Logging setup
|
| 20 |
logging.basicConfig(level=logging.INFO)
|
|
@@ -63,8 +64,9 @@ client_utils._json_schema_to_python_type = patched_json_schema_to_python_type
|
|
| 63 |
# Device and autocast setup
|
| 64 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 65 |
use_autocast = device == "cuda"
|
|
|
|
| 66 |
|
| 67 |
-
# ROFORMER_MODELS and OUTPUT_FORMATS
|
| 68 |
ROFORMER_MODELS = {
|
| 69 |
"Vocals": {
|
| 70 |
'MelBand Roformer | Big Beta 6X by unwa': 'melband_roformer_big_beta6x.ckpt',
|
|
@@ -158,7 +160,7 @@ ROFORMER_MODELS = {
|
|
| 158 |
|
| 159 |
OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']
|
| 160 |
|
| 161 |
-
#
|
| 162 |
CSS = """
|
| 163 |
/* Modern ve Etkileşimli Tema */
|
| 164 |
#app-container {
|
|
@@ -173,7 +175,7 @@ CSS = """
|
|
| 173 |
min-height: 100vh;
|
| 174 |
background: linear-gradient(135deg, #1a0b2e, #2e1a47);
|
| 175 |
position: relative;
|
| 176 |
-
overflow: visible;
|
| 177 |
}
|
| 178 |
body {
|
| 179 |
background: none;
|
|
@@ -230,7 +232,7 @@ body::after {
|
|
| 230 |
width: 100%;
|
| 231 |
transition: transform 0.3s ease;
|
| 232 |
position: relative;
|
| 233 |
-
z-index: 10;
|
| 234 |
}
|
| 235 |
.dubbing-theme:hover {
|
| 236 |
transform: translateY(-5px);
|
|
@@ -320,7 +322,7 @@ button:hover {
|
|
| 320 |
font-size: 1rem !important;
|
| 321 |
transition: border-color 0.3s ease, box-shadow 0.3s ease !important;
|
| 322 |
position: relative;
|
| 323 |
-
z-index: 100;
|
| 324 |
}
|
| 325 |
.compact-dropdown:hover {
|
| 326 |
border-color: #ff8787 !important;
|
|
@@ -342,11 +344,11 @@ button:hover {
|
|
| 342 |
border: 2px solid #ff6b6b !important;
|
| 343 |
border-radius: 8px !important;
|
| 344 |
color: #e0e0e0 !important;
|
| 345 |
-
max-height: 300px !important;
|
| 346 |
overflow-y: auto !important;
|
| 347 |
-
z-index: 200 !important;
|
| 348 |
width: 100% !important;
|
| 349 |
-
opacity: 1 !important;
|
| 350 |
visibility: visible !important;
|
| 351 |
position: absolute !important;
|
| 352 |
top: 100% !important;
|
|
@@ -409,7 +411,7 @@ button:hover {
|
|
| 409 |
max-width: 100%;
|
| 410 |
}
|
| 411 |
.compact-dropdown .gr-dropdown-menu {
|
| 412 |
-
max-height: 200px !important;
|
| 413 |
}
|
| 414 |
}
|
| 415 |
"""
|
|
@@ -453,7 +455,7 @@ def download_audio(url, cookies_file=None, out_dir="ytdl"):
|
|
| 453 |
logger.error(f"Download failed: {e}")
|
| 454 |
raise RuntimeError(f"Download failed: {e}")
|
| 455 |
|
| 456 |
-
|
| 457 |
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)):
|
| 458 |
"""Separate audio into stems using a Roformer model."""
|
| 459 |
if not audio:
|
|
@@ -473,7 +475,7 @@ def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, p
|
|
| 473 |
else:
|
| 474 |
raise ValueError(f"Model '{model_key}' not found.")
|
| 475 |
|
| 476 |
-
logger.info(f"Separating {base_name} with {model_key}")
|
| 477 |
try:
|
| 478 |
separator = Separator(
|
| 479 |
log_level=logging.INFO,
|
|
@@ -500,6 +502,7 @@ def roformer_separator(audio, model_key, seg_size, override_seg_size, overlap, p
|
|
| 500 |
logger.error(f"Separation failed: {e}")
|
| 501 |
raise RuntimeError(f"Separation failed: {e}")
|
| 502 |
|
|
|
|
| 503 |
def auto_ensemble_process(audio, model_keys, seg_size, overlap, out_format, use_tta, model_dir, output_dir, norm_thresh, amp_thresh, batch_size, ensemble_method, exclude_stems="", weights_str="", progress=gr.Progress()):
|
| 504 |
"""Perform ensemble processing on audio using multiple Roformer models."""
|
| 505 |
if not audio or not model_keys:
|
|
@@ -512,7 +515,7 @@ def auto_ensemble_process(audio, model_keys, seg_size, overlap, out_format, use_
|
|
| 512 |
os.makedirs(output_dir, exist_ok=True)
|
| 513 |
|
| 514 |
base_name = os.path.splitext(os.path.basename(audio))[0]
|
| 515 |
-
logger.info(f"Ensemble for {base_name} with {model_keys}")
|
| 516 |
|
| 517 |
all_stems = []
|
| 518 |
total_models = len(model_keys)
|
|
|
|
| 15 |
import validators
|
| 16 |
import matchering as mg
|
| 17 |
from typing import Any, Optional
|
| 18 |
+
import spaces # Added for @spaces.GPU
|
| 19 |
|
| 20 |
# Logging setup
|
| 21 |
logging.basicConfig(level=logging.INFO)
|
|
|
|
| 64 |
# Device and autocast setup
|
| 65 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 66 |
use_autocast = device == "cuda"
|
| 67 |
+
logger.info(f"Using device: {device}")
|
| 68 |
|
| 69 |
+
# ROFORMER_MODELS and OUTPUT_FORMATS
|
| 70 |
ROFORMER_MODELS = {
|
| 71 |
"Vocals": {
|
| 72 |
'MelBand Roformer | Big Beta 6X by unwa': 'melband_roformer_big_beta6x.ckpt',
|
|
|
|
| 160 |
|
| 161 |
OUTPUT_FORMATS = ['wav', 'flac', 'mp3', 'ogg', 'opus', 'm4a', 'aiff', 'ac3']
|
| 162 |
|
| 163 |
+
# CSS (unchanged from provided version)
|
| 164 |
CSS = """
|
| 165 |
/* Modern ve Etkileşimli Tema */
|
| 166 |
#app-container {
|
|
|
|
| 175 |
min-height: 100vh;
|
| 176 |
background: linear-gradient(135deg, #1a0b2e, #2e1a47);
|
| 177 |
position: relative;
|
| 178 |
+
overflow: visible;
|
| 179 |
}
|
| 180 |
body {
|
| 181 |
background: none;
|
|
|
|
| 232 |
width: 100%;
|
| 233 |
transition: transform 0.3s ease;
|
| 234 |
position: relative;
|
| 235 |
+
z-index: 10;
|
| 236 |
}
|
| 237 |
.dubbing-theme:hover {
|
| 238 |
transform: translateY(-5px);
|
|
|
|
| 322 |
font-size: 1rem !important;
|
| 323 |
transition: border-color 0.3s ease, box-shadow 0.3s ease !important;
|
| 324 |
position: relative;
|
| 325 |
+
z-index: 100;
|
| 326 |
}
|
| 327 |
.compact-dropdown:hover {
|
| 328 |
border-color: #ff8787 !important;
|
|
|
|
| 344 |
border: 2px solid #ff6b6b !important;
|
| 345 |
border-radius: 8px !important;
|
| 346 |
color: #e0e0e0 !important;
|
| 347 |
+
max-height: 300px !important;
|
| 348 |
overflow-y: auto !important;
|
| 349 |
+
z-index: 200 !important;
|
| 350 |
width: 100% !important;
|
| 351 |
+
opacity: 1 !important;
|
| 352 |
visibility: visible !important;
|
| 353 |
position: absolute !important;
|
| 354 |
top: 100% !important;
|
|
|
|
| 411 |
max-width: 100%;
|
| 412 |
}
|
| 413 |
.compact-dropdown .gr-dropdown-menu {
|
| 414 |
+
max-height: 200px !important;
|
| 415 |
}
|
| 416 |
}
|
| 417 |
"""
|
|
|
|
| 455 |
logger.error(f"Download failed: {e}")
|
| 456 |
raise RuntimeError(f"Download failed: {e}")
|
| 457 |
|
| 458 |
+
@spaces.GPU
|
| 459 |
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)):
|
| 460 |
"""Separate audio into stems using a Roformer model."""
|
| 461 |
if not audio:
|
|
|
|
| 475 |
else:
|
| 476 |
raise ValueError(f"Model '{model_key}' not found.")
|
| 477 |
|
| 478 |
+
logger.info(f"Separating {base_name} with {model_key} on {device}")
|
| 479 |
try:
|
| 480 |
separator = Separator(
|
| 481 |
log_level=logging.INFO,
|
|
|
|
| 502 |
logger.error(f"Separation failed: {e}")
|
| 503 |
raise RuntimeError(f"Separation failed: {e}")
|
| 504 |
|
| 505 |
+
@spaces.GPU
|
| 506 |
def auto_ensemble_process(audio, model_keys, seg_size, overlap, out_format, use_tta, model_dir, output_dir, norm_thresh, amp_thresh, batch_size, ensemble_method, exclude_stems="", weights_str="", progress=gr.Progress()):
|
| 507 |
"""Perform ensemble processing on audio using multiple Roformer models."""
|
| 508 |
if not audio or not model_keys:
|
|
|
|
| 515 |
os.makedirs(output_dir, exist_ok=True)
|
| 516 |
|
| 517 |
base_name = os.path.splitext(os.path.basename(audio))[0]
|
| 518 |
+
logger.info(f"Ensemble for {base_name} with {model_keys} on {device}")
|
| 519 |
|
| 520 |
all_stems = []
|
| 521 |
total_models = len(model_keys)
|