# Use official PyTorch image with CUDA if available, else CPU-only python base # For portability default to python:3.10-slim; users with GPU can adapt. FROM python:3.10-slim ENV PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 \ PIP_NO_CACHE_DIR=1 \ HF_HOME=/app/.cache/huggingface \ HF_TOKEN="" # System deps RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ git \ libgl1 \ && rm -rf /var/lib/apt/lists/* # Ensure HF cache dir exists and is writable RUN mkdir -p /app/.cache/huggingface && chmod -R 777 /app/.cache WORKDIR /app # Copy only requirements first for better caching COPY requirements.txt /app/requirements.txt # Install Python dependencies RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir -r requirements.txt # Copy application code COPY . /app # Optional: allow passing HF_TOKEN at runtime for private models # ENV HF_TOKEN="" # Expose port EXPOSE 7860 # Model weights will be downloaded on first run CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]