-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom_types.py
More file actions
30 lines (21 loc) · 933 Bytes
/
custom_types.py
File metadata and controls
30 lines (21 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from __future__ import annotations
from typing import Literal
from pydantic import BaseModel, Field, model_validator
class PlateBBox(BaseModel):
x1: float = Field(..., description="Left coordinate.")
y1: float = Field(..., description="Top coordinate.")
x2: float = Field(..., description="Right coordinate.")
y2: float = Field(..., description="Bottom coordinate.")
@model_validator(mode="after")
def validate_bounds(self):
if min(self.x1, self.y1, self.x2, self.y2) < 0:
raise ValueError("Bounding box coordinates must be non-negative")
if self.x2 <= self.x1 or self.y2 <= self.y1:
raise ValueError("Bounding box coordinates are invalid")
return self
class PlateResult(BaseModel):
status: Literal["success", "not_found"]
plate_text: str
confidence: float = Field(ge=0.0, le=1.0)
bbox: PlateBBox
__all__ = ["PlateBBox", "PlateResult"]