-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (50 loc) · 1.91 KB
/
main.py
File metadata and controls
70 lines (50 loc) · 1.91 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
60
61
62
63
64
65
66
67
68
69
70
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from app.api.router import api_router
from app.api.routes import pages
from app.core.config import settings
from app.db.base import Base
from app.db.session import engine
# Import models to register them with SQLAlchemy
from app.models import User, Image, Comparison, FindingComparisonDB # noqa: F401
logger = logging.getLogger(__name__)
@asynccontextmanager
async def lifespan(app: FastAPI):
"""Application lifespan handler for startup/shutdown events."""
# Startup
logger.info("Starting up MedDaaS API...")
# Create database tables if they don't exist
try:
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
logger.info("Database tables created/verified successfully")
except Exception as e:
logger.warning(f"Could not create database tables: {e}")
logger.info("Continuing without database - using in-memory storage")
yield
# Shutdown
logger.info("Shutting down MedDaaS API...")
await engine.dispose()
app = FastAPI(
title=settings.PROJECT_NAME,
version=settings.VERSION,
openapi_url=f"{settings.API_V1_PREFIX}/openapi.json",
lifespan=lifespan,
)
# Mount static files (CSS, JS)
app.mount("/static", StaticFiles(directory="app/static"), name="static")
# Mount medical images from data directory
app.mount("/images", StaticFiles(directory="data/images"), name="images")
# Include frontend page routes (at root level)
app.include_router(pages.router, tags=["pages"])
# Include API routes
app.include_router(api_router, prefix=settings.API_V1_PREFIX)
@app.get("/health")
async def health_check():
"""Health check endpoint."""
return {"status": "healthy"}
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True)