main.py 1.8 KB

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