File size: 2,302 Bytes
b9cacf3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# ── 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"]