2023-08-29 13:58:00 +00:00
|
|
|
from enum import StrEnum
|
2023-11-13 16:18:46 +00:00
|
|
|
from typing import Any, Protocol, TypeAlias, TypedDict, TypeGuard
|
2023-06-25 03:18:09 +00:00
|
|
|
|
2023-10-31 10:02:04 +00:00
|
|
|
import numpy as np
|
2023-06-05 14:40:48 +00:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
2023-11-13 16:18:46 +00:00
|
|
|
ndarray_f32: TypeAlias = np.ndarray[int, np.dtype[np.float32]]
|
|
|
|
ndarray_i64: TypeAlias = np.ndarray[int, np.dtype[np.int64]]
|
|
|
|
ndarray_i32: TypeAlias = np.ndarray[int, np.dtype[np.int32]]
|
2023-06-05 14:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TextResponse(BaseModel):
|
|
|
|
__root__: str
|
|
|
|
|
|
|
|
|
|
|
|
class MessageResponse(BaseModel):
|
|
|
|
message: str
|
|
|
|
|
|
|
|
|
2023-11-13 16:18:46 +00:00
|
|
|
class BoundingBox(TypedDict):
|
2023-06-05 14:40:48 +00:00
|
|
|
x1: int
|
|
|
|
y1: int
|
|
|
|
x2: int
|
|
|
|
y2: int
|
|
|
|
|
|
|
|
|
2023-08-29 13:58:00 +00:00
|
|
|
class ModelType(StrEnum):
|
2023-06-25 03:18:09 +00:00
|
|
|
IMAGE_CLASSIFICATION = "image-classification"
|
|
|
|
CLIP = "clip"
|
|
|
|
FACIAL_RECOGNITION = "facial-recognition"
|
2023-10-31 10:02:04 +00:00
|
|
|
|
|
|
|
|
2023-11-13 16:18:46 +00:00
|
|
|
class HasProfiling(Protocol):
|
|
|
|
profiling: dict[str, float]
|
|
|
|
|
|
|
|
|
|
|
|
class Face(TypedDict):
|
|
|
|
boundingBox: BoundingBox
|
|
|
|
embedding: ndarray_f32
|
|
|
|
imageWidth: int
|
|
|
|
imageHeight: int
|
|
|
|
score: float
|
|
|
|
|
|
|
|
|
|
|
|
def has_profiling(obj: Any) -> TypeGuard[HasProfiling]:
|
|
|
|
return hasattr(obj, "profiling") and type(obj.profiling) == dict
|