Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI, APIRouter | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from src.apis.routes.user_route import router as router_user | |
| from src.apis.routes.chat_route import router as router_chat | |
| from src.apis.routes.lesson_route import router as router_lesson | |
| from src.apis.routes.evaluation_route import router as router_evaluation | |
| from src.apis.routes.pronunciation_route import router as router_pronunciation | |
| from src.apis.routes.speaking_route import router as router_speaking | |
| from src.apis.routes.ipa_route import router as router_ipa | |
| from loguru import logger | |
| api_router = APIRouter(prefix="/api") | |
| api_router.include_router(router_user) | |
| api_router.include_router(router_chat) | |
| api_router.include_router(router_lesson) | |
| api_router.include_router(router_evaluation) | |
| api_router.include_router(router_pronunciation) | |
| api_router.include_router(router_speaking) | |
| api_router.include_router(router_ipa) | |
| def create_app(): | |
| app = FastAPI(docs_url="/", title="API") | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| async def startup_event(): | |
| """Pre-initialize assessor on server startup for better performance""" | |
| try: | |
| logger.info("Pre-initializing ProductionPronunciationAssessor...") | |
| from src.apis.routes.speaking_route import get_assessor | |
| from src.apis.routes.ipa_route import get_assessor as get_ipa_assessor | |
| # Pre-initialize both assessors (they share the same singleton) | |
| get_assessor() | |
| get_ipa_assessor() | |
| logger.info("ProductionPronunciationAssessor pre-initialization completed!") | |
| except Exception as e: | |
| logger.error(f"Failed to pre-initialize assessor: {e}") | |
| return app | |