curemind / server /main.py
Alishba Siddique
feat: production deployment setup for HF Spaces
e2640ca
Raw
History Blame Contribute Delete
1.35 kB
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from core.schemas import HealthResponse
from logger import logger
from middlewares.exception_handlers import catch_exception_middleware
from routes.ask_question import router as ask_router
from routes.load_hf_datasets import router as hf_router
from routes.upload_pdfs import router as upload_router
@asynccontextmanager
async def lifespan(app: FastAPI):
logger.info("CureMind API starting")
yield
logger.info("CureMind API stopped")
app = FastAPI(
title="CureMind API",
description=(
"AI-powered medical information assistant. "
"Combines Retrieval-Augmented Generation with curated medical datasets "
"(PubMedQA, USMLE, mental health) and user-uploaded documents."
),
version="1.0.0",
lifespan=lifespan,
)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
app.middleware("http")(catch_exception_middleware)
@app.get("/health", response_model=HealthResponse, tags=["System"])
async def health_check():
return HealthResponse(status="healthy")
app.include_router(upload_router, tags=["Documents"])
app.include_router(ask_router, tags=["Chat"])
app.include_router(hf_router, tags=["Datasets"])