| """ |
| Tibetan Learning Platform - FastAPI Backend |
| Main application entry point |
| """ |
|
|
| from fastapi import FastAPI |
| from fastapi.middleware.cors import CORSMiddleware |
| from contextlib import asynccontextmanager |
|
|
| from app.routers import tts, translate, learn |
|
|
|
|
| @asynccontextmanager |
| async def lifespan(app: FastAPI): |
| """Application lifespan events""" |
| |
| from app.services.tts_service import tts_service |
| print("π Loading TTS model...") |
| await tts_service.load_model() |
| print("β
TTS model loaded successfully!") |
| |
| yield |
| |
| |
| print("π Shutting down...") |
|
|
|
|
| app = FastAPI( |
| title="Tibetan Learning Platform API", |
| description="API for Tibetan TTS, Translation, and Learning features", |
| version="1.0.0", |
| lifespan=lifespan |
| ) |
|
|
| |
| app.add_middleware( |
| CORSMiddleware, |
| allow_origins=[ |
| "http://localhost:3000", |
| "http://127.0.0.1:3000", |
| "*", |
| ], |
| allow_credentials=True, |
| allow_methods=["*"], |
| allow_headers=["*"], |
| ) |
|
|
| |
| app.include_router(tts.router, prefix="/api/tts", tags=["TTS"]) |
| app.include_router(translate.router, prefix="/api/translate", tags=["Translation"]) |
| app.include_router(learn.router, prefix="/api/learn", tags=["Learning"]) |
|
|
|
|
| @app.get("/") |
| async def root(): |
| """Health check endpoint""" |
| return { |
| "status": "ok", |
| "message": "Tibetan Learning Platform API", |
| "version": "1.0.0" |
| } |
|
|
|
|
| @app.get("/api/health") |
| async def health_check(): |
| """Detailed health check""" |
| from app.services.tts_service import tts_service |
| return { |
| "status": "healthy", |
| "tts_model_loaded": tts_service.is_loaded(), |
| "device": tts_service.get_device() |
| } |
|
|
|
|
| if __name__ == "__main__": |
| import uvicorn |
| uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True) |
|
|