from typing import Dict | |
import joblib | |
import numpy as np | |
class SvmModel: | |
def __init__(self): | |
self.model = joblib.load("model.pkl") | |
def predict(self, inputs: Dict): | |
""" | |
Make predictions using the SVM model | |
""" | |
try: | |
# Convert inputs to correct format | |
features = np.array(inputs).reshape(1, -1) | |
# Make prediction | |
prediction = self.model.predict(features) | |
probability = self.model.predict_proba(features).max() | |
return { | |
"label": int(prediction[0]), | |
"confidence": float(probability) | |
} | |
except Exception as e: | |
return {"error": str(e)} | |
def pipeline(inputs: Dict): | |
model = SvmModel() | |
return model.predict(inputs["inputs"]) | |