Commit ·
49ee1a8
1
Parent(s): 2aedd24
created /health route
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
from fastapi import FastAPI, UploadFile, Form
|
| 2 |
from fastapi.responses import FileResponse
|
| 3 |
-
import uuid
|
|
|
|
|
|
|
| 4 |
from TTS.api import TTS
|
| 5 |
|
| 6 |
app = FastAPI()
|
|
@@ -9,10 +11,11 @@ app = FastAPI()
|
|
| 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:
|
|
@@ -22,3 +25,8 @@ async def generate(text: str = Form(...), speaker_wav: UploadFile = None):
|
|
| 22 |
tts.tts_to_file(text=text, speaker="random", file_path=output_path)
|
| 23 |
|
| 24 |
return FileResponse(output_path, media_type="audio/wav")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, UploadFile, Form
|
| 2 |
from fastapi.responses import FileResponse
|
| 3 |
+
import uuid
|
| 4 |
+
import os
|
| 5 |
+
import soundfile as sf
|
| 6 |
from TTS.api import TTS
|
| 7 |
|
| 8 |
app = FastAPI()
|
|
|
|
| 11 |
# This will be slow on cold start but stays cached in memory
|
| 12 |
tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2").to("cuda")
|
| 13 |
|
| 14 |
+
|
| 15 |
@app.post("/generate")
|
| 16 |
async def generate(text: str = Form(...), speaker_wav: UploadFile = None):
|
| 17 |
output_path = f"/tmp/{uuid.uuid4().hex}.wav"
|
| 18 |
+
|
| 19 |
if speaker_wav:
|
| 20 |
wav_path = f"/tmp/{speaker_wav.filename}"
|
| 21 |
with open(wav_path, "wb") as f:
|
|
|
|
| 25 |
tts.tts_to_file(text=text, speaker="random", file_path=output_path)
|
| 26 |
|
| 27 |
return FileResponse(output_path, media_type="audio/wav")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@app.get("/health")
|
| 31 |
+
def health():
|
| 32 |
+
return {"status": "ok"}
|