|
| 1 | +# SongBloom Runtime Docker Image |
| 2 | +# Optimized for runtime with on-demand model weight downloads |
| 3 | +FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04 |
| 4 | + |
| 5 | +# Set environment variables |
| 6 | +ENV DEBIAN_FRONTEND=noninteractive |
| 7 | +ENV PYTHONUNBUFFERED=1 |
| 8 | +ENV CUDA_HOME=/usr/local/cuda |
| 9 | + |
| 10 | +# Install system dependencies |
| 11 | +RUN apt-get update && apt-get install -y \ |
| 12 | + python3.10 \ |
| 13 | + python3-pip \ |
| 14 | + git \ |
| 15 | + wget \ |
| 16 | + libsndfile1 \ |
| 17 | + ffmpeg \ |
| 18 | + && rm -rf /var/lib/apt/lists/* |
| 19 | + |
| 20 | +# Set working directory |
| 21 | +WORKDIR /app |
| 22 | + |
| 23 | +# Copy requirements first for better caching |
| 24 | +COPY requirements.txt . |
| 25 | + |
| 26 | +# Install Python dependencies |
| 27 | +RUN pip3 install --no-cache-dir --upgrade pip && \ |
| 28 | + pip3 install --no-cache-dir torch==2.2.0 torchaudio==2.2.0 --index-url https://download.pytorch.org/whl/cu118 && \ |
| 29 | + pip3 install --no-cache-dir -r requirements.txt |
| 30 | + |
| 31 | +# Copy application code |
| 32 | +COPY . . |
| 33 | + |
| 34 | +# Create necessary directories |
| 35 | +RUN mkdir -p /app/models/songbloom /app/cache /app/output /app/gradio_outputs /app/api_outputs /app/api_prompts |
| 36 | + |
| 37 | +# Expose ports for API and Gradio |
| 38 | +EXPOSE 7860 8000 |
| 39 | + |
| 40 | +# Create entrypoint script that downloads weights if missing |
| 41 | +RUN echo '#!/bin/bash\n\ |
| 42 | +set -e\n\ |
| 43 | +\n\ |
| 44 | +# Check if model weights exist\n\ |
| 45 | +if [ ! -d "/app/models/songbloom" ] || [ -z "$(ls -A /app/models/songbloom 2>/dev/null)" ]; then\n\ |
| 46 | + echo "🔍 Model weights not found, downloading..."\n\ |
| 47 | + python3 scripts/download_weights.py || {\n\ |
| 48 | + echo "❌ Failed to download model weights"\n\ |
| 49 | + echo "💡 You can:"\n\ |
| 50 | + echo " 1. Mount weights at /app/models/songbloom"\n\ |
| 51 | + echo " 2. Set HUGGING_FACE_HUB_TOKEN for private repos"\n\ |
| 52 | + exit 1\n\ |
| 53 | + }\n\ |
| 54 | +else\n\ |
| 55 | + echo "✓ Model weights found"\n\ |
| 56 | +fi\n\ |
| 57 | +\n\ |
| 58 | +# Execute the provided command\n\ |
| 59 | +exec python3 "$@"\n\ |
| 60 | +' > /entrypoint.sh && chmod +x /entrypoint.sh |
| 61 | + |
| 62 | +# Set entrypoint |
| 63 | +ENTRYPOINT ["/entrypoint.sh"] |
| 64 | + |
| 65 | +# Default command (can be overridden) |
| 66 | +CMD ["app.py", "--server-name", "0.0.0.0", "--server-port", "7860"] |
0 commit comments