Upload inference.py with huggingface_hub
Browse files12345678910111213141516171819202122
from typing import Dict, Listimport joblibimport numpy as np
def load_model(): model = joblib.load("model.pkl") return model
def predict(inputs: Dict): """ Prediction function for the API """ model = load_model() features = np.array(inputs['inputs']).reshape(1, -1) prediction = model.predict(features) probability = model.predict_proba(features).max() return { "prediction": int(prediction[0]), "confidence": float(probability) }inference.pyAdded+22