main.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. import logging
  3. import uvicorn
  4. from fastapi import FastAPI
  5. from app.api.errors.iot import MissingIOTDataError, missing_data_exception_handler
  6. from app.api.routers import (
  7. algorithms,
  8. targets,
  9. space,
  10. bluetooth,
  11. devices,
  12. nlp,
  13. positioning,
  14. )
  15. from app.api.routers.model_path import early_start
  16. from app.core.config import settings
  17. from app.core.events import create_start_app_handler
  18. from app.core.logger import InterceptHandler
  19. from app.db.session import Base, engine
  20. Base.metadata.create_all(bind=engine)
  21. logging.getLogger().handlers = [InterceptHandler()]
  22. def get_application() -> FastAPI:
  23. application = FastAPI(title=settings.PROJECT_NAME)
  24. application.add_event_handler("startup", create_start_app_handler())
  25. application.include_router(algorithms.router, prefix="/algo", tags=["Algorithms"])
  26. application.include_router(bluetooth.router, prefix="/bluetooth", tags=["BLE"])
  27. application.include_router(devices.router, prefix="/devices", tags=["Devices"])
  28. application.include_router(early_start.router, prefix="/model-path", tags=["Model Path"])
  29. application.include_router(nlp.router, prefix="/nlp-service", tags=["NLP"])
  30. application.include_router(positioning.router, prefix="/positioning-service", tags=["Positioning Service"])
  31. application.include_router(space.router, prefix="/room", tags=["Spaces"])
  32. application.include_router(targets.router, prefix="/target", tags=["Targets"])
  33. application.add_exception_handler(MissingIOTDataError, missing_data_exception_handler)
  34. return application
  35. app = get_application()
  36. if __name__ == "__main__":
  37. uvicorn.run(app, host="0.0.0.0", port=8000)