push
Browse files- Dockerfile +2 -5
- main.py +24 -11
Dockerfile
CHANGED
|
@@ -55,11 +55,8 @@ RUN mkdir -p /models/huggingface && \
|
|
| 55 |
mkdir -p /code/models && \
|
| 56 |
chmod -R 777 /models/huggingface
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
# Preload tokenizer (avoid runtime delays)
|
| 62 |
-
RUN python -c "from transformers import AutoTokenizer; AutoTokenizer.from_pretrained('saheedniyi/YarnGPT2', use_fast=True)"
|
| 63 |
|
| 64 |
# Download wavtokenizer configuration file (to both root and models directory)
|
| 65 |
RUN wget -O /code/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml \
|
|
|
|
| 55 |
mkdir -p /code/models && \
|
| 56 |
chmod -R 777 /models/huggingface
|
| 57 |
|
| 58 |
+
# Note: Models will be downloaded lazily at runtime to save build storage
|
| 59 |
+
# Pre-downloading is disabled to avoid storage limit issues
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
# Download wavtokenizer configuration file (to both root and models directory)
|
| 62 |
RUN wget -O /code/wavtokenizer_mediumdata_frame75_3s_nq1_code4096_dim512_kmeans200_attn.yaml \
|
main.py
CHANGED
|
@@ -172,15 +172,10 @@ def load_model():
|
|
| 172 |
|
| 173 |
@app.on_event("startup")
|
| 174 |
async def startup_event():
|
| 175 |
-
"""Initialize model and tokenizer
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
load_audio_tokenizer()
|
| 180 |
-
logger.info("Model initialization complete")
|
| 181 |
-
except Exception as e:
|
| 182 |
-
logger.error(f"Failed to initialize model: {e}")
|
| 183 |
-
logger.warning("Server will start but TTS functionality will be unavailable")
|
| 184 |
|
| 185 |
@app.get("/")
|
| 186 |
async def root():
|
|
@@ -224,10 +219,19 @@ async def text_to_speech(request: TTSRequest):
|
|
| 224 |
Returns:
|
| 225 |
- Audio file in WAV format
|
| 226 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 227 |
if model is None or audio_tokenizer is None:
|
| 228 |
raise HTTPException(
|
| 229 |
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
| 230 |
-
detail="Model
|
| 231 |
)
|
| 232 |
|
| 233 |
try:
|
|
@@ -280,10 +284,19 @@ async def text_to_speech_stream(request: TTSRequest):
|
|
| 280 |
|
| 281 |
Same parameters as /tts endpoint.
|
| 282 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
if model is None or audio_tokenizer is None:
|
| 284 |
raise HTTPException(
|
| 285 |
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
| 286 |
-
detail="Model
|
| 287 |
)
|
| 288 |
|
| 289 |
try:
|
|
|
|
| 172 |
|
| 173 |
@app.on_event("startup")
|
| 174 |
async def startup_event():
|
| 175 |
+
"""Initialize model and tokenizer lazily."""
|
| 176 |
+
logger.info("Server started. Models will be loaded on first request.")
|
| 177 |
+
# Don't load models at startup to save storage and startup time
|
| 178 |
+
# Models will be loaded lazily when first API call is made
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
@app.get("/")
|
| 181 |
async def root():
|
|
|
|
| 219 |
Returns:
|
| 220 |
- Audio file in WAV format
|
| 221 |
"""
|
| 222 |
+
# Lazy load models on first request
|
| 223 |
+
global model, audio_tokenizer
|
| 224 |
+
if model is None:
|
| 225 |
+
logger.info("Loading YarnGPT2 model (lazy loading)...")
|
| 226 |
+
load_model()
|
| 227 |
+
if audio_tokenizer is None:
|
| 228 |
+
logger.info("Loading audio tokenizer (lazy loading)...")
|
| 229 |
+
load_audio_tokenizer()
|
| 230 |
+
|
| 231 |
if model is None or audio_tokenizer is None:
|
| 232 |
raise HTTPException(
|
| 233 |
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
| 234 |
+
detail="Model loading failed. Please check logs."
|
| 235 |
)
|
| 236 |
|
| 237 |
try:
|
|
|
|
| 284 |
|
| 285 |
Same parameters as /tts endpoint.
|
| 286 |
"""
|
| 287 |
+
# Lazy load models on first request
|
| 288 |
+
global model, audio_tokenizer
|
| 289 |
+
if model is None:
|
| 290 |
+
logger.info("Loading YarnGPT2 model (lazy loading)...")
|
| 291 |
+
load_model()
|
| 292 |
+
if audio_tokenizer is None:
|
| 293 |
+
logger.info("Loading audio tokenizer (lazy loading)...")
|
| 294 |
+
load_audio_tokenizer()
|
| 295 |
+
|
| 296 |
if model is None or audio_tokenizer is None:
|
| 297 |
raise HTTPException(
|
| 298 |
status_code=status.HTTP_503_SERVICE_UNAVAILABLE,
|
| 299 |
+
detail="Model loading failed. Please check logs."
|
| 300 |
)
|
| 301 |
|
| 302 |
try:
|