-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
59 lines (42 loc) · 1.5 KB
/
main.py
File metadata and controls
59 lines (42 loc) · 1.5 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from contextlib import asynccontextmanager
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.staticfiles import StaticFiles
from app.agent import agent
from app.endpoints import nutrition, chat
from app.utils.envManager import get_env_variable_safe
from app.middleware.exception_handlers import setup_exception_handlers
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Lifespan context manager for FastAPI app."""
yield
isProd = get_env_variable_safe("PROD", "false").lower() == "true"
app = FastAPI(
title="NomAI Nutrition API",
description="AI-powered nutrition analysis API with chat functionality",
version="1.0.0",
debug=not isProd,
lifespan=lifespan,
)
app = setup_exception_handlers(app)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(nutrition.router, prefix="/nutrition")
app.include_router(chat.router, prefix="/user")
app.include_router(agent.router, prefix="/chat")
app.mount("/static", StaticFiles(directory="app/static"), name="static")
@app.get("/")
async def root():
"""Serve the chat HTML page."""
from fastapi.responses import FileResponse
return FileResponse("app/static/chat_app.html")
if __name__ == "__main__":
host = get_env_variable_safe("HOST", "0.0.0.0")
port = int(get_env_variable_safe("PORT", "8000"))
uvicorn.run(app, host=host, port=port, reload=not isProd)