HashirAwaiz commited on
Commit
14bbdb2
·
verified ·
1 Parent(s): ce3d782

Upload schemas.py

Browse files
Files changed (1) hide show
  1. app/schemas.py +131 -0
app/schemas.py ADDED
@@ -0,0 +1,131 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseModel, ConfigDict
2
+ from typing import Dict
3
+
4
+ # Input Data Model
5
+ class WeatherInput(BaseModel):
6
+ tmmn: float # temp min (Kelvin)
7
+ tmmx: float # temp max (Kelvin)
8
+ rmin: float # humidity min (%)
9
+ rmax: float # humidity max (%)
10
+ vs: float # wind speed (m/s)
11
+ pr: float # precipitation (mm)
12
+ erc: float # energy release component
13
+ latitude: float
14
+ longitude: float
15
+
16
+ # Pydantic V2 Config
17
+ model_config = ConfigDict(
18
+ json_schema_extra={
19
+ "example": {
20
+ "tmmn": 290.5,
21
+ "tmmx": 305.2,
22
+ "rmin": 12.5,
23
+ "rmax": 45.0,
24
+ "vs": 5.4,
25
+ "pr": 0.0,
26
+ "erc": 48.0,
27
+ "latitude": 34.05,
28
+ "longitude": -118.25
29
+ }
30
+ }
31
+ )
32
+
33
+ # Output Data Model
34
+ class PredictionOutput(BaseModel):
35
+ burning_index_prediction: float
36
+ risk_level_prediction: str
37
+ cluster_zone: int
38
+ pca_x: float
39
+ pca_y: float
40
+ seasonal_trend: Dict[int, float] # Maps Month (1-12) to Avg Intensity
41
+
42
+ # Pydantic V2 Config with example
43
+ model_config = ConfigDict(
44
+ json_schema_extra={
45
+ "example": {
46
+ "burning_index_prediction": 65.8,
47
+ "risk_level_prediction": "Medium",
48
+ "cluster_zone": 2,
49
+ "pca_x": -1.25,
50
+ "pca_y": 0.83,
51
+ "seasonal_trend": {
52
+ 1: 42.3, 2: 44.1, 3: 47.8, 4: 52.4,
53
+ 5: 58.9, 6: 67.2, 7: 75.6, 8: 78.3,
54
+ 9: 71.8, 10: 62.4, 11: 51.2, 12: 45.7
55
+ }
56
+ }
57
+ }
58
+ )
59
+
60
+ # Optional: Model for PCA Projection endpoint
61
+ class PCAProjectionOutput(BaseModel):
62
+ pca_x: float
63
+ pca_y: float
64
+ explained_variance_ratio: list[float]
65
+
66
+ model_config = ConfigDict(
67
+ json_schema_extra={
68
+ "example": {
69
+ "pca_x": -1.25,
70
+ "pca_y": 0.83,
71
+ "explained_variance_ratio": [0.65, 0.25]
72
+ }
73
+ }
74
+ )
75
+
76
+ # Optional: Model for Seasonal Trend endpoint
77
+ class SeasonalTrendOutput(BaseModel):
78
+ description: str
79
+ trend: Dict[int, float]
80
+ units: str
81
+
82
+ model_config = ConfigDict(
83
+ json_schema_extra={
84
+ "example": {
85
+ "description": "Average Burning Index by Month",
86
+ "trend": {
87
+ 1: 42.3, 2: 44.1, 3: 47.8, 4: 52.4,
88
+ 5: 58.9, 6: 67.2, 7: 75.6, 8: 78.3,
89
+ 9: 71.8, 10: 62.4, 11: 51.2, 12: 45.7
90
+ },
91
+ "units": "Burning Index (BI)"
92
+ }
93
+ }
94
+ )
95
+
96
+ # Optional: Health check response model
97
+ class HealthResponse(BaseModel):
98
+ status: str
99
+ models_loaded: list[str] = []
100
+ missing: list[str] = []
101
+ detail: str = ""
102
+ version: str = ""
103
+
104
+ model_config = ConfigDict(
105
+ json_schema_extra={
106
+ "example": {
107
+ "status": "healthy",
108
+ "models_loaded": ["regression", "classification", "clustering", "encoder", "pca", "seasonality"],
109
+ "missing": [],
110
+ "detail": "",
111
+ "version": "1.1.0"
112
+ }
113
+ }
114
+ )
115
+
116
+ # Optional: Model info response model
117
+ class ModelInfo(BaseModel):
118
+ type: str
119
+ details: dict
120
+
121
+ model_config = ConfigDict(
122
+ json_schema_extra={
123
+ "example": {
124
+ "regression": {
125
+ "type": "RandomForest",
126
+ "n_estimators": 50,
127
+ "n_features": 7
128
+ }
129
+ }
130
+ }
131
+ )