FROM nvidia/cuda:12.1.1-runtime-ubuntu22.04 ENV DEBIAN_FRONTEND=noninteractive \ PYTHONDONTWRITEBYTECODE=1 \ PYTHONUNBUFFERED=1 RUN apt-get update && apt-get install -y --no-install-recommends \ python3 python3-pip python3-venv wget ca-certificates && \ ln -sf /usr/bin/python3 /usr/bin/python && \ rm -rf /var/lib/apt/lists/* WORKDIR /app # Pin versions known to work with Piper import layout RUN pip install --no-cache-dir fastapi==0.115.0 uvicorn[standard]==0.30.6 \ piper-tts==1.2.0 onnxruntime==1.18.1 # Try GPU provider; remain functional on CPU if driver not present at runtime RUN pip install --no-cache-dir onnxruntime-gpu==1.18.1 || true # Bake model assets at build time (no runtime downloads) RUN mkdir -p models && \ wget -O models/en_US-ljspeech-medium.onnx \ https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/ljspeech/medium/en_US-ljspeech-medium.onnx && \ wget -O models/en_US-ljspeech-medium.onnx.json \ https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/ljspeech/medium/en_US-ljspeech-medium.onnx.json COPY app.py /app/app.py ENV PIPER_MODEL=models/en_US-ljspeech-medium.onnx EXPOSE 7860 # Bind to 0.0.0.0:7860 for Spaces ingress; CPU path works when CUDA not available CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--no-access-log"]