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 = sorted(prediction, key=lambda x: x['score'])[::-1] return result sentiment_map = {'anger': 'neg', 'sadness': 'neg', 'fear': 'neg', 'joy': 'pos', 'love': 'pos', 'surprise': 'pos'} good_arcs = ['neg - pos', 'pos - neg'] great_arcs = ['pos - neg - pos', 'neg - pos - neg'] def get_sentiment_arc_evaluation(emotions): sentiment_arc = [] for emo in emotions: sentiment = sentiment_map[emo] if sentiment_arc and sentiment_arc[-1] == sentiment: continue sentiment_arc.append(sentiment) sentiment_arc_str = ' - '.join(sentiment_arc) if sentiment_arc_str in great_arcs: return 'What a great plot! Excellent! 😍' elif sentiment_arc_str in good_arcs: return 'Story plot seems nice! But you can do better. 😉' elif len(sentiment_arc) < 2: return "No judgment, but... The plot might be too simple! 🤓" else: return "The plot seems complicated. 🤔 But maybe I am just too stupid to understand!"