| # Use Python 3.9 slim image | |
| FROM python:3.9-slim | |
| # Set working directory | |
| WORKDIR /app | |
| # Install system dependencies required for OpenCV | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender1 \ | |
| libgomp1 \ | |
| && apt-get clean \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Copy requirements and install Python dependencies | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir --upgrade pip && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # Copy all application files | |
| COPY . . | |
| # Create a non-root user for Hugging Face Spaces | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| # Set working directory to user home | |
| WORKDIR $HOME/app | |
| COPY --chown=user . $HOME/app | |
| # Expose port 7860 (required by Hugging Face Spaces) | |
| EXPOSE 7860 | |
| # Run the application with gunicorn | |
| CMD ["gunicorn", "-b", "0.0.0.0:7860", "app:app", "--timeout", "120", "--workers", "1", "--threads", "2"] |