prshntdxt commited on
Commit
831da65
·
verified ·
1 Parent(s): 4855bb3

Update schemas.py

Browse files
Files changed (1) hide show
  1. schemas.py +54 -24
schemas.py CHANGED
@@ -1,41 +1,71 @@
1
  from pydantic import BaseModel
2
- from typing import Dict, List, Optional, Union
 
 
 
 
3
 
4
  class PredictRequest(BaseModel):
5
  """
6
- Forest segmentation prediction request
7
-
8
- Supports Landsat 8 Collection 2 Level 2 data format.
9
- Each band can be provided as:
10
- - Base64-encoded float32 data (for remote API calls)
11
- - Array/list format (for direct server calls)
12
-
13
- Required bands:
14
- - Blue, Green, Red: Optical bands
15
- - NIR, SWIR1, SWIR2: Infrared bands
16
- - NDVI, NDWI, NBR: Spectral indices (or server will compute them)
17
-
18
- Optional special keys:
19
- - _invert_mask: Set to true to invert forest/non-forest in response
20
-
21
- Value range expectations:
22
- - Optical bands: [-0.2, 0.6]
23
- - Indices: [-1, 1]
24
  """
 
25
  model_name: str = "forest_segmentation"
26
  model_version: str = "landsat8_v1"
27
- bands: Dict[str, Union[str, List, int]] # Band data as base64 or array
28
 
 
 
 
 
 
 
 
 
 
29
 
30
- from typing import List, Dict, Any, Optional
31
- from pydantic import BaseModel
 
 
32
 
33
  class PredictResponse(BaseModel):
34
- mask: List[int] # 1D flat list ✓
35
- inverted_mask: List[int] # 1D flat list ✓
 
 
 
 
 
 
 
 
 
 
 
36
  forest_percentage: float
37
  forest_confidence: float
38
  mean_prediction: float
 
 
39
  classes: Dict[str, int]
 
 
40
  model_info: Dict[str, Any]
 
 
41
  debug: Optional[Dict[str, Any]] = None
 
1
  from pydantic import BaseModel
2
+ from typing import Dict, List, Optional, Union, Any
3
+
4
+ # =============================================================================
5
+ # REQUEST SCHEMA
6
+ # =============================================================================
7
 
8
  class PredictRequest(BaseModel):
9
  """
10
+ Forest segmentation prediction request.
11
+
12
+ This schema is intentionally flexible to support:
13
+ - Supabase Edge Functions
14
+ - Hugging Face remote inference
15
+ - Local inference scripts
16
+
17
+ Required:
18
+ - bands: Dict[str, Union[str, List[float]]]
19
+
20
+ Allowed extra fields (sent by Supabase):
21
+ - width, height
22
+ - bbox
23
+ - band_names
24
+ - preprocessing
25
+ - model_name, model_version
 
 
26
  """
27
+
28
  model_name: str = "forest_segmentation"
29
  model_version: str = "landsat8_v1"
 
30
 
31
+ # Band data:
32
+ # - base64-encoded float32 (remote calls)
33
+ # - list/array of floats (local calls)
34
+ bands: Dict[str, Union[str, List[float]]]
35
+
36
+ class Config:
37
+ # 🔑 CRITICAL FIX
38
+ # Allows Supabase to send extra metadata without 422 errors
39
+ extra = "allow"
40
 
41
+
42
+ # =============================================================================
43
+ # RESPONSE SCHEMA
44
+ # =============================================================================
45
 
46
  class PredictResponse(BaseModel):
47
+ """
48
+ Forest segmentation prediction response.
49
+
50
+ Mask values are CONTINUOUS (0–255) — NOT binary.
51
+ """
52
+
53
+ # Flattened mask (length = width * height)
54
+ mask: List[int]
55
+
56
+ # Inverted mask (optional utility)
57
+ inverted_mask: List[int]
58
+
59
+ # Statistics
60
  forest_percentage: float
61
  forest_confidence: float
62
  mean_prediction: float
63
+
64
+ # Class mapping
65
  classes: Dict[str, int]
66
+
67
+ # Model metadata
68
  model_info: Dict[str, Any]
69
+
70
+ # Optional debug block
71
  debug: Optional[Dict[str, Any]] = None