Spaces:
Sleeping
Sleeping
| """Pure continuous mapping: mood[7] (V A D U G W I, 0-255) -> render params. | |
| Hue flows smoothly with valence (red->orange->yellow->green); arousal sets | |
| vividness and eye-openness; face is parametric (mouth curve, eye size, brow tilt).""" | |
| from __future__ import annotations | |
| def _lerp(x, x0, x1, y0, y1): | |
| if x1 == x0: | |
| return y0 | |
| t = max(0.0, min(1.0, (x - x0) / (x1 - x0))) | |
| return y0 + (y1 - y0) * t | |
| def _norm(x): # 0..255 -> 0..1 | |
| return max(0, min(255, x)) / 255.0 | |
| def _face(v: int, a: int) -> str: | |
| """Region string for voice/emoticon lookup (backward compatibility).""" | |
| POS, NEG = 150, 106 | |
| if v >= POS: | |
| return "excited" if a >= 170 else "content" | |
| if v <= NEG: | |
| return "angry" if a >= 128 else "sad" | |
| return "neutral" | |
| def _emotion_glow(v: int, a: int) -> dict: | |
| """Anime-style emotion on the FACE β the body stays yellow, the cheeks/face glow. | |
| Returns {type, hue, intensity 0..1}. Red for anger/fluster, blue for sadness, | |
| warm pink for joy/blush.""" | |
| if v <= 100 and a >= 150: # anger β red face | |
| return {"type": "anger", "hue": 2, "intensity": round(_lerp(a, 150, 255, 0.45, 1.0), 2)} | |
| if v <= 106: # sad/low β blue | |
| return {"type": "sad", "hue": 212, "intensity": round(_lerp(v, 106, 0, 0.2, 0.7), 2)} | |
| if v >= 165 and a >= 165: # elated β warm pink blush | |
| return {"type": "joy", "hue": 332, "intensity": round(_lerp(a, 165, 255, 0.35, 0.85), 2)} | |
| if a >= 200: # very high arousal, mid valence β flustered/embarrassed red | |
| return {"type": "fluster", "hue": 356, "intensity": round(_lerp(a, 200, 255, 0.35, 0.85), 2)} | |
| return {"type": "none", "hue": 0, "intensity": 0.0} | |
| def mood_to_appearance(mood: list[int]) -> dict: | |
| v, a, d, u, g, w, i = mood | |
| glow = _emotion_glow(v, a) | |
| return { | |
| # BODY is always Hugging Face yellow (mascot identity). Arousal only changes | |
| # how saturated/bright the yellow is β never the hue. Emotion shows on the face. | |
| "hue": 48.0, | |
| "saturation": round(_lerp(a, 0, 255, 80.0, 96.0), 1), | |
| "lightness": round(_lerp(a, 0, 255, 56.0, 64.0), 1), | |
| # aura behind him picks up the EMOTION color (subtle ambient mood) | |
| "aura": round(_lerp(a, 0, 255, 0.12, 0.7), 2), | |
| "glow": glow, | |
| "scale": round(_lerp(d, 0, 255, 0.85, 1.18), 3), | |
| "droop": round(_norm(g), 2), | |
| "lean": round((i - 128) / 128.0, 2), | |
| "face": { | |
| "mouth": round((v - 128) / 128.0, 2), # +smile β¦ -frown | |
| "eye": round(_lerp(a, 0, 255, 0.5, 1.4), 2), # openness | |
| "brow": round(((128 - v) / 128.0) * _norm(a), 2), # angry = low V + high A | |
| }, | |
| "mood": mood, | |
| } | |