Vova Manannikov commited on
Commit
f4d70a9
·
1 Parent(s): ca8fafa
Files changed (1) hide show
  1. handler.py +27 -0
handler.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import Dict, List, Union
2
+ import os
3
+ import joblib
4
+ import numpy as np
5
+
6
+ features = ["fixed_acidity", "volatile_acidity", "citric_acid", "residual_sugar", "chlorides", "free_sulfur_dioxide", "total_sulfur_dioxide", "density", "pH", "sulphates", "alcohol"]
7
+
8
+ class EndpointHandler():
9
+ def __init__(self, path=""):
10
+ self.model = joblib.load("sklearn_model.joblib")
11
+
12
+ def __call__(
13
+ self, inputs: Dict[str, Dict[str, List[Union[str, float]]]]
14
+ ) -> List[Union[str, float]]:
15
+ """
16
+ Args:
17
+ inputs (:obj:`dict`):
18
+ a dictionary containing a key 'data' mapping to a dict in which
19
+ the values represent each column.
20
+ Return:
21
+ A :obj:`list` of floats or strings: The classification output for each row.
22
+ """
23
+ data = inputs["data"]
24
+ X = np.array([data[i] for i in features])
25
+ X = np.transpose(X, (1, 0))
26
+ return self.model.predict(X)
27
+