Spaces:
Sleeping
Sleeping
File size: 1,396 Bytes
a5a6a2e | 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 | # Use Python 3.10 slim image for compatibility with AI libraries
FROM python:3.10-slim-bullseye
# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV DEBIAN_FRONTEND=noninteractive
# Set working directory
WORKDIR /app
# Install system dependencies required for OpenCV
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1-mesa-glx \
libglib2.0-0 \
libsm6 \
libxext6 \
libxrender-dev \
wget \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application code
COPY . .
# Ensure the LBF model is present (download if missing during build)
# We can run a small python script to check/download it
RUN python3 -c "import landmarks; landmarks.ensure_model()"
# Train the model during build (if dataset is provided in the context)
RUN if [ -d "dataset" ]; then \
echo "Dataset found. Training face shape model..." && \
python3 train_means.py; \
else \
echo "No dataset found. Using pre-trained face_shape_means.pkl if available."; \
fi
# Expose port (HF Spaces uses 7860 by default)
EXPOSE 7860
# Start the server (Railway/Spaces provide PORT env var)
# We default to 7860 for HF Spaces
CMD ["sh", "-c", "uvicorn app:app --host 0.0.0.0 --port ${PORT:-7860}"]
|