FROM python:3.9-slim WORKDIR /code # Redirect HF cache to /tmp/.cache for better performance ENV HF_HOME=/tmp/.cache ENV TRANSFORMERS_CACHE=/tmp/.cache # Add additional environment variables for optimization ENV PYTHONUNBUFFERED=1 ENV PYTHONDONTWRITEBYTECODE=1 # Install system dependencies if needed (uncomment if you need curl for health checks) # RUN apt-get update && apt-get install -y curl && rm -rf /var/lib/apt/lists/* # Copy and install Python dependencies first (better Docker layer caching) COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy the app directory with your main.py file COPY app ./app # Add health check to monitor container health HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \ CMD python -c "import requests; requests.get('http://localhost:7860/health', timeout=5)" || exit 1 # Start the application CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]