File size: 1,403 Bytes
4ae4ae8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
"""Atmosphere — maps emotional tone to CSS classes for ambient background."""

from __future__ import annotations

EMOTION_KEYWORDS: dict[str, list[str]] = {
    "anxious": [
        "anxious", "worried", "nervous", "panic", "dread",
        "scared", "fear", "terrified", "overwhelmed", "racing",
    ],
    "sad": [
        "sad", "depressed", "hopeless", "empty", "lonely",
        "grief", "loss", "crying", "worthless", "numb",
    ],
    "angry": [
        "angry", "furious", "frustrated", "rage", "irritated",
        "resentful", "unfair", "hate",
    ],
    "calm": [
        "calm", "peaceful", "relaxed", "okay", "better",
        "relieved", "content", "grateful",
    ],
    "breakthrough": [
        "realize", "never thought of it", "that makes sense",
        "you're right", "actually", "huh", "wow",
        "i see", "that's true",
    ],
}


def detect_emotion(text: str) -> str:
    """Detect dominant emotional tone from conversation text.

    Returns CSS class name for the atmosphere gradient.
    """
    text_lower = text.lower()
    scores: dict[str, int] = {}

    for emotion, keywords in EMOTION_KEYWORDS.items():
        score = sum(1 for kw in keywords if kw in text_lower)
        if score > 0:
            scores[emotion] = score

    if not scores:
        return "atmosphere-neutral"

    dominant = max(scores, key=scores.get)
    return f"atmosphere-{dominant}"