|
|
from pydantic import BaseModel |
|
|
from typing import Dict, List, Optional, Union, Any |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PredictRequest(BaseModel): |
|
|
""" |
|
|
Forest segmentation prediction request. |
|
|
|
|
|
This schema is intentionally flexible to support: |
|
|
- Supabase Edge Functions |
|
|
- Hugging Face remote inference |
|
|
- Local inference scripts |
|
|
|
|
|
Required: |
|
|
- bands: Dict[str, Union[str, List[float]]] |
|
|
|
|
|
Allowed extra fields (sent by Supabase): |
|
|
- width, height |
|
|
- bbox |
|
|
- band_names |
|
|
- preprocessing |
|
|
- model_name, model_version |
|
|
""" |
|
|
|
|
|
model_name: str = "forest_segmentation" |
|
|
model_version: str = "landsat8_v1" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bands: Dict[str, Union[str, List[float]]] |
|
|
|
|
|
class Config: |
|
|
|
|
|
|
|
|
extra = "allow" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PredictResponse(BaseModel): |
|
|
""" |
|
|
Forest segmentation prediction response. |
|
|
|
|
|
Mask values are CONTINUOUS (0β255) β NOT binary. |
|
|
""" |
|
|
|
|
|
|
|
|
mask: List[int] |
|
|
|
|
|
|
|
|
inverted_mask: List[int] |
|
|
|
|
|
|
|
|
forest_percentage: float |
|
|
forest_confidence: float |
|
|
mean_prediction: float |
|
|
|
|
|
|
|
|
classes: Dict[str, int] |
|
|
|
|
|
|
|
|
model_info: Dict[str, Any] |
|
|
|
|
|
|
|
|
debug: Optional[Dict[str, Any]] = None |
|
|
|