Spaces:
Paused
Paused
File size: 1,455 Bytes
a3982b2 df85082 a3982b2 df85082 a3982b2 df85082 a3982b2 |
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 41 42 43 44 |
import os
import sys # <--- ADD THIS LINE
import logging
# --- ADD THESE LINES TO FIX THE IMPORT PATH ---
# The Dockerfile places the cloned repo at /app/neutts-air
NEUTTS_PATH = "/app/neutts-air"
if NEUTTS_PATH not in sys.path:
sys.path.insert(0, NEUTTS_PATH)
# ---------------------------------------------
# Set cache environment variables before any other imports
CACHE_DIR = "/app/cache"
os.environ['HF_HOME'] = CACHE_DIR
os.environ['HUGGINGFACE_HUB_CACHE'] = CACHE_DIR
# Now this import will work correctly
from neuttsair.neutts import NeuTTSAir
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def preload_model():
"""
Downloads and caches the NeuTTSAir model and its dependencies
to the directory specified by HF_HOME.
"""
logger.info(f"Pre-loading NeuTTS Air model to cache: {CACHE_DIR}...")
try:
# Instantiating the class triggers the download from Hugging Face Hub
NeuTTSAir(
backbone_repo="neuphonic/neutts-air",
backbone_device="cpu",
codec_repo="neuphonic/neucodec",
codec_device="cpu"
)
logger.info("✅ NeuTTS Air model pre-loading completed successfully!")
except Exception as e:
logger.error(f"❌ Error during model pre-loading: {e}")
# We raise the exception to fail the build if the model can't be downloaded
raise e
if __name__ == "__main__":
preload_model() |