Spaces:
Sleeping
Sleeping
| # --------------------------------------------------------------------------- # | |
| # Dockerfile for Hugging Face Spaces (Docker SDK) | |
| # Crop vs No-Crop Segmentation - SegFormer-B2 - CPU optimized | |
| # --------------------------------------------------------------------------- # | |
| FROM python:3.10-slim | |
| # --- Environment ----------------------------------------------------------- # | |
| ENV PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PIP_NO_CACHE_DIR=1 \ | |
| PIP_DISABLE_PIP_VERSION_CHECK=1 \ | |
| # Hugging Face cache in a writable location (model config + best.pt land here) | |
| HF_HOME=/home/user/.cache/huggingface | |
| # --- System dependencies --------------------------------------------------- # | |
| # opencv-python-headless needs libglib2.0-0 at runtime. | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libglib2.0-0 \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # --- Non-root user (Hugging Face Spaces best practice) --------------------- # | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| WORKDIR /home/user/app | |
| # --- Python dependencies --------------------------------------------------- # | |
| COPY --chown=user requirements.txt . | |
| # Install the CPU-only build of torch/torchvision first to keep the image | |
| # small (no CUDA libraries). The subsequent -r install then finds them already | |
| # satisfied and skips re-downloading. | |
| RUN pip install --upgrade pip && \ | |
| pip install --no-cache-dir \ | |
| torch torchvision \ | |
| --index-url https://download.pytorch.org/whl/cpu && \ | |
| pip install --no-cache-dir -r requirements.txt | |
| # --- Application code ------------------------------------------------------ # | |
| COPY --chown=user . . | |
| # Streamlit listens on 8501 (matched by app_port in README front matter). | |
| EXPOSE 8501 | |
| CMD ["streamlit", "run", "app.py", \ | |
| "--server.port=8501", \ | |
| "--server.address=0.0.0.0", \ | |
| "--server.enableCORS=false", \ | |
| "--server.enableXsrfProtection=false"] | |