Spaces:
Runtime error
Runtime error
Calvin commited on
Commit ·
0cf41d1
1
Parent(s): 4f81e42
change model
Browse files- app.py +1 -7
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -4,13 +4,12 @@ import torch
|
|
| 4 |
import aiofiles
|
| 5 |
import uvicorn
|
| 6 |
import os
|
| 7 |
-
import time
|
| 8 |
import soundfile as sf
|
| 9 |
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
# Load model once at startup
|
| 13 |
-
model_name = "
|
| 14 |
model = VitsModel.from_pretrained(model_name)
|
| 15 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 16 |
|
|
@@ -41,24 +40,19 @@ async def root():
|
|
| 41 |
@app.post("/tts")
|
| 42 |
async def text_to_speech(payload: dict):
|
| 43 |
text = payload.get("text", "")
|
| 44 |
-
lang = payload.get("lang", "id") # Ignored here, since model is Indonesian only
|
| 45 |
-
slow = payload.get("slow", False) # Also ignored
|
| 46 |
|
| 47 |
if not text:
|
| 48 |
return {"error": "Text is required"}
|
| 49 |
|
| 50 |
-
# Save audio file as WAV
|
| 51 |
file_path = "output.wav"
|
| 52 |
inputs = tokenizer(text, return_tensors="pt")
|
| 53 |
with torch.no_grad():
|
| 54 |
output = model(**inputs).waveform
|
| 55 |
sf.write(file_path, output.squeeze().cpu().numpy(), model.config.sampling_rate)
|
| 56 |
|
| 57 |
-
# Read audio for size
|
| 58 |
async with aiofiles.open(file_path, mode="rb") as f:
|
| 59 |
audio_data = await f.read()
|
| 60 |
|
| 61 |
-
# Build JSON response with download link
|
| 62 |
return {
|
| 63 |
"script": text,
|
| 64 |
"timestamps": generate_timestamps(text),
|
|
|
|
| 4 |
import aiofiles
|
| 5 |
import uvicorn
|
| 6 |
import os
|
|
|
|
| 7 |
import soundfile as sf
|
| 8 |
|
| 9 |
app = FastAPI()
|
| 10 |
|
| 11 |
# Load model once at startup
|
| 12 |
+
model_name = "Ellbendls/csm-1b-indonesian-fine-tuned"
|
| 13 |
model = VitsModel.from_pretrained(model_name)
|
| 14 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 15 |
|
|
|
|
| 40 |
@app.post("/tts")
|
| 41 |
async def text_to_speech(payload: dict):
|
| 42 |
text = payload.get("text", "")
|
|
|
|
|
|
|
| 43 |
|
| 44 |
if not text:
|
| 45 |
return {"error": "Text is required"}
|
| 46 |
|
|
|
|
| 47 |
file_path = "output.wav"
|
| 48 |
inputs = tokenizer(text, return_tensors="pt")
|
| 49 |
with torch.no_grad():
|
| 50 |
output = model(**inputs).waveform
|
| 51 |
sf.write(file_path, output.squeeze().cpu().numpy(), model.config.sampling_rate)
|
| 52 |
|
|
|
|
| 53 |
async with aiofiles.open(file_path, mode="rb") as f:
|
| 54 |
audio_data = await f.read()
|
| 55 |
|
|
|
|
| 56 |
return {
|
| 57 |
"script": text,
|
| 58 |
"timestamps": generate_timestamps(text),
|
requirements.txt
CHANGED
|
@@ -5,4 +5,5 @@ pydantic
|
|
| 5 |
transformers
|
| 6 |
torch
|
| 7 |
torchaudio
|
| 8 |
-
soundfile
|
|
|
|
|
|
| 5 |
transformers
|
| 6 |
torch
|
| 7 |
torchaudio
|
| 8 |
+
soundfile
|
| 9 |
+
sentencepiece
|