RVC-CH / lib /models.py
LosCaquitos's picture
Update lib/models.py
2113afc verified
"""
Model management: list, download, upload.
"""
import os
import shutil
import zipfile
from pathlib import Path
from .config import MODELS_DIR, BUILTIN_MODELS, logger
os.makedirs(MODELS_DIR, exist_ok=True)
def list_models() -> list:
"""Return list of available model names (built-in + custom)."""
models = set(BUILTIN_MODELS.keys())
for item in os.listdir(MODELS_DIR):
if os.path.isdir(os.path.join(MODELS_DIR, item)):
models.add(item)
elif item.endswith(".pth"):
models.add(item.replace(".pth", ""))
return sorted(models)
def startup_downloads() -> str:
"""Download built-in models if not present. Returns first model name."""
logger.info("Checking built-in models...")
# Implemente o download real se necessário
return list_models()[0] if list_models() else ""
def download_demucs_model() -> None:
"""Ensure Demucs model is cached (optional)."""
try:
subprocess.run([
"python3", "-m", "demucs.separate",
"--two-stems=vocals", "-n", "htdemucs",
"-d", "cpu", "--help"
], capture_output=True, check=True)
logger.info("Demucs model check passed")
except Exception as e:
logger.warning(f"Demucs model not yet cached: {e}")