Upload inference.py with huggingface_hub
Browse files- inference.py +22 -0
inference.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
from typing import Dict, List
|
3 |
+
import joblib
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
def load_model():
|
7 |
+
model = joblib.load("model.pkl")
|
8 |
+
return model
|
9 |
+
|
10 |
+
def predict(inputs: Dict):
|
11 |
+
"""
|
12 |
+
Prediction function for the API
|
13 |
+
"""
|
14 |
+
model = load_model()
|
15 |
+
features = np.array(inputs['inputs']).reshape(1, -1)
|
16 |
+
prediction = model.predict(features)
|
17 |
+
probability = model.predict_proba(features).max()
|
18 |
+
|
19 |
+
return {
|
20 |
+
"prediction": int(prediction[0]),
|
21 |
+
"confidence": float(probability)
|
22 |
+
}
|