from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from src.api.ocr import router as ocr_router from src.core.config import settings app = FastAPI( title=settings.app_name, version=settings.app_version, debug=settings.debug ) # CORS middleware app.add_middleware( CORSMiddleware, allow_origins=["*"] if settings.debug else [], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) # 注册 OCR 路由 app.include_router(ocr_router) @app.get("/") async def root(): return { "app": settings.app_name, "version": settings.app_version, "status": "running", "model": settings.model_path } @app.get("/health") async def health_check(): return {"status": "healthy"} if __name__ == "__main__": import uvicorn uvicorn.run( "src.main:app", host=settings.host, port=settings.port, reload=settings.debug )