File size: 1,496 Bytes
6cc8ae1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
Pydantic schemas for prediction endpoints.
"""

from typing import Optional
from pydantic import BaseModel, Field


class PredictionItem(BaseModel):
    """Single prediction result."""
    breed: str = Field(..., description="Predicted breed name")
    confidence: float = Field(..., ge=0, le=1, description="Confidence score")


class BreedInfo(BaseModel):
    """Breed metadata for the predicted breed."""
    breed_name: str
    animal_type: str
    region: str
    avg_milk_liters_per_day: str
    lifespan_years: str
    primary_use: str
    description: str


class PredictResponse(BaseModel):
    """Full prediction response."""
    predicted_breed: str
    confidence: float = Field(..., ge=0, le=1)
    top_k: list[PredictionItem]
    breed_info: Optional[BreedInfo] = None
    model_version: str = "v1.0"
    inference_time_ms: float
    warning: Optional[str] = None


class PredictURLRequest(BaseModel):
    """Request body for URL-based prediction."""
    url: str = Field(..., description="URL of the image to classify")
    top_k: int = Field(default=3, ge=1, le=10, description="Number of top predictions")


class PredictBase64Request(BaseModel):
    """Request body for base64-based prediction."""
    image: str = Field(..., description="Base64-encoded image string")
    top_k: int = Field(default=3, ge=1, le=10, description="Number of top predictions")


class ErrorResponse(BaseModel):
    """Error response."""
    detail: str
    error_type: str = "prediction_error"