File size: 1,161 Bytes
575d22a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""Minimal FastAPI bootstrap using lifespan for startup model load."""
from fastapi import FastAPI
from contextlib import asynccontextmanager
import os
from app.routes import router, startup_load
from app import config


@asynccontextmanager
async def lifespan(app: FastAPI):  # type: ignore[override]
    # Startup
    try:
        startup_load()
    except Exception as e:
        # Allow continuation if configured; error surfaces via /health
        if not config.ALLOW_START_WITHOUT_MODEL:
            raise
        print(f"Startup load warning (continuing due to ALLOW_START_WITHOUT_MODEL): {e}")
    yield
    # Shutdown (no-op for now; placeholder for future resource cleanup)


app = FastAPI(title="Hotel Cancellation Prediction API", version=config.APP_VERSION, lifespan=lifespan)

@app.get("/", response_model=dict)
async def root():
    return {"message": "Hotel Cancellation Prediction API", "version": config.APP_VERSION, "endpoints": {"health": "/health", "predict": "/predict", "docs": "/docs"}}

app.include_router(router)

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", "8000")))