Spaces:
Runtime error
Runtime error
File size: 1,215 Bytes
2dfbde4 | 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 48 49 | # === Stage 1: Build Dependencies ===
FROM python:3.9-slim AS builder
# Set environment variables
ENV PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PATH="/root/.local/bin:$PATH"
# Install only necessary system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libgl1-mesa-glx \
libglib2.0-0 \
&& rm -rf /var/lib/apt/lists/*
# Install Python dependencies
WORKDIR /app
COPY requirements.txt .
RUN pip install --user --no-cache-dir -r requirements.txt
# Copy model preparation script and run it
COPY prepare.py .
RUN python3 prepare.py
# === Stage 2: Minimal Runtime Image ===
FROM python:3.9-slim
# Set environment variables
ENV PATH="/root/.local/bin:$PATH"
# Copy only required dependencies from builder
COPY --from=builder /root/.local /root/.local
# Set work directory
WORKDIR /app
# Copy the model and class mapping
COPY --from=builder /app/model.h5 /app/model.h5
COPY --from=builder /app/class.json /app/class.json
# Copy only necessary application files
COPY app.py .
# Expose Streamlit port
EXPOSE 7860
# Run Streamlit app
CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0"]
|