Download Dockerfile from Nausad/Vision_Transformer_Based_Image_Classification_Model: direct link, hf CLI and curl.
- Browser
- Download file 2.8 kB
-
https://huggingface.co/spaces/Nausad/Vision_Transformer_Based_Image_Classification_Model/resolve/35ffb7c54fcdd1287331a0b59e79a3d2c9b65589/Dockerfile
- Command line
-
hf download hf://spaces/Nausad/Vision_Transformer_Based_Image_Classification_Model@35ffb7c54fcdd1287331a0b59e79a3d2c9b65589/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/Nausad/Vision_Transformer_Based_Image_Classification_Model/resolve/35ffb7c54fcdd1287331a0b59e79a3d2c9b65589/Dockerfile
2.8 kB
| # βββ Stage 1: Base Image βββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| FROM python:3.10-slim | |
| # Set working directory | |
| WORKDIR /app | |
| # βββ Environment Variables βββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # Prevent Python from writing .pyc files | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| # Prevent Python from buffering stdout/stderr | |
| ENV PYTHONUNBUFFERED=1 | |
| # HuggingFace Spaces runs on port 7860 | |
| ENV PORT=7860 | |
| # βββ Create a non-root user FIRST (HuggingFace requirement) ββββββββββββββββ | |
| RUN useradd -m -u 1000 appuser | |
| # βββ Install System Dependencies βββββββββββββββββββββββββββββββββββββββββββ | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| libglib2.0-0 \ | |
| libsm6 \ | |
| libxrender1 \ | |
| libxext6 \ | |
| && apt-get clean \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # βββ Install Python Dependencies βββββββββββββββββββββββββββββββββββββββββββ | |
| COPY requirements.txt . | |
| # Use CPU-only PyTorch index to keep image lean and avoid CUDA download timeouts | |
| RUN pip install --no-cache-dir \ | |
| --extra-index-url https://download.pytorch.org/whl/cpu \ | |
| -r requirements.txt | |
| # βββ Copy Application Files ββββββββββββββββββββββββββββββββββββββββββββββββ | |
| COPY app.py . | |
| COPY cifar10_model.pth . | |
| COPY templates/ ./templates/ | |
| # βββ Fix file ownership so appuser can read all files ββββββββββββββββββββββ | |
| RUN chown -R appuser:appuser /app | |
| # βββ Switch to non-root user βββββββββββββββββββββββββββββββββββββββββββββββ | |
| USER appuser | |
| # βββ Expose Port βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| EXPOSE 7860 | |
| # βββ Launch with Gunicorn (production WSGI server) βββββββββββββββββββββββββ | |
| # timeout=180 gives the model enough time to run inference on slow HF CPU | |
| # preload=true loads the model once before forking workers (saves memory) | |
| CMD ["gunicorn", \ | |
| "--bind", "0.0.0.0:7860", \ | |
| "--workers", "1", \ | |
| "--timeout", "180", \ | |
| "--preload", \ | |
| "--log-level", "info", \ | |
| "app:app"] | |