Spaces:
Sleeping
Sleeping
| # Use Python 3.12 as base image | |
| FROM python:3.12-slim | |
| # Install system dependencies including OpenCV requirements | |
| RUN apt-get update && apt-get install -y \ | |
| curl \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender1 \ | |
| libgomp1 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set up a new user named "user" with user ID 1000 (HF Spaces requirement) | |
| RUN useradd -m -u 1000 user | |
| # Switch to the "user" user | |
| USER user | |
| # Set home to the user's home directory | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| # Set the working directory to the user's home directory | |
| WORKDIR $HOME/app | |
| # Upgrade pip and install dependencies | |
| RUN pip install --no-cache-dir --upgrade pip | |
| # Copy requirements first for better Docker layer caching | |
| # Note: For HF Spaces deployment, files are in root. For local builds, adjust paths as needed. | |
| COPY --chown=user requirements.txt $HOME/app/ | |
| # Install Python dependencies | |
| RUN pip install --no-cache-dir --user -r requirements.txt | |
| # Copy the source code | |
| # Note: For HF Spaces, files are synced to root directory | |
| COPY --chown=user src/ $HOME/app/src/ | |
| COPY --chown=user models/ $HOME/app/models/ | |
| # Copy the main entry point | |
| COPY --chown=user main.py $HOME/app/ | |
| # Expose the port that the app runs on (HF Spaces default is 7860) | |
| EXPOSE 7860 | |
| # Set environment variables | |
| ENV PYTHONPATH=$HOME/app | |
| ENV PORT=7860 | |
| # Health check to ensure the API is running | |
| HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ | |
| CMD curl -f http://localhost:7860/health || exit 1 | |
| # Start the application directly | |
| CMD ["python", "main.py"] | |