File size: 840 Bytes
9d98666
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

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"])