File size: 2,147 Bytes
07b8c48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# ─── 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

# ─── 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 .
RUN pip install --no-cache-dir -r requirements.txt

# ─── Copy Application Files ────────────────────────────────────────────────
COPY app.py .
COPY cifar10_model.pth .
COPY templates/ ./templates/

# ─── Create a non-root user (HuggingFace best practice) ────────────────────
RUN useradd -m -u 1000 appuser
USER appuser

# ─── Expose Port ───────────────────────────────────────────────────────────
EXPOSE 7860

# ─── Launch with Gunicorn (production WSGI server) ─────────────────────────
CMD ["gunicorn", \
     "--bind", "0.0.0.0:7860", \
     "--workers", "1", \
     "--timeout", "120", \
     "--log-level", "info", \
     "app:app"]