yukee1992 commited on
Commit
cb3e149
Β·
verified Β·
1 Parent(s): 89a41da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -4
app.py CHANGED
@@ -58,6 +58,14 @@ print("πŸ“ Models will load on first request (lazy loading)")
58
  print("⏰ Startup time:", app_startup_time.isoformat())
59
  print("=" * 50)
60
 
 
 
 
 
 
 
 
 
61
  # Pydantic models
62
  class TTSRequest(BaseModel):
63
  text: str
@@ -215,12 +223,14 @@ def load_tts_model(voice_style="default_female"):
215
  # Health check endpoints
216
  @app.get("/")
217
  async def root():
218
- """Root endpoint"""
219
  return {
220
- "status": "running",
221
  "service": "TTS API",
222
- "message": "Visit /docs for API documentation",
223
- "model_loaded": model_loaded
 
 
224
  }
225
 
226
  @app.get("/health")
@@ -243,6 +253,21 @@ async def api_health_check():
243
  "device": DEVICE
244
  }
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  # API endpoints
247
  @app.post("/api/tts")
248
  async def generate_tts(request: TTSRequest):
 
58
  print("⏰ Startup time:", app_startup_time.isoformat())
59
  print("=" * 50)
60
 
61
+ # Add startup event
62
+ @app.on_event("startup")
63
+ async def startup_event():
64
+ """Run on application startup"""
65
+ print("βœ… TTS API Startup Completed Successfully!")
66
+ print("🌐 Server is running on http://0.0.0.0:8000")
67
+ print("πŸ“š API Documentation available at: http://0.0.0.0:8000/docs")
68
+
69
  # Pydantic models
70
  class TTSRequest(BaseModel):
71
  text: str
 
223
  # Health check endpoints
224
  @app.get("/")
225
  async def root():
226
+ """Root endpoint with detailed health info"""
227
  return {
228
+ "status": "healthy",
229
  "service": "TTS API",
230
+ "message": "API is running successfully",
231
+ "model_loaded": model_loaded,
232
+ "device": DEVICE,
233
+ "timestamp": datetime.now().isoformat()
234
  }
235
 
236
  @app.get("/health")
 
253
  "device": DEVICE
254
  }
255
 
256
+ # Hugging Face specific health checks
257
+ @app.get("/health-check")
258
+ async def huggingface_health_check():
259
+ """Specific health check for Hugging Face Spaces"""
260
+ return {
261
+ "status": "healthy",
262
+ "message": "TTS API is running",
263
+ "timestamp": datetime.now().isoformat()
264
+ }
265
+
266
+ @app.get("/ready")
267
+ async def ready_check():
268
+ """Simple readiness check"""
269
+ return {"status": "ready"}
270
+
271
  # API endpoints
272
  @app.post("/api/tts")
273
  async def generate_tts(request: TTSRequest):