backend / Dockerfile
Bc-AI's picture
Upload 3 files
321b635 verified
# ── Mochiva HF Space β€” CPU inference server ──────────────────────────────────
# Base: Python 3.11 slim (small image, fast startup on HF free tier)
FROM python:3.11-slim
# HF Spaces runs as user 1000 β€” set up a non-root user
RUN useradd -m -u 1000 mochiva
WORKDIR /app
RUN chown mochiva /app
# ── System dependencies ────────────────────────────────────────────────────
# Only what we strictly need: no CUDA, no build tools for heavy packages
RUN apt-get update && apt-get install -y --no-install-recommends \
git \
curl \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# ── Python dependencies ────────────────────────────────────────────────────
COPY requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
# ── App code ───────────────────────────────────────────────────────────────
COPY app.py .
# ── HF Spaces metadata ────────────────────────────────────────────────────
# Port 7860 is the standard HF Space port
EXPOSE 7860
# ── Run as non-root ────────────────────────────────────────────────────────
USER mochiva
# ── Startup ────────────────────────────────────────────────────────────────
# --workers 1: model is loaded once in the main process; threading handles concurrency
# --timeout-keep-alive 30: keep SSE connections alive
CMD ["uvicorn", "app:app", \
"--host", "0.0.0.0", \
"--port", "7860", \
"--workers", "1", \
"--timeout-keep-alive", "30", \
"--log-level", "info"]