Spaces:
Runtime error
Runtime error
File size: 3,357 Bytes
df64439 7755adc df64439 7755adc df64439 7755adc df64439 7755adc df64439 7755adc df64439 7755adc df64439 7755adc e05e60f df64439 7755adc e05e60f df64439 7755adc df64439 7755adc df64439 7755adc df64439 7755adc df64439 7755adc df64439 7755adc df64439 7755adc df64439 | 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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | # ============================================================
# Stage 1: Builder β install Python dependencies
# ============================================================
FROM python:3.11-slim AS builder
WORKDIR /install
# Build-time system deps (compilers, headers needed by grpcio, cffi, etc.)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
wget \
libgl1 \
libglib2.0-0 \
libgomp1 \
libsm6 \
libxext6 \
libxrender1 \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt .
# Install all Python deps + gunicorn into an isolated prefix
RUN pip install --no-cache-dir --prefix=/python-deps -r requirements.txt gunicorn
# Pre-download the MediaPipe face-detector tflite model at build time
# so the container never needs to reach out to Google Storage at runtime.
RUN mkdir -p /models && \
wget -q -O /models/detector.tflite \
"https://storage.googleapis.com/mediapipe-models/face_detector/blaze_face_short_range/float16/1/blaze_face_short_range.tflite"
# ============================================================
# Stage 2: Runtime image
# ============================================================
FROM python:3.11-slim
LABEL maintainer="undertone-classification"
LABEL description="Skin undertone classification β Flask + TensorFlow + MediaPipe (HF Spaces)"
# Runtime system libs required by OpenCV and MediaPipe
# libgles2 β provides libGLESv2.so.2 (MediaPipe C bindings hard-require this)
# libegl1 β provides libEGL.so.1 (MediaPipe GPU/EGL path)
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1 \
libglib2.0-0 \
libgomp1 \
libsm6 \
libxext6 \
libxrender1 \
libgles2 \
libegl1 \
&& rm -rf /var/lib/apt/lists/*
# Copy installed Python packages from the builder stage
COPY --from=builder /python-deps /usr/local
# ββ Hugging Face Spaces requirement ββββββββββββββββββββββββββ
# HF Spaces runs containers with a non-root user (UID=1000, GID=1000).
# We create that user and make /app writable so Flask can write uploads.
RUN useradd -m -u 1000 appuser
WORKDIR /app
# Copy application source code
COPY app.py .
COPY templates/ templates/
COPY static/ static/
COPY models/ models/
# Copy the pre-downloaded tflite model into the models directory
COPY --from=builder /models/detector.tflite models/detector.tflite
# Ensure the uploads directory exists and is owned by the runtime user
RUN mkdir -p static/uploads && \
chown -R appuser:appuser /app
USER appuser
# ββ Port ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
# Hugging Face Spaces Docker SDK expects port 7860.
EXPOSE 7860
ENV FLASK_ENV=production \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
# Silence unnecessary TF / oneDNN log noise
TF_CPP_MIN_LOG_LEVEL=2 \
TF_ENABLE_ONEDNN_OPTS=0
# 1 worker β global ai_engine singleton is shared; 180 s timeout for
# model load + first inference.
CMD ["gunicorn", \
"--bind", "0.0.0.0:7860", \
"--workers", "1", \
"--timeout", "180", \
"--log-level", "info", \
"app:app"]
|