Upload model.py
Browse files
model.py
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Literal, TypedDict
|
| 2 |
+
|
| 3 |
+
SentimentClass = Literal["negative", "neutral", "positive"]
|
| 4 |
+
|
| 5 |
+
class FeedbackAnalysis(TypedDict):
|
| 6 |
+
sentiment: SentimentClass
|
| 7 |
+
needs_followup: bool
|
| 8 |
+
suggested_priority: str
|
| 9 |
+
|
| 10 |
+
def analyze_feedback(rating: int, followup_flag: str) -> FeedbackAnalysis:
|
| 11 |
+
"""Map numeric rating and follow-up flag to sentiment and priority.
|
| 12 |
+
|
| 13 |
+
- rating: 1–5
|
| 14 |
+
- followup_flag: "yes" or "no"
|
| 15 |
+
"""
|
| 16 |
+
if rating <= 2:
|
| 17 |
+
sentiment: SentimentClass = "negative"
|
| 18 |
+
elif rating == 3:
|
| 19 |
+
sentiment = "neutral"
|
| 20 |
+
else:
|
| 21 |
+
sentiment = "positive"
|
| 22 |
+
|
| 23 |
+
flag = followup_flag.strip().lower() == "yes"
|
| 24 |
+
|
| 25 |
+
if not flag:
|
| 26 |
+
priority = "low" if sentiment == "positive" else "normal"
|
| 27 |
+
else:
|
| 28 |
+
if sentiment == "negative":
|
| 29 |
+
priority = "high"
|
| 30 |
+
elif sentiment == "neutral":
|
| 31 |
+
priority = "normal"
|
| 32 |
+
else:
|
| 33 |
+
priority = "medium"
|
| 34 |
+
|
| 35 |
+
return {
|
| 36 |
+
"sentiment": sentiment,
|
| 37 |
+
"needs_followup": flag,
|
| 38 |
+
"suggested_priority": priority,
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
if __name__ == "__main__":
|
| 42 |
+
tests = [
|
| 43 |
+
(5, "no"),
|
| 44 |
+
(4, "yes"),
|
| 45 |
+
(3, "yes"),
|
| 46 |
+
(2, "yes"),
|
| 47 |
+
]
|
| 48 |
+
for r, f in tests:
|
| 49 |
+
print(r, f, "->", analyze_feedback(r, f))
|