Spaces:
Sleeping
Sleeping
fix:
Browse files
main.py
CHANGED
|
@@ -9,6 +9,7 @@ from api.routers import health
|
|
| 9 |
from infra.logger_structlog import StructLogger
|
| 10 |
|
| 11 |
from contextlib import asynccontextmanager
|
|
|
|
| 12 |
import mlflow
|
| 13 |
import torch
|
| 14 |
import redis.asyncio as aioredis
|
|
@@ -17,13 +18,17 @@ import dagshub
|
|
| 17 |
from fastapi import FastAPI
|
| 18 |
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
@asynccontextmanager
|
| 21 |
async def lifespan(app: FastAPI):
|
| 22 |
"""
|
| 23 |
This is on_event("startup") new alternative, Make sure you load models here.
|
| 24 |
"""
|
| 25 |
|
| 26 |
-
settings = AppConfig()
|
| 27 |
logger = StructLogger(settings=settings)
|
| 28 |
# Using this way to can store data. it is acts as a dict which holds instances
|
| 29 |
app.state.logger = logger
|
|
@@ -34,13 +39,16 @@ async def lifespan(app: FastAPI):
|
|
| 34 |
# asyncio.create_task(log_system_metrics(logger, logger_interval_sec=settings.intervals.system_metrics_seconds))
|
| 35 |
|
| 36 |
detection_model_path = hf_fetch_model(
|
| 37 |
-
repo_id="Ultralytics/YOLO26",
|
|
|
|
|
|
|
| 38 |
)
|
| 39 |
app.state.detection_model = YOLO_Detector(detection_model_path)
|
| 40 |
|
| 41 |
depth_model_path = hf_fetch_model(
|
| 42 |
repo_id="depth-anything/Depth-Anything-V2-Small",
|
| 43 |
filename=settings.depth.model_name,
|
|
|
|
| 44 |
)
|
| 45 |
app.state.depth_model = DepthAnything(
|
| 46 |
encoder=settings.depth.encoder,
|
|
@@ -49,7 +57,9 @@ async def lifespan(app: FastAPI):
|
|
| 49 |
)
|
| 50 |
|
| 51 |
safety_detection_path = hf_fetch_model(
|
| 52 |
-
repo_id="e1250/safety_detection",
|
|
|
|
|
|
|
| 53 |
)
|
| 54 |
app.state.safety_detection_model = YOLO_Detector(safety_detection_path)
|
| 55 |
|
|
|
|
| 9 |
from infra.logger_structlog import StructLogger
|
| 10 |
|
| 11 |
from contextlib import asynccontextmanager
|
| 12 |
+
import os
|
| 13 |
import mlflow
|
| 14 |
import torch
|
| 15 |
import redis.asyncio as aioredis
|
|
|
|
| 18 |
from fastapi import FastAPI
|
| 19 |
|
| 20 |
|
| 21 |
+
settings = AppConfig()
|
| 22 |
+
if settings.dagshub_user_token:
|
| 23 |
+
os.environ["DAGSHUB_USER_TOKEN"] = settings.dagshub_user_token
|
| 24 |
+
|
| 25 |
+
|
| 26 |
@asynccontextmanager
|
| 27 |
async def lifespan(app: FastAPI):
|
| 28 |
"""
|
| 29 |
This is on_event("startup") new alternative, Make sure you load models here.
|
| 30 |
"""
|
| 31 |
|
|
|
|
| 32 |
logger = StructLogger(settings=settings)
|
| 33 |
# Using this way to can store data. it is acts as a dict which holds instances
|
| 34 |
app.state.logger = logger
|
|
|
|
| 39 |
# asyncio.create_task(log_system_metrics(logger, logger_interval_sec=settings.intervals.system_metrics_seconds))
|
| 40 |
|
| 41 |
detection_model_path = hf_fetch_model(
|
| 42 |
+
repo_id="Ultralytics/YOLO26",
|
| 43 |
+
filename=settings.yolo.model_name,
|
| 44 |
+
cache_dir=settings.hf_cache_dir,
|
| 45 |
)
|
| 46 |
app.state.detection_model = YOLO_Detector(detection_model_path)
|
| 47 |
|
| 48 |
depth_model_path = hf_fetch_model(
|
| 49 |
repo_id="depth-anything/Depth-Anything-V2-Small",
|
| 50 |
filename=settings.depth.model_name,
|
| 51 |
+
cache_dir=settings.hf_cache_dir,
|
| 52 |
)
|
| 53 |
app.state.depth_model = DepthAnything(
|
| 54 |
encoder=settings.depth.encoder,
|
|
|
|
| 57 |
)
|
| 58 |
|
| 59 |
safety_detection_path = hf_fetch_model(
|
| 60 |
+
repo_id="e1250/safety_detection",
|
| 61 |
+
filename=settings.security_detector.model_name,
|
| 62 |
+
cache_dir=settings.hf_cache_dir,
|
| 63 |
)
|
| 64 |
app.state.safety_detection_model = YOLO_Detector(safety_detection_path)
|
| 65 |
|