main.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. import logging
  3. from pathlib import Path
  4. import uvicorn
  5. from fastapi import FastAPI
  6. from loguru import logger
  7. from app.api.routers import (
  8. algorithms,
  9. targets,
  10. space,
  11. bluetooth,
  12. devices,
  13. nlp,
  14. positioning,
  15. )
  16. from app.api.routers.model_path import early_start
  17. from app.core.config import settings
  18. from app.core.events import create_start_app_handler
  19. from app.core.logger import InterceptHandler
  20. from app.db.session import Base, engine
  21. Base.metadata.create_all(bind=engine)
  22. logging.getLogger().handlers = [InterceptHandler()]
  23. # logger.add(
  24. # Path(settings.LOGS_DIR, "env_fastapi.log"),
  25. # level="INFO",
  26. # rotation="00:00",
  27. # encoding="utf-8",
  28. # )
  29. def get_application() -> FastAPI:
  30. application = FastAPI(title=settings.PROJECT_NAME, root_path="/env-py")
  31. application.add_event_handler("startup", create_start_app_handler())
  32. application.include_router(algorithms.router, prefix="/algo", tags=["Algorithms"])
  33. application.include_router(bluetooth.router, prefix="/bluetooth", tags=["BLE"])
  34. application.include_router(devices.router, prefix="/devices", tags=["Devices"])
  35. application.include_router(
  36. early_start.router, prefix="/model-path", tags=["Model Path"]
  37. )
  38. application.include_router(nlp.router, prefix="/nlp-service", tags=["NLP"])
  39. application.include_router(
  40. positioning.router, prefix="/positioning-service", tags=["Positioning Service"]
  41. )
  42. application.include_router(space.router, prefix="/room", tags=["Spaces"])
  43. application.include_router(targets.router, prefix="/target", tags=["Targets"])
  44. return application
  45. app = get_application()
  46. if __name__ == "__main__":
  47. uvicorn.run(app, host="0.0.0.0", port=8000)