mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 15:11:58 +00:00
20be42cec0
* chore(deps): update machine-learning * fix typing, use new lifespan syntax * wrap in try / finally * move log --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: mertalev <101130780+mertalev@users.noreply.github.com>
46 lines
953 B
Python
46 lines
953 B
Python
from enum import StrEnum
|
|
from typing import Any, Protocol, TypedDict, TypeGuard
|
|
|
|
import numpy as np
|
|
import numpy.typing as npt
|
|
from pydantic import BaseModel
|
|
|
|
|
|
class TextResponse(BaseModel):
|
|
__root__: str
|
|
|
|
|
|
class MessageResponse(BaseModel):
|
|
message: str
|
|
|
|
|
|
class BoundingBox(TypedDict):
|
|
x1: int
|
|
y1: int
|
|
x2: int
|
|
y2: int
|
|
|
|
|
|
class ModelType(StrEnum):
|
|
CLIP = "clip"
|
|
FACIAL_RECOGNITION = "facial-recognition"
|
|
|
|
|
|
class HasProfiling(Protocol):
|
|
profiling: dict[str, float]
|
|
|
|
|
|
class Face(TypedDict):
|
|
boundingBox: BoundingBox
|
|
embedding: npt.NDArray[np.float32]
|
|
imageWidth: int
|
|
imageHeight: int
|
|
score: float
|
|
|
|
|
|
def has_profiling(obj: Any) -> TypeGuard[HasProfiling]:
|
|
return hasattr(obj, "profiling") and isinstance(obj.profiling, dict)
|
|
|
|
|
|
def is_ndarray(obj: Any, dtype: "type[np._DTypeScalar_co]") -> "TypeGuard[npt.NDArray[np._DTypeScalar_co]]":
|
|
return isinstance(obj, np.ndarray) and obj.dtype == dtype
|