feat(pipeline): implement stage runner, cache, cli, and doctor command
This commit is contained in:
43
src/songsplit/config.py
Normal file
43
src/songsplit/config.py
Normal file
@ -0,0 +1,43 @@
|
||||
"""Configuration management for songsplit (devices, models, paths)."""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
|
||||
class Config(BaseModel):
|
||||
"""Runtime configuration for pipeline stages, devices, and directories."""
|
||||
|
||||
models_cache_dir: Path = Field(
|
||||
default_factory=lambda: Path(
|
||||
os.getenv("SONGSPLIT_MODELS_DIR", Path.home() / ".cache" / "songsplit" / "models")
|
||||
).expanduser()
|
||||
)
|
||||
|
||||
default_device: str = Field(default_factory=lambda: os.getenv("SONGSPLIT_DEFAULT_DEVICE", "cuda:0"))
|
||||
|
||||
stage_devices: dict[str, str] = Field(
|
||||
default_factory=lambda: {
|
||||
"s1_extract": os.getenv("SONGSPLIT_DEVICE_S1", "cpu"),
|
||||
"s2_stems": os.getenv("SONGSPLIT_DEVICE_S2", "cuda:0"),
|
||||
"s3_lyrics": os.getenv("SONGSPLIT_DEVICE_S3", "cuda:0"),
|
||||
"s4_pitch": os.getenv("SONGSPLIT_DEVICE_S4", "cuda:0"),
|
||||
"s5_tempo": os.getenv("SONGSPLIT_DEVICE_S5", "cpu"),
|
||||
"s6_chords": os.getenv("SONGSPLIT_DEVICE_S6", "cpu"),
|
||||
"s7_strumming": os.getenv("SONGSPLIT_DEVICE_S7", "cpu"),
|
||||
}
|
||||
)
|
||||
|
||||
def get_device(self, stage: str) -> str:
|
||||
"""Get target compute device for a specific stage."""
|
||||
return self.stage_devices.get(stage, self.default_device)
|
||||
|
||||
def get_models_dir(self) -> Path:
|
||||
"""Ensure and return the model cache directory."""
|
||||
self.models_cache_dir.mkdir(parents=True, exist_ok=True)
|
||||
return self.models_cache_dir
|
||||
|
||||
|
||||
# Global singleton instance
|
||||
config = Config()
|
||||
Reference in New Issue
Block a user