schemas.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. from enum import Enum
  2. from pydantic import BaseModel
  3. def to_lower_camel(string: str) -> str:
  4. tokens = [
  5. token.capitalize() if i > 0 else token
  6. for i, token in enumerate(string.split("_"))
  7. ]
  8. return "".join(tokens)
  9. class TextModelRequest(BaseModel):
  10. text: str
  11. class TextResponse(BaseModel):
  12. __root__: str
  13. class MessageResponse(BaseModel):
  14. message: str
  15. class TagResponse(BaseModel):
  16. __root__: list[str]
  17. class Embedding(BaseModel):
  18. __root__: list[float]
  19. class EmbeddingResponse(BaseModel):
  20. __root__: Embedding
  21. class BoundingBox(BaseModel):
  22. x1: int
  23. y1: int
  24. x2: int
  25. y2: int
  26. class Face(BaseModel):
  27. image_width: int
  28. image_height: int
  29. bounding_box: BoundingBox
  30. score: float
  31. embedding: Embedding
  32. class Config:
  33. alias_generator = to_lower_camel
  34. allow_population_by_field_name = True
  35. class FaceResponse(BaseModel):
  36. __root__: list[Face]
  37. class ModelType(Enum):
  38. IMAGE_CLASSIFICATION = "image-classification"
  39. CLIP = "clip"
  40. CLIP_VISION = "clip-vision"
  41. CLIP_TEXT = "clip-text"
  42. FACIAL_RECOGNITION = "facial-recognition"