Spaces:
Runtime error
Runtime error
File size: 2,242 Bytes
11c6f05 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | # ============================================================
# Stage 1: Builder — install Python dependencies
# ============================================================
FROM python:3.11-slim AS builder
WORKDIR /install
# System dependencies required to build some Python packages
# (OpenCV, MediaPipe, grpcio, cffi, etc.)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libgl1 \
libglib2.0-0 \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
# Install all Python deps into an isolated prefix so we can copy
# only the built packages to the final stage
# Also install gunicorn as the production WSGI server
RUN pip install --no-cache-dir --prefix=/python-deps -r requirements.txt gunicorn
# ============================================================
# Stage 2: Runtime image
# ============================================================
FROM python:3.11-slim
LABEL maintainer="undertone-classification"
LABEL description="Skin undertone classification — Flask + TensorFlow + MediaPipe"
# Runtime system libs (OpenCV needs libGL/libGLib; MediaPipe needs libgomp)
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# Copy installed Python packages from the builder stage
COPY --from=builder /python-deps /usr/local
WORKDIR /app
# Copy application source code
COPY app.py .
COPY templates/ templates/
COPY static/ static/
COPY models/ models/
# Create uploads directory that Flask writes to at runtime
RUN mkdir -p static/uploads
# Expose Flask's default port
EXPOSE 5000
# Run with Gunicorn for production (single worker keeps model in memory)
# Falls back gracefully: if gunicorn is unavailable the CMD can be swapped
# to `python app.py` during development.
ENV FLASK_ENV=production \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1
# Use gunicorn; 1 worker so the global ai_engine singleton is shared
CMD ["python", "-m", "gunicorn", \
"--bind", "0.0.0.0:5000", \
"--workers", "1", \
"--timeout", "120", \
"app:app"]
|