| FROM python:3.11-slim | |
| # Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| libgl1 \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxext6 \ | |
| libxrender1 \ | |
| libgomp1 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Set up a non-root user for HF Spaces | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| WORKDIR $HOME/app | |
| # Install Python deps | |
| COPY --chown=user requirements.txt . | |
| # Debug: show what's in requirements.txt | |
| RUN cat requirements.txt | |
| RUN pip install --no-cache-dir --user -r requirements.txt | |
| # Copy app code | |
| COPY --chown=user . . | |
| # Download model files at build time | |
| RUN python download_models.py | |
| # Ensure static directories exist and are writable | |
| RUN mkdir -p static/uploads static/results models | |
| EXPOSE 7860 | |
| CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--timeout", "120", "app:app"] | |