Commit ·
edbdd2a
1
Parent(s): 2b80d66
Deploy XTTS fallback as HF Inference Endpoint
Browse files- Dockerfile +27 -0
- app.py +24 -0
- huggingface.yaml +15 -0
- requirements.txt +8 -0
Dockerfile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM pytorch/pytorch:2.1.0-cuda12.1-cudnn8-runtime
|
| 2 |
+
|
| 3 |
+
# Prevent interactive tzdata prompts and accept Coqui TOS
|
| 4 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 5 |
+
ENV TZ=Etc/UTC
|
| 6 |
+
ENV COQUI_TOS_AGREED=1
|
| 7 |
+
|
| 8 |
+
# Install system dependencies
|
| 9 |
+
RUN apt-get update && \
|
| 10 |
+
apt-get install -y git ffmpeg libsndfile1 tzdata && \
|
| 11 |
+
rm -rf /var/lib/apt/lists/*
|
| 12 |
+
|
| 13 |
+
# Create working directory
|
| 14 |
+
WORKDIR /app
|
| 15 |
+
|
| 16 |
+
# Install Python dependencies
|
| 17 |
+
COPY requirements.txt .
|
| 18 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 19 |
+
|
| 20 |
+
# Copy app code
|
| 21 |
+
COPY app.py .
|
| 22 |
+
|
| 23 |
+
# Expose port
|
| 24 |
+
EXPOSE 7860
|
| 25 |
+
|
| 26 |
+
# Start FastAPI server
|
| 27 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, UploadFile, Form
|
| 2 |
+
from fastapi.responses import FileResponse
|
| 3 |
+
import uuid, os, soundfile as sf
|
| 4 |
+
from TTS.api import TTS
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
# Load XTTS model (multi-lingual, multi-speaker)
|
| 9 |
+
# This will be slow on cold start but stays cached in memory
|
| 10 |
+
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda")
|
| 11 |
+
|
| 12 |
+
@app.post("/generate")
|
| 13 |
+
async def generate(text: str = Form(...), speaker_wav: UploadFile = None):
|
| 14 |
+
output_path = f"/tmp/{uuid.uuid4().hex}.wav"
|
| 15 |
+
|
| 16 |
+
if speaker_wav:
|
| 17 |
+
wav_path = f"/tmp/{speaker_wav.filename}"
|
| 18 |
+
with open(wav_path, "wb") as f:
|
| 19 |
+
f.write(await speaker_wav.read())
|
| 20 |
+
tts.tts_to_file(text=text, speaker_wav=wav_path, file_path=output_path)
|
| 21 |
+
else:
|
| 22 |
+
tts.tts_to_file(text=text, speaker="random", file_path=output_path)
|
| 23 |
+
|
| 24 |
+
return FileResponse(output_path, media_type="audio/wav")
|
huggingface.yaml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hugging Face Inference Endpoint config
|
| 2 |
+
build:
|
| 3 |
+
dockerfile: Dockerfile
|
| 4 |
+
|
| 5 |
+
resources:
|
| 6 |
+
# Use CPU instance for free/low-cost deployment
|
| 7 |
+
cpu: "2"
|
| 8 |
+
memory: "8Gi"
|
| 9 |
+
|
| 10 |
+
scaling:
|
| 11 |
+
# Scale-to-zero when idle → no charges while unused
|
| 12 |
+
min_replicas: 0
|
| 13 |
+
max_replicas: 1
|
| 14 |
+
|
| 15 |
+
entrypoint: uvicorn app:app --host 0.0.0.0 --port 7860
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
soundfile
|
| 4 |
+
numpy
|
| 5 |
+
torch
|
| 6 |
+
torchaudio
|
| 7 |
+
transformers
|
| 8 |
+
TTS==0.21.1
|