Spaces:
Runtime error
Runtime error
Download app/main.py from devmurtaza/RastaAI: direct link, hf CLI and curl.
- Browser
- Download file 1.6 kB
-
https://huggingface.co/spaces/devmurtaza/RastaAI/resolve/main/app/main.py
- Command line
-
hf download hf://spaces/devmurtaza/RastaAI/app/main.py
-
curl -L -o main.py https://huggingface.co/spaces/devmurtaza/RastaAI/resolve/main/app/main.py
1.6 kB
| """FastAPI application entrypoint.""" | |
| from __future__ import annotations | |
| import asyncio | |
| from contextlib import asynccontextmanager | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from app.config import settings | |
| from app.database import init_db | |
| from app.utils.logger import logger | |
| from app.api import health, routes, training, feedback, cities | |
| from app.services.scheduler import retraining_loop | |
| async def lifespan(app: FastAPI): | |
| logger.info(f"Starting RastaAI backend (env={settings.app_env})") | |
| try: | |
| await init_db() | |
| except Exception as e: | |
| logger.warning(f"DB init failed (continuing): {e}") | |
| task = asyncio.create_task(retraining_loop()) | |
| yield | |
| task.cancel() | |
| logger.info("Shutting down RastaAI backend") | |
| app = FastAPI( | |
| title="RastaAI Route Intelligence API", | |
| description="AI-powered route prediction & ranking for Pakistan.", | |
| version="0.1.0", | |
| lifespan=lifespan, | |
| ) | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=settings.cors_origins, | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| prefix = settings.api_v1_prefix | |
| app.include_router(health.router, prefix=prefix) | |
| app.include_router(routes.router, prefix=prefix) | |
| app.include_router(training.router, prefix=prefix) | |
| app.include_router(feedback.router, prefix=prefix) | |
| app.include_router(cities.router, prefix=prefix) | |
| async def root() -> dict: | |
| return { | |
| "service": "RastaAI", | |
| "version": "0.1.0", | |
| "docs": "/docs", | |
| "health": f"{prefix}/health", | |
| } | |