Spaces:
Runtime error
Runtime error
| # Use NVIDIA CUDA runtime as base for better GPU support | |
| FROM nvidia/cuda:12.4.1-runtime-ubuntu20.04 | |
| # Set environment variables | |
| ENV PYTHONUNBUFFERED=1 | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # Install Python and system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| python3.11 \ | |
| python3.11-dev \ | |
| python3-pip \ | |
| git \ | |
| wget \ | |
| curl \ | |
| build-essential \ | |
| ffmpeg \ | |
| libsndfile1 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set Python 3.11 as default | |
| RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.11 1 | |
| RUN update-alternatives --install /usr/bin/python python /usr/bin/python3.11 1 | |
| # Set working directory | |
| WORKDIR /app | |
| # Install PyTorch with CUDA support | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cu124 | |
| # Copy requirements and install other dependencies | |
| COPY requirements.txt ./ | |
| RUN pip install --no-cache-dir fastapi uvicorn[standard] python-dotenv python-multipart requests psutil chatterbox-tts | |
| # Copy application code | |
| COPY app/ ./app/ | |
| COPY main.py ./ | |
| # Copy voice sample if it exists (optional, can be mounted) | |
| COPY voice-sample.mp3 ./voice-sample.mp3 | |
| # Create directory for model cache (separate from source code) | |
| RUN mkdir -p /cache | |
| # Set default environment variables (prefer CUDA) | |
| ENV PORT=4123 | |
| ENV EXAGGERATION=0.5 | |
| ENV CFG_WEIGHT=0.5 | |
| ENV TEMPERATURE=0.8 | |
| ENV VOICE_SAMPLE_PATH=/app/voice-sample.mp3 | |
| ENV MAX_CHUNK_LENGTH=280 | |
| ENV MAX_TOTAL_LENGTH=3000 | |
| ENV DEVICE=cuda | |
| ENV MODEL_CACHE_DIR=/cache | |
| ENV HOST=0.0.0.0 | |
| # NVIDIA/CUDA environment variables | |
| ENV NVIDIA_VISIBLE_DEVICES=all | |
| ENV NVIDIA_DRIVER_CAPABILITIES=compute,utility | |
| # Expose port | |
| EXPOSE ${PORT} | |
| # Health check | |
| HEALTHCHECK --interval=30s --timeout=30s --start-period=5m --retries=3 \ | |
| CMD curl -f http://localhost:${PORT}/health || exit 1 | |
| # Run the application with the new entry point | |
| CMD ["python", "main.py"] |