File size: 705 Bytes
c588c04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import joblib
import pandas as pd

class EndpointHandler:
    def __init__(self, path=""):
        # load your model artifact
        self.artifact = joblib.load(f"{path}/csic_rf_model.joblib")

    def __call__(self, data):
        # input must be a list in correct feature order
        inputs = data["inputs"]

        df = pd.DataFrame([inputs], columns=self.artifact["features"])

        pred = self.artifact["model"].predict(df)

        # if target encoder exists
        if "target_encoder" in self.artifact:
            label = self.artifact["target_encoder"].inverse_transform(pred)
            return {"prediction": label[0]}

        return {"prediction": int(pred[0])}