| from fastapi import FastAPI |
| from fastapi.middleware.cors import CORSMiddleware |
| import uvicorn |
| from contextlib import asynccontextmanager |
|
|
| |
| from router import cnn_router |
|
|
| @asynccontextmanager |
| async def lifespan_manager(app: FastAPI): |
| """ |
| μλ² μμ μ λͺ¨λΈμ λ‘λνκ³ μ’
λ£ μ μ 리ν©λλ€. |
| """ |
| |
| await cnn_router.load_models() |
| |
| |
| yield |
| |
| |
| cnn_router.shutdown_models() |
|
|
| |
| app = FastAPI( |
| title="EfficientNetB0 μ΄λ―Έμ§ λΆλ₯ API", |
| description="Fine-tuned EfficientNetB0 λͺ¨λΈμ μ¬μ©νμ¬ μ΄λ―Έμ§λ₯Ό μμΈ‘ν©λλ€.", |
| lifespan=lifespan_manager |
| ) |
|
|
| |
| app.add_middleware( |
| CORSMiddleware, |
| allow_origins=["*"], |
| allow_credentials=True, |
| allow_methods=["*"], |
| allow_headers=["*"], |
| ) |
|
|
| |
| app.include_router(cnn_router.router) |
|
|
| |
| @app.get("/", summary="API ν¬μ€ 체ν¬") |
| def read_root(): |
| """API μλ²κ° μ μμ μΌλ‘ μλνλμ§ νμΈν©λλ€.""" |
| return {"message": "EfficientNetB0 Classification API is running successfully."} |
|
|
| if __name__ == "__main__": |
| |
| uvicorn.run("app:app", host="0.0.0.0", port=8000, reload=True) |
|
|