File size: 1,280 Bytes
0671759
 
 
 
aac14c4
0671759
aac14c4
 
5ab587e
 
 
0671759
aac14c4
0671759
 
 
 
 
 
 
 
 
5ab587e
0671759
2113afc
0671759
2113afc
0671759
5ab587e
0671759
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""
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}")