File size: 1,310 Bytes
6c8167c 0d86501 6c8167c 8f0caba 6c8167c 4bb00e8 6c8167c 4bb00e8 6c8167c 81f9771 6c8167c 4bb00e8 | 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 | # Use official Python runtime as a parent image
FROM python:3.10-slim
# Set working directory
WORKDIR /app
# Install system dependencies required for OpenCV
RUN apt-get update && apt-get install -y \
libgl1 \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# Copy backend requirements
COPY backend/requirements.txt ./backend/requirements.txt
# Install python dependencies
RUN pip install --no-cache-dir -r backend/requirements.txt
# Pre-download AI models to bake them into the image
# This prevents timeouts and slow startup on Render
COPY backend/download_models.py ./backend/download_models.py
RUN python backend/download_models.py
# Copy the rest of the application code
COPY backend ./backend
# Expose port 7860 (Hugging Face Spaces Default)
EXPOSE 7860
# Set environment variables
ENV HOST=0.0.0.0
ENV PORT=7860
ENV PYTHONUNBUFFERED=1
ENV TF_USE_LEGACY_KERAS=1
# Create a non-root user with ID 1000 (Required for HF Spaces)
RUN useradd -m -u 1000 user
# Change ownership of the app directory to the new user
RUN chown -R user:user /app
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Command to run the application
# We use shell form to ensure environment variables are expanded correctly
CMD ["sh", "-c", "uvicorn backend.app:app --host 0.0.0.0 --port $PORT"]
|