Download belel_moonshot/cloud/api/emotions.py from TTOPM/belel-protocol: direct link, hf CLI and curl.
- Browser
- Download file 999 Bytes
-
https://huggingface.co/TTOPM/belel-protocol/resolve/main/belel_moonshot/cloud/api/emotions.py
- Command line
-
hf download hf://TTOPM/belel-protocol/belel_moonshot/cloud/api/emotions.py
-
curl -L -o emotions.py https://huggingface.co/TTOPM/belel-protocol/resolve/main/belel_moonshot/cloud/api/emotions.py
999 Bytes
| from typing import Tuple | |
| LEX = {"sad":{"sad","down","depressed","blue"}, | |
| "nervous":{"nervous","worried","uneasy","concerned"}, | |
| "anxious":{"anxious","panic","overwhelmed"}, | |
| "angry":{"angry","furious","annoyed","irritated"}, | |
| "frustrated":{"frustrated","stuck","blocked"}, | |
| "happy":{"happy","glad","joyful","cheerful"}, | |
| "excited":{"excited","pumped","thrilled"}} | |
| INTENS={"very","really","so","super","extremely","quite"} | |
| NEG={"not","no","never"} | |
| def classify(text:str)->Tuple[str,float]: | |
| if not text: return "neutral",0.5 | |
| t=text.lower().split(); best=("neutral",0.5) | |
| for i,w in enumerate(t): | |
| for k,vs in LEX.items(): | |
| if w in vs: | |
| inten=0.6 | |
| win=t[max(0,i-2):i] | |
| if any(x in INTENS for x in win): inten+=0.2 | |
| if any(x in NEG for x in win): k="neutral"; inten=0.5 | |
| inten=max(0,min(1,inten)) | |
| if inten>best[1]: best=(k,inten) | |
| return best | |