Mariamyasser commited on
Commit
4370a09
·
verified ·
1 Parent(s): a47f90b

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -53
app.py DELETED
@@ -1,53 +0,0 @@
1
- from fastapi import FastAPI
2
- from pydantic import BaseModel
3
- import pandas as pd
4
- import joblib
5
-
6
-
7
- # Load artifacts
8
- model = joblib.load("xgb_desertification_pipeline.pkl")
9
- label_encoder = joblib.load("label_encoder.pkl")
10
- expected_features = joblib.load("feature_names.pkl")
11
-
12
- app = FastAPI(title="Desertification Prediction API")
13
-
14
- class PredictionRequest(BaseModel):
15
- year: int
16
- month: int
17
- sand: float
18
- silt: float
19
- clay: float
20
- soc: float
21
- ph: float
22
- bdod: float
23
- cec: float
24
- ndvi: float
25
- t2m_c: float
26
- td2m_c: float
27
- rh_pct: float
28
- tp_m: float
29
- ssrd_jm2: float
30
- lc_type1: int
31
- nitrogen: float
32
- phosphorus: float
33
- potassium: float
34
- latitude: float
35
- longitude: float
36
-
37
- @app.post("/predict")
38
- def predict(request: PredictionRequest):
39
- data = request.dict()
40
-
41
- df = pd.DataFrame([data])
42
- df = df[expected_features]
43
-
44
- pred_encoded = model.predict(df)
45
- pred_label = label_encoder.inverse_transform(pred_encoded)[0]
46
- confidence = model.predict_proba(df).max(axis=1)[0]
47
-
48
- return {
49
- "prediction": {
50
- "desertification_level": pred_label,
51
- "confidence": float(confidence)
52
- }
53
- }