File size: 698 Bytes
b0dd51d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from typing import Any

from modules.utils import Pipeline, load_model


class Emotion:
    task: str = "text-classification"
    
    def __init__(self, model_name: str) -> None:
        # model_name: str = "/models/distilbert-base-uncased-go-emotions-student/"
        print("Loading emotion model...")
        self.emotion_model: Pipeline = load_model(task=self.task, model=model_name)
        print("Loaded emotion model")
    
    def detect_emotion(self, text: str) -> str:
        """Detects emotion of the given text



        Args:

            text (str): text



        Returns:

            str: emotion

        """
        return self.emotion_model(text)[0]['label']