2023-08-29 15:58:00 +02:00
|
|
|
from enum import StrEnum
|
2023-11-13 18:18:46 +02:00
|
|
|
from typing import Any, Protocol, TypeAlias, TypedDict, TypeGuard
|
2023-06-25 05:18:09 +02:00
|
|
|
|
2023-10-31 12:02:04 +02:00
|
|
|
import numpy as np
|
2023-06-05 16:40:48 +02:00
|
|
|
from pydantic import BaseModel
|
|
|
|
|
2023-11-13 18:18:46 +02: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 16:40:48 +02:00
|
|
|
|
|
|
|
|
|
|
|
class TextResponse(BaseModel):
|
|
|
|
__root__: str
|
|
|
|
|
|
|
|
|
|
|
|
class MessageResponse(BaseModel):
|
|
|
|
message: str
|
|
|
|
|
|
|
|
|
2023-11-13 18:18:46 +02:00
|
|
|
class BoundingBox(TypedDict):
|
2023-06-05 16:40:48 +02:00
|
|
|
x1: int
|
|
|
|
y1: int
|
|
|
|
x2: int
|
|
|
|
y2: int
|
|
|
|
|
|
|
|
|
2023-08-29 15:58:00 +02:00
|
|
|
class ModelType(StrEnum):
|
2023-06-25 05:18:09 +02:00
|
|
|
IMAGE_CLASSIFICATION = "image-classification"
|
|
|
|
CLIP = "clip"
|
|
|
|
FACIAL_RECOGNITION = "facial-recognition"
|
2023-10-31 12:02:04 +02:00
|
|
|
|
|
|
|
|
2023-11-13 18:18:46 +02: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
|