Spaces:
Sleeping
Sleeping
| # api/main.py | |
| import os | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.staticfiles import StaticFiles | |
| from fastapi.responses import FileResponse | |
| from slowapi import Limiter, _rate_limit_exceeded_handler | |
| from slowapi.util import get_remote_address | |
| from slowapi.errors import RateLimitExceeded | |
| from api.routes.query import router as query_router | |
| from api.routes.health import router as health_router | |
| from api.startup_checks import validate_secrets | |
| validate_secrets() | |
| limiter = Limiter(key_func=get_remote_address) | |
| app = FastAPI( | |
| title="SchemeSaathi API", | |
| description="Agentic RAG over 3400 Indian government welfare schemes", | |
| version="1.0.0", | |
| ) | |
| app.state.limiter = limiter | |
| app.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| app.include_router(health_router) | |
| app.include_router(query_router) | |
| # Serve frontend | |
| FRONTEND_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), "frontend") | |
| if os.path.exists(FRONTEND_DIR): | |
| app.mount("/static", StaticFiles(directory=FRONTEND_DIR), name="static") | |
| async def root(): | |
| return FileResponse(os.path.join(FRONTEND_DIR, "index.html")) | |