# Use Python 3.10 slim image for smaller size FROM python:3.10-slim # Set working directory WORKDIR /app # Install system dependencies RUN apt-get update && apt-get install -y \ gcc \ g++ \ make \ libffi-dev \ libssl-dev \ curl \ && rm -rf /var/lib/apt/lists/* # Create cache directories with proper permissions RUN mkdir -p /tmp/transformers_cache /tmp/hf_cache && \ chmod 777 /tmp/transformers_cache /tmp/hf_cache # Set environment variables for caching ENV TRANSFORMERS_CACHE=/tmp/transformers_cache ENV HF_HOME=/tmp/hf_cache ENV TRANSFORMERS_OFFLINE=0 ENV HF_DATASETS_OFFLINE=0 # Copy requirements first for better caching COPY requirements.txt . # Install Python dependencies RUN pip install --no-cache-dir -r requirements.txt # Create directories for models and temp files RUN mkdir -p /app/models /app/temp # Copy application code COPY app.py . # Set environment variables ENV PYTHONUNBUFFERED=1 ENV FLASK_APP=app.py ENV FLASK_ENV=production ENV PORT=7860 # Expose port EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=30s --start-period=120s --retries=3 \ CMD curl -f http://localhost:7860/health || exit 1 # Command to run the application CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--timeout", "300", "--worker-class", "sync", "--preload", "app:app"]