Anshika2002 commited on
Commit
c588c04
·
verified ·
1 Parent(s): 2fe9618

Upload handler.py

Browse files
Files changed (1) hide show
  1. handler.py +22 -0
handler.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import pandas as pd
3
+
4
+ class EndpointHandler:
5
+ def __init__(self, path=""):
6
+ # load your model artifact
7
+ self.artifact = joblib.load(f"{path}/csic_rf_model.joblib")
8
+
9
+ def __call__(self, data):
10
+ # input must be a list in correct feature order
11
+ inputs = data["inputs"]
12
+
13
+ df = pd.DataFrame([inputs], columns=self.artifact["features"])
14
+
15
+ pred = self.artifact["model"].predict(df)
16
+
17
+ # if target encoder exists
18
+ if "target_encoder" in self.artifact:
19
+ label = self.artifact["target_encoder"].inverse_transform(pred)
20
+ return {"prediction": label[0]}
21
+
22
+ return {"prediction": int(pred[0])}