# Use a lightweight Python base FROM python:3.10-slim # Prevent interactive prompts & speed up Python ENV DEBIAN_FRONTEND=noninteractive \ PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 \ TOKENIZERS_PARALLELISM=false # Set work directory WORKDIR /code # Install system dependencies RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ git \ curl \ wget \ libopenblas-dev \ libomp-dev \ && rm -rf /var/lib/apt/lists/* # Copy requirements first (for Docker caching) COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Hugging Face tools RUN pip install --no-cache-dir huggingface-hub accelerate # Install additional dependencies RUN pip install --no-cache-dir outetts uroman # Clone yarngpt repository RUN git clone https://github.com/saheedniyi02/yarngpt.git /tmp/yarngpt && \ pip install --no-cache-dir /tmp/yarngpt && \ rm -rf /tmp/yarngpt # Set Hugging Face cache inside container (persistent, not /tmp) ENV HF_HOME=/models/huggingface ENV TRANSFORMERS_CACHE=/models/huggingface ENV HUGGINGFACE_HUB_CACHE=/models/huggingface ENV HF_HUB_CACHE=/models/huggingface # Create cache dir and models directory RUN mkdir -p /models/huggingface && \ mkdir -p /code/models # Pre-download model at build time (YarnGPT2 model) RUN python -c "from huggingface_hub import snapshot_download; snapshot_download(repo_id='saheedniyi/YarnGPT2')" # Preload tokenizer (avoid runtime delays) RUN python -c "from transformers import AutoTokenizer; AutoTokenizer.from_pretrained('saheedniyi/YarnGPT2', use_fast=True)" # Download wavtokenizer configuration file RUN wget -O /code/models/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml \ https://huggingface.co/novateur/WavTokenizer-medium-speech-75token/resolve/main/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml # Note: Checkpoint file must be downloaded separately or mounted as volume # The checkpoint is large and may not download during build RUN echo "Note: wavtokenizer_large_speech_320_24k.ckpt must be provided separately" # Copy project files COPY . . # Expose FastAPI port EXPOSE 8000 # Run FastAPI app with uvicorn (2 workers for better concurrency) CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "2"]