Spaces:
Sleeping
Sleeping
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.middleware.gzip import GZipMiddleware | |
| from core.db import db_handler | |
| from api import router_scam, router_currency, router_intel, router_citizen | |
| from contextlib import asynccontextmanager | |
| async def lifespan(app: FastAPI): | |
| # Startup | |
| await db_handler.connect() | |
| yield | |
| # Shutdown | |
| await db_handler.disconnect() | |
| app = FastAPI( | |
| title="JanRakshak ML Backend", | |
| description="Multi-stage machine learning backend using FastAPI deployed on Modal.", | |
| version="1.0.0", | |
| lifespan=lifespan | |
| ) | |
| # Compression configuration for large JSON payloads | |
| app.add_middleware(GZipMiddleware, minimum_size=1000) | |
| # CORS configuration | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], # Adjust in production | |
| allow_credentials=False, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # Include routers | |
| app.include_router(router_scam.router) | |
| app.include_router(router_currency.router) | |
| app.include_router(router_intel.router) | |
| app.include_router(router_citizen.router) | |
| async def root(): | |
| return {"message": "Welcome to JanRakshak ML Backend. APIs are under /api/v1"} | |