Files
stemengine_old/backend/config.py
T
2026-03-03 14:52:19 +09:00

266 lines
12 KiB
Python
Executable File

import os
from pathlib import Path
# Base paths — each can be overridden independently via its own env var,
# or all inherit from MEDIA_DIR when left unset.
MEDIA_DIR = Path(os.environ.get("MEDIA_DIR", "/app/media"))
UPLOAD_DIR = Path(os.environ.get("UPLOAD_DIR", str(MEDIA_DIR / "uploads")))
JOBS_DIR = Path(os.environ.get("JOBS_DIR", str(MEDIA_DIR / "jobs")))
PROJECTS_DIR = Path(os.environ.get("PROJECTS_DIR", str(MEDIA_DIR / "projects")))
DB_PATH = Path(os.environ.get("DB_PATH", str(MEDIA_DIR / "db" / "stemengine.db")))
LRC_SYNC_DIR = Path(os.environ.get("LRC_SYNC_DIR", str(MEDIA_DIR / "lrc_sync")))
# BS-RoFormer model directory
BS_ROFORMER_MODEL_DIR = Path(os.environ.get("BS_ROFORMER_MODEL_DIR", "/opt/bs_roformer_models"))
# MelBand RoFormer model directory
MEL_BAND_MODEL_DIR = Path(os.environ.get("MEL_BAND_MODEL_DIR", "/opt/mel_band_models"))
# MDX-Net model directory
MDXNET_MODEL_DIR = Path(os.environ.get("MDXNET_MODEL_DIR", "/opt/mdxnet_models"))
# SCNet XL model directory
SCNET_MODEL_DIR = Path(os.environ.get("SCNET_MODEL_DIR", "/opt/scnet_models"))
# MedleyVox model directory
MEDLEYVOX_MODEL_DIR = Path(os.environ.get("MEDLEYVOX_MODEL_DIR", "/opt/medleyvox_models"))
# Apollo model directory
APOLLO_MODEL_DIR = Path(os.environ.get("APOLLO_MODEL_DIR", "/opt/apollo_models"))
# Bandit model directory
BANDIT_MODEL_DIR = Path(os.environ.get("BANDIT_MODEL_DIR", "/opt/bandit_models"))
# Aspiration model directory
ASPIRATION_MODEL_DIR = Path(os.environ.get("ASPIRATION_MODEL_DIR", "/opt/aspiration_models"))
# Ensemble mode cache directory
ENSEMBLE_CACHE_DIR = Path(os.environ.get("ENSEMBLE_CACHE_DIR", "/app/media/ensemble_cache"))
# Separation models — Demucs + BS-RoFormer
DEMUCS_MODELS = [
{"id": "htdemucs", "label": "Demucs v4", "group": "Demucs"},
{"id": "htdemucs_ft", "label": "Demucs v4 Fine-tuned", "group": "Demucs"},
{"id": "mdx_extra_q", "label": "Demucs v3 Extra Quantized","group": "Demucs"},
{"id": "mdx", "label": "Demucs v3", "group": "Demucs"},
]
BS_ROFORMER_MODELS = [
{"id": "bs_roformer_4stem", "label": "BS-RoFormer 4-stem", "group": "BS-RoFormer"},
{"id": "bs_roformer_5stem_guitar", "label": "BS-RoFormer 5-stem (+ Guitar)", "group": "BS-RoFormer"},
{"id": "bs_roformer_5stem_piano", "label": "BS-RoFormer 5-stem (+ Piano)", "group": "BS-RoFormer"},
{"id": "bs_roformer_6stem", "label": "BS-RoFormer 6-stem (full)", "group": "BS-RoFormer"},
]
# MelBand RoFormer models
MEL_BAND_MODELS = [
{"id": "mel_band_roformer_4stem", "label": "MelBand RoFormer 4-stem", "group": "MelBand RoFormer"},
{"id": "mel_band_vocals", "label": "MelBand Vocals (2-stem)", "group": "MelBand RoFormer"},
{"id": "mel_band_vocals_anvuew", "label": "MelBand Vocals Anvuew", "group": "MelBand RoFormer"},
{"id": "mel_band_dereverb", "label": "MelBand Dereverb", "group": "MelBand RoFormer"},
{"id": "mel_band_dereverb_anvuew", "label": "MelBand Dereverb Anvuew", "group": "MelBand RoFormer"},
{"id": "mel_band_dereverb_room", "label": "MelBand Dereverb Room", "group": "MelBand RoFormer"},
{"id": "mel_band_karaoke", "label": "MelBand Karaoke (Lead/Back)", "group": "MelBand RoFormer"},
{"id": "mel_band_karaoke_gabox", "label": "MelBand Karaoke Gabox", "group": "MelBand RoFormer"},
{"id": "mel_band_deux_becruily", "label": "MelBand RoFormer Deux Becruily", "group": "MelBand RoFormer"},
]
# BS-RoFormer specialized models
BS_ROFORMER_SPECIALIZED_MODELS = [
{"id": "bs_roformer_chorus", "label": "BS-RoFormer Male/Female Chorus", "group": "BS-RoFormer"},
{"id": "bs_roformer_anvuew", "label": "BS-RoFormer Anvuew (Vocals)", "group": "BS-RoFormer"},
{"id": "bs_roformer_karaoke_anvuew", "label": "BS-RoFormer Karaoke Anvuew", "group": "BS-RoFormer"},
]
# MDX-Net models (from Ultimate Vocal Remover)
MDXNET_MODELS = [
{"id": "mdxnet_voc_ft", "label": "MDX-Net Vocals FT", "group": "MDX-Net"},
{"id": "mdxnet_inst_hq_1", "label": "MDX-Net Inst HQ 1", "group": "MDX-Net"},
{"id": "mdxnet_inst_hq_2", "label": "MDX-Net Inst HQ 2", "group": "MDX-Net"},
{"id": "mdxnet_karaoke", "label": "MDX-Net Karaoke", "group": "MDX-Net"},
{"id": "mdxnet_dereverb", "label": "MDX-Net Dereverb", "group": "MDX-Net"},
{"id": "mdxnet_drumsep", "label": "MDX-Net Drum Separation", "group": "MDX-Net"},
]
# SCNet XL models (state-of-the-art 2024-2025)
SCNET_MODELS = [
{"id": "scnet_xl", "label": "SCNet XL (2-stem)", "group": "SCNet"},
{"id": "scnet_xl_ihf", "label": "SCNet XL IHF (2-stem)", "group": "SCNet"},
{"id": "scnet_large", "label": "SCNet Large (4-stem)", "group": "SCNet"},
{"id": "scnet_large_starrytong", "label": "SCNet Large Starrytong", "group": "SCNet"},
]
# BS-RoFormer SW (Swin Transformer variant)
BS_ROFORMER_SW_MODELS = [
{"id": "bs_roformer_sw_6stem", "label": "BS-RoFormer SW 6-stem", "group": "BS-RoFormer SW"},
]
# MedleyVox models (specialized vocal separation)
MEDLEYVOX_MODELS = [
{"id": "medleyvox", "label": "MedleyVox (Vocals)", "group": "MedleyVox"},
{"id": "medleyvox_55ep", "label": "MedleyVox 55 Epochs", "group": "MedleyVox"},
{"id": "medleyvox_66ep", "label": "MedleyVox 66 Epochs", "group": "MedleyVox"},
{"id": "medleyvox_88ep", "label": "MedleyVox 88 Epochs", "group": "MedleyVox"},
{"id": "medleyvox_100ep", "label": "MedleyVox 100 Epochs", "group": "MedleyVox"},
]
# Apollo models (vocal enhancement/reverb removal)
APOLLO_MODELS = [
{"id": "apollo_vocals", "label": "Apollo Vocals (Enhancement)", "group": "Apollo"},
{"id": "apollo_edm", "label": "Apollo EDM", "group": "Apollo"},
{"id": "apollo_edm_big", "label": "Apollo EDM Big", "group": "Apollo"},
]
# Aspiration models (breath/aspiration removal)
ASPIRATION_MODELS = [
{"id": "aspiration_full", "label": "Aspiration Removal (Full)", "group": "Aspiration"},
{"id": "aspiration_light", "label": "Aspiration Removal (Light)", "group": "Aspiration"},
]
# Bandit-v2 models (multi-language/multi-stem)
BANDIT_MODELS = [
{"id": "bandit_v2_multi", "label": "Bandit v2 Multi-Language", "group": "Bandit"},
{"id": "bandit_v2_eng", "label": "Bandit v2 English", "group": "Bandit"},
]
# Ensemble modes (combines multiple models for best quality)
ENSEMBLE_MODELS = [
{"id": "ensemble_vocal_best", "label": "Ensemble - Vocal Best Quality", "group": "Ensemble"},
{"id": "ensemble_4stem", "label": "Ensemble - 4-Stem", "group": "Ensemble"},
{"id": "ensemble_6stem", "label": "Ensemble - 6-Stem Full", "group": "Ensemble"},
]
ALL_MODELS = (
DEMUCS_MODELS +
BS_ROFORMER_MODELS +
BS_ROFORMER_SW_MODELS +
BS_ROFORMER_SPECIALIZED_MODELS +
MEL_BAND_MODELS +
MDXNET_MODELS +
SCNET_MODELS +
MEDLEYVOX_MODELS +
APOLLO_MODELS +
ASPIRATION_MODELS +
BANDIT_MODELS +
ENSEMBLE_MODELS
)
DEFAULT_DEMUCS_MODEL = "htdemucs"
DEFAULT_MODEL = DEFAULT_DEMUCS_MODEL
ALL_MODEL_IDS = {m["id"] for m in ALL_MODELS}
# Output formats
OUTPUT_FORMATS = [
{"id": "mp3", "label": "MP3 (256 kbps)"},
{"id": "mp3_320", "label": "MP3 (320 kbps)"},
{"id": "flac", "label": "FLAC (lossless)"},
{"id": "wav", "label": "WAV (lossless)"},
]
DEFAULT_OUTPUT_FORMAT = "mp3"
# basic-pitch transcription modes (mapped to inference parameter presets)
TRANSCRIBE_MODES = [
{"id": "polyphonic", "label": "Polyphonic"},
{"id": "melody", "label": "Melody / Vocal"},
]
DEFAULT_TRANSCRIBE_MODE = "polyphonic"
# basic-pitch inference parameter presets per mode
TRANSCRIBE_PRESETS = {
"polyphonic": {
"onset_threshold": 0.5,
"frame_threshold": 0.3,
"minimum_note_length": 58.0,
"melodia_trick": False,
},
"melody": {
"onset_threshold": 0.5,
"frame_threshold": 0.3,
"minimum_note_length": 58.0,
"minimum_frequency": 65.0, # Hz — below typical singing range
"melodia_trick": True,
},
}
# Hardware
CPU_SEPARATION = os.environ.get("CPU_SEPARATION", "true").lower() != "false"
# Limits
MAX_UPLOAD_BYTES = int(os.environ.get("MAX_UPLOAD_MB", "500")) * 1024 * 1024
POLL_INTERVAL_SECONDS = 5.0
# ---------------------------------------------------------------------------
# Presets for stem mixing
# ---------------------------------------------------------------------------
# Available preset types
PRESET_TYPES = [
{"id": "stems_only", "label": "Stems Only", "description": "Generate separated stems only"},
{"id": "static", "label": "Static Mix", "description": "Remove specific elements completely"},
{"id": "instrumental", "label": "Instrumental", "description": "Remove vocals only"},
{"id": "dynamic", "label": "Dynamic Mix", "description": "Adjust volume levels of each element"},
]
# Static preset options (what to remove)
STATIC_OPTIONS = [
{"id": "no_vocals", "label": "No Vocals", "description": "Remove vocals (keep drums, bass, other)"},
{"id": "no_drums", "label": "No Drums", "description": "Remove drums (keep vocals, bass, other)"},
{"id": "no_bass", "label": "No Bass", "description": "Remove bass (keep vocals, drums, other)"},
{"id": "no_vocals_no_bass", "label": "No Vocals + No Bass", "description": "Remove vocals and bass"},
{"id": "no_drums_no_bass", "label": "No Drums + No Bass", "description": "Remove drums and bass (vocals + other)"},
]
# Default volume levels for dynamic preset (0.0 to 2.0, where 1.0 = original)
DEFAULT_DYNAMIC_LEVELS = {
"vocals": 1.0,
"drums": 1.0,
"bass": 1.0,
"other": 1.0,
}
# Available stems and their labels (varies by model)
STEM_LABELS = {
"vocals": "Vocals",
"drums": "Drums",
"bass": "Bass",
"other": "Other",
"guitar": "Guitar",
"piano": "Piano",
"lead": "Lead Vocals",
"backing": "Backing Vocals",
"male": "Male Vocals",
"female": "Female Vocals",
"instrumental": "Instrumental",
"dry_vocals": "Dry Vocals",
"reverb": "Reverb",
}
# ---------------------------------------------------------------------------
# Project folder structure
# ---------------------------------------------------------------------------
PROJECT_SUBFOLDERS = {
"stems": "Stems", # Always generated - contains separated stems
"instrumental": "Instrumental", # Contains instrumental mixes (no vocals)
"static": "Static", # Contains static mixes (specific elements removed)
"dynamic": "Dynamic", # Contains dynamic mixes (volume adjusted)
"transcriptions": "Transcriptions", # Contains transcription outputs
"lrc": "LRC", # Contains synced lyrics files
}
# Subsonic integration
IMPORTS_DIR = MEDIA_DIR / "imports"
SUBSONIC_CONFIG_PATH = MEDIA_DIR / "subsonic.json"
# Lyric transcription (Whisper models)
WHISPER_MODEL_DIR = Path(os.environ.get("WHISPER_MODEL_DIR", "/opt/whisper_models"))
DEFAULT_WHISPER_MODEL = os.environ.get("DEFAULT_WHISPER_MODEL", "large-v2")
# Create directories on import
UPLOAD_DIR.mkdir(parents=True, exist_ok=True)
JOBS_DIR.mkdir(parents=True, exist_ok=True)
PROJECTS_DIR.mkdir(parents=True, exist_ok=True)
DB_PATH.parent.mkdir(parents=True, exist_ok=True)
LRC_SYNC_DIR.mkdir(parents=True, exist_ok=True)
IMPORTS_DIR.mkdir(parents=True, exist_ok=True)