NangTherr commited on
Commit
157e6ad
·
verified ·
1 Parent(s): ef4ac7f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -0
app.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import numpy as np
3
+ from fastapi import FastAPI
4
+ from pydantic import BaseModel
5
+ import uvicorn
6
+
7
+ # Initialize FastAPI app
8
+ app = FastAPI()
9
+
10
+ # Load model and scaler
11
+ model = joblib.load('conme.pkl')
12
+ scaler = joblib.load('scaler.joblib')
13
+
14
+ class InputData(BaseModel):
15
+ soil_moisture: float
16
+ temperature: float
17
+ air_humidity: float
18
+ light_intensity: float
19
+
20
+ @app.post("/predict")
21
+ def predict(data: InputData):
22
+ # Prepare input data
23
+ input_data = np.array([[data.soil_moisture, data.temperature, data.air_humidity, data.light_intensity]])
24
+
25
+ # Scale the data
26
+ std_data = scaler.transform(input_data)
27
+
28
+ # Make prediction
29
+ prediction = model.predict(std_data)
30
+
31
+ return {"prediction": int(prediction[0])} # Convert prediction to int (0 or 1)
32
+
33
+ if __name__ == "__main__":
34
+ uvicorn.run(app, host="0.0.0.0", port=8000)