Spaces:
Sleeping
Sleeping
Update app.py
Browse files32 unmodified lines3334353637383925 unmodified lines6566676869707122 unmodified lines9495969798991001011021033 unmodified lines10710810911011111211332 unmodified linesmodel = AutoModelForSequenceClassification.from_pretrained(model_name)emotion_classifier = pipeline("text-classification", tokenizer=tokenizer, model=model, return_all_scores=True)line_emotions = analyze_lines_emotions(lines, emotion_classifier, threshold=0.5)# 4. Выбор лучших цитат по настроениюquotes_by_mood = get_best_quotes_by_mood(line_emotions)25 unmodified lineslines = text.strip().split('\n')return linesdef analyze_lines_emotions(lines, emotion_classifier, threshold=0.5):# Словарь для перевода эмоций на русский языкemotion_translation = {"admiration": "восхищение",22 unmodified lines"relief": "облегчение","remorse": "раскаяние","sadness": "печаль","surprise": "удивление","neutral": "нейтрально"}results = []for line in lines:if not line.strip():3 unmodified linesfor pred in predictions:emotion_label = pred['label']emotion_label_ru = emotion_translation.get(emotion_label, emotion_label)emotions[emotion_label_ru] = round(float(pred['score']), 3)# Определяем доминирующую эмоциюdominant_emotion = max(emotions, key=emotions.get)dominant_score = emotions[dominant_emotion]32 unmodified lines3334353637383925 unmodified lines6566676869707122 unmodified lines9495969798991001011021031041051061071081091101111121131141151161171181191201211223 unmodified lines12612712812913013113213313413513613732 unmodified linesmodel = AutoModelForSequenceClassification.from_pretrained(model_name)emotion_classifier = pipeline("text-classification", tokenizer=tokenizer, model=model, return_all_scores=True)line_emotions = analyze_lines_emotions(lines, emotion_classifier, threshold=0.3)# 4. Выбор лучших цитат по настроениюquotes_by_mood = get_best_quotes_by_mood(line_emotions)25 unmodified lineslines = text.strip().split('\n')return linesdef analyze_lines_emotions(lines, emotion_classifier, threshold=0.3):# Словарь для перевода эмоций на русский языкemotion_translation = {"admiration": "восхищение",22 unmodified lines"relief": "облегчение","remorse": "раскаяние","sadness": "печаль","surprise": "удивление"}# Список эмоций для исключенияexcluded_emotions = ["развлечение","одобрение","забота","замешательство","любопытство","желание","неодобрение","отвращение","смущение","волнение","благодарность","нервозность","гордость","осознание","облегчение","раскаяние"]results = []for line in lines:if not line.strip():3 unmodified linesfor pred in predictions:emotion_label = pred['label']emotion_label_ru = emotion_translation.get(emotion_label, emotion_label)# Пропускаем эмоции из списка исключенияif emotion_label_ru in excluded_emotions or emotion_label == "neutral":continueemotions[emotion_label_ru] = round(float(pred['score']), 3)if not emotions:continue # Если нет эмоций для рассмотрения, пропускаем строку# Определяем доминирующую эмоциюdominant_emotion = max(emotions, key=emotions.get)dominant_score = emotions[dominant_emotion]
app.py+28-4