chatbot / Dockerfile
digifreely's picture
Upload 3 files
b9cacf3 verified
# ── Base image ────────────────────────────────────────────────
FROM python:3.11-slim
# ── System dependencies ────────────────────────────────────────
# libgomp1 is required by ONNX Runtime (used internally by piper-tts)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# ── Non-root user required by HuggingFace Spaces ──────────────
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# ── Working directory ──────────────────────────────────────────
WORKDIR $HOME/app
# ── Install Python dependencies ────────────────────────────────
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
# ── Download Piper voice model (en_US-lessac-medium) ──────────
# Model and its JSON config are fetched from the official Piper voices repo
RUN mkdir -p $HOME/app/models \
&& curl -L -o $HOME/app/models/en_US-lessac-medium.onnx \
"https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_US/lessac/medium/en_US-lessac-medium.onnx" \
&& curl -L -o $HOME/app/models/en_US-lessac-medium.onnx.json \
"https://huggingface.co/rhasspy/piper-voices/resolve/v1.0.0/en/en_US/lessac/medium/en_US-lessac-medium.onnx.json"
# ── Copy application code ──────────────────────────────────────
COPY --chown=user app.py .
# ── Expose the port HuggingFace Spaces expects ─────────────────
EXPOSE 7860
# ── Start the server ───────────────────────────────────────────
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]