Download Dockerfile from Nausad/Vision_Transformer_Based_Image_Classification_Model: direct link, hf CLI and curl.
- Browser
- Download file 3.26 kB
-
https://huggingface.co/spaces/Nausad/Vision_Transformer_Based_Image_Classification_Model/resolve/main/Dockerfile
- Command line
-
hf download hf://spaces/Nausad/Vision_Transformer_Based_Image_Classification_Model/Dockerfile
-
curl -L -o Dockerfile https://huggingface.co/spaces/Nausad/Vision_Transformer_Based_Image_Classification_Model/resolve/main/Dockerfile
3.26 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 | |
| # Pin CPU threads β prevents over-subscription on HF free-tier (2 vCPUs) | |
| ENV OMP_NUM_THREADS=2 | |
| ENV MKL_NUM_THREADS=2 | |
| # βββ 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) βββββββββββββββββββββββββ | |
| # --worker-class gthread: Uses a threaded worker so the heartbeat thread | |
| # stays alive during long CPU inference (sync workers block the heartbeat | |
| # and get killed by the arbiter even when timeout is set high). | |
| # --threads 2: One thread handles the request, the other keeps heartbeat alive. | |
| # --timeout 300: Safety net for very slow inference on free-tier CPUs. | |
| # --preload: Load the model once before forking (saves memory). | |
| CMD ["gunicorn", \ | |
| "--bind", "0.0.0.0:7860", \ | |
| "--workers", "1", \ | |
| "--worker-class", "gthread", \ | |
| "--threads", "2", \ | |
| "--timeout", "300", \ | |
| "--preload", \ | |
| "--log-level", "info", \ | |
| "app:app"] | |