niruthiha commited on
Commit
9d98666
·
verified ·
1 Parent(s): 01e42e6

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from typing import Dict
3
+ import joblib
4
+ import numpy as np
5
+
6
+ class SvmModel:
7
+ def __init__(self):
8
+ self.model = joblib.load("model.pkl")
9
+
10
+ def predict(self, inputs: Dict):
11
+ """
12
+ Make predictions using the SVM model
13
+ """
14
+ try:
15
+ # Convert inputs to correct format
16
+ features = np.array(inputs).reshape(1, -1)
17
+
18
+ # Make prediction
19
+ prediction = self.model.predict(features)
20
+ probability = self.model.predict_proba(features).max()
21
+
22
+ return {
23
+ "label": int(prediction[0]),
24
+ "confidence": float(probability)
25
+ }
26
+ except Exception as e:
27
+ return {"error": str(e)}
28
+
29
+ def pipeline(inputs: Dict):
30
+ model = SvmModel()
31
+ return model.predict(inputs["inputs"])