kataria_opticals_api / Dockerfile
codernotme's picture
commit
a5a6a2e verified
# 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}"]