File size: 733 Bytes
0c746c9
 
 
 
a6bbf63
 
 
 
 
 
0c746c9
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from utils.commons import setup_logging

logger = setup_logging("predictor.log")

class Predictor:
    def __init__(self, pipeline):
        self.pipeline = pipeline
        
    def predict(self, text):
        """Make prediction"""
        try:
            logger.info(f"Making prediction for text: {text}")
            preds_list = self.pipeline(text)
            best_pred = max(preds_list[0], key=lambda x: x["score"])
            logger.info(f"Prediction successful: {best_pred}")
            return {
                "predicted_intent": best_pred["label"],
                "confidence": best_pred["score"]
            }
        except Exception as e:
            logger.error(f"Error during prediction: {e}")
            raise