Spaces:
Sleeping
Sleeping
Commit ·
19b877f
1
Parent(s): d775c8a
Fix model download reliability and silent import failures
Browse filesExtract ensure_pretrained_models() into ensure_models.py and call it
from webui.py before AppState init, so models are downloaded regardless
of entry point. Narrow except clauses in preprocess/tools/__init__.py
from Exception to ImportError so real errors propagate instead of
silently setting classes to None.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- app.py +2 -42
- ensure_models.py +45 -0
- preprocess/tools/__init__.py +3 -3
- webui.py +3 -0
app.py
CHANGED
|
@@ -3,55 +3,15 @@ Hugging Face Space entry point for SoulX-Singer.
|
|
| 3 |
Downloads pretrained models from the Hub if needed, then launches the Gradio app.
|
| 4 |
"""
|
| 5 |
import os
|
| 6 |
-
import sys
|
| 7 |
from pathlib import Path
|
| 8 |
|
| 9 |
# Set matplotlib backend before any imports that might use it (required for headless environments)
|
| 10 |
import matplotlib
|
| 11 |
matplotlib.use('Agg') # Use non-interactive backend
|
| 12 |
|
| 13 |
-
|
| 14 |
-
PRETRAINED_DIR = ROOT / "pretrained_models"
|
| 15 |
-
MODEL_DIR_SVS = PRETRAINED_DIR / "SoulX-Singer"
|
| 16 |
-
MODEL_DIR_PREPROCESS = PRETRAINED_DIR / "SoulX-Singer-Preprocess"
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
def ensure_pretrained_models():
|
| 20 |
-
"""Download SoulX-Singer and Preprocess models from Hugging Face Hub if not present."""
|
| 21 |
-
if (MODEL_DIR_SVS / "model.pt").exists() and MODEL_DIR_PREPROCESS.exists():
|
| 22 |
-
print("Pretrained models already present, skipping download.", flush=True)
|
| 23 |
-
return
|
| 24 |
-
|
| 25 |
-
try:
|
| 26 |
-
from huggingface_hub import snapshot_download
|
| 27 |
-
except ImportError:
|
| 28 |
-
print(
|
| 29 |
-
"huggingface_hub not installed. Install with: pip install huggingface_hub",
|
| 30 |
-
file=sys.stderr,
|
| 31 |
-
flush=True,
|
| 32 |
-
)
|
| 33 |
-
raise
|
| 34 |
-
|
| 35 |
-
PRETRAINED_DIR.mkdir(parents=True, exist_ok=True)
|
| 36 |
-
|
| 37 |
-
if not (MODEL_DIR_SVS / "model.pt").exists():
|
| 38 |
-
print("Downloading SoulX-Singer model...", flush=True)
|
| 39 |
-
snapshot_download(
|
| 40 |
-
repo_id="Soul-AILab/SoulX-Singer",
|
| 41 |
-
local_dir=str(MODEL_DIR_SVS),
|
| 42 |
-
local_dir_use_symlinks=False,
|
| 43 |
-
)
|
| 44 |
-
print("SoulX-Singer model ready.", flush=True)
|
| 45 |
-
|
| 46 |
-
if not MODEL_DIR_PREPROCESS.exists():
|
| 47 |
-
print("Downloading SoulX-Singer-Preprocess models...", flush=True)
|
| 48 |
-
snapshot_download(
|
| 49 |
-
repo_id="Soul-AILab/SoulX-Singer-Preprocess",
|
| 50 |
-
local_dir=str(MODEL_DIR_PREPROCESS),
|
| 51 |
-
local_dir_use_symlinks=False,
|
| 52 |
-
)
|
| 53 |
-
print("SoulX-Singer-Preprocess models ready.", flush=True)
|
| 54 |
|
|
|
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
| 57 |
os.chdir(ROOT)
|
|
|
|
| 3 |
Downloads pretrained models from the Hub if needed, then launches the Gradio app.
|
| 4 |
"""
|
| 5 |
import os
|
|
|
|
| 6 |
from pathlib import Path
|
| 7 |
|
| 8 |
# Set matplotlib backend before any imports that might use it (required for headless environments)
|
| 9 |
import matplotlib
|
| 10 |
matplotlib.use('Agg') # Use non-interactive backend
|
| 11 |
|
| 12 |
+
from ensure_models import ensure_pretrained_models
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
ROOT = Path(__file__).resolve().parent
|
| 15 |
|
| 16 |
if __name__ == "__main__":
|
| 17 |
os.chdir(ROOT)
|
ensure_models.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Download pretrained models from Hugging Face Hub if not already present."""
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
ROOT = Path(__file__).resolve().parent
|
| 6 |
+
PRETRAINED_DIR = ROOT / "pretrained_models"
|
| 7 |
+
MODEL_DIR_SVS = PRETRAINED_DIR / "SoulX-Singer"
|
| 8 |
+
MODEL_DIR_PREPROCESS = PRETRAINED_DIR / "SoulX-Singer-Preprocess"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def ensure_pretrained_models():
|
| 12 |
+
"""Download SoulX-Singer and Preprocess models from Hugging Face Hub if not present."""
|
| 13 |
+
if (MODEL_DIR_SVS / "model.pt").exists() and MODEL_DIR_PREPROCESS.exists():
|
| 14 |
+
print("Pretrained models already present, skipping download.", flush=True)
|
| 15 |
+
return
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
from huggingface_hub import snapshot_download
|
| 19 |
+
except ImportError:
|
| 20 |
+
print(
|
| 21 |
+
"huggingface_hub not installed. Install with: pip install huggingface_hub",
|
| 22 |
+
file=sys.stderr,
|
| 23 |
+
flush=True,
|
| 24 |
+
)
|
| 25 |
+
raise
|
| 26 |
+
|
| 27 |
+
PRETRAINED_DIR.mkdir(parents=True, exist_ok=True)
|
| 28 |
+
|
| 29 |
+
if not (MODEL_DIR_SVS / "model.pt").exists():
|
| 30 |
+
print("Downloading SoulX-Singer model...", flush=True)
|
| 31 |
+
snapshot_download(
|
| 32 |
+
repo_id="Soul-AILab/SoulX-Singer",
|
| 33 |
+
local_dir=str(MODEL_DIR_SVS),
|
| 34 |
+
local_dir_use_symlinks=False,
|
| 35 |
+
)
|
| 36 |
+
print("SoulX-Singer model ready.", flush=True)
|
| 37 |
+
|
| 38 |
+
if not MODEL_DIR_PREPROCESS.exists():
|
| 39 |
+
print("Downloading SoulX-Singer-Preprocess models...", flush=True)
|
| 40 |
+
snapshot_download(
|
| 41 |
+
repo_id="Soul-AILab/SoulX-Singer-Preprocess",
|
| 42 |
+
local_dir=str(MODEL_DIR_PREPROCESS),
|
| 43 |
+
local_dir_use_symlinks=False,
|
| 44 |
+
)
|
| 45 |
+
print("SoulX-Singer-Preprocess models ready.", flush=True)
|
preprocess/tools/__init__.py
CHANGED
|
@@ -28,16 +28,16 @@ from .vocal_detection import VocalDetector
|
|
| 28 |
# Keep the public surface stable while avoiding hard import failures.
|
| 29 |
try:
|
| 30 |
from .vocal_separation.model import VocalSeparator # type: ignore
|
| 31 |
-
except
|
| 32 |
VocalSeparator = None # type: ignore
|
| 33 |
|
| 34 |
try:
|
| 35 |
from .note_transcription.model import NoteTranscriber # type: ignore
|
| 36 |
-
except
|
| 37 |
NoteTranscriber = None # type: ignore
|
| 38 |
try:
|
| 39 |
from .lyric_transcription import LyricTranscriber
|
| 40 |
-
except
|
| 41 |
LyricTranscriber = None # type: ignore
|
| 42 |
|
| 43 |
__all__ = [
|
|
|
|
| 28 |
# Keep the public surface stable while avoiding hard import failures.
|
| 29 |
try:
|
| 30 |
from .vocal_separation.model import VocalSeparator # type: ignore
|
| 31 |
+
except ImportError: # pragma: no cover
|
| 32 |
VocalSeparator = None # type: ignore
|
| 33 |
|
| 34 |
try:
|
| 35 |
from .note_transcription.model import NoteTranscriber # type: ignore
|
| 36 |
+
except ImportError: # pragma: no cover
|
| 37 |
NoteTranscriber = None # type: ignore
|
| 38 |
try:
|
| 39 |
from .lyric_transcription import LyricTranscriber
|
| 40 |
+
except ImportError: # pragma: no cover
|
| 41 |
LyricTranscriber = None # type: ignore
|
| 42 |
|
| 43 |
__all__ = [
|
webui.py
CHANGED
|
@@ -269,6 +269,9 @@ class AppState:
|
|
| 269 |
return True, "svs inference done", merged
|
| 270 |
|
| 271 |
|
|
|
|
|
|
|
|
|
|
| 272 |
APP_STATE = AppState()
|
| 273 |
|
| 274 |
|
|
|
|
| 269 |
return True, "svs inference done", merged
|
| 270 |
|
| 271 |
|
| 272 |
+
from ensure_models import ensure_pretrained_models
|
| 273 |
+
ensure_pretrained_models()
|
| 274 |
+
|
| 275 |
APP_STATE = AppState()
|
| 276 |
|
| 277 |
|