from transformers import pipeline | |
classifier = pipeline("text-classification", | |
model='bhadresh-savani/distilbert-base-uncased-emotion', | |
return_all_scores=True) | |
def get_emotion(text='No text yet'): | |
prediction = classifier(text)[0] | |
result = max(prediction, key=lambda x: x['score']) | |
return result | |