# HuggingFace Spaces requires port 7860 — do not change FROM python:3.10-slim # Create non-root user (required by HF Spaces) RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /app # Install dependencies first (layer caching) COPY --chown=user requirements.txt requirements.txt RUN pip install --no-cache-dir -r requirements.txt # Copy the rest of the backend code COPY --chown=user . . # Download model from HuggingFace Hub at build time RUN python - <<'EOF' from huggingface_hub import snapshot_download import os os.makedirs("models", exist_ok=True) snapshot_download( repo_id="saidimn/ids-cnn-cicids2017", local_dir="models", ignore_patterns=["*.git*", ".gitattributes"] ) print("Models downloaded successfully.") EOF # HF Spaces only allows port 7860 EXPOSE 7860 # Start Flask via gunicorn on port 7860 # Change "app:app" if your Flask instance is named differently CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "1", "--timeout", "120", "app:app"]