Spaces:
Running
Running
Update mood and expense category
Browse files
main.py
CHANGED
|
@@ -233,20 +233,56 @@ def generate_summary(text):
|
|
| 233 |
|
| 234 |
def estimate_mood(text):
|
| 235 |
text_lower = text.lower()
|
|
|
|
| 236 |
mood_map = {
|
| 237 |
-
"happy": [
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
"
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
}
|
| 245 |
|
|
|
|
| 246 |
for mood, keywords in mood_map.items():
|
| 247 |
for kw in keywords:
|
| 248 |
if kw in text_lower:
|
| 249 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 250 |
return "neutral"
|
| 251 |
|
| 252 |
def generate_tags(label, text):
|
|
@@ -524,25 +560,63 @@ def predict_expense_category(text, detected_stores):
|
|
| 524 |
|
| 525 |
# Category keyword mapping
|
| 526 |
category_keywords = {
|
| 527 |
-
|
| 528 |
-
"
|
| 529 |
-
"
|
| 530 |
-
"
|
| 531 |
-
"
|
| 532 |
-
"
|
| 533 |
-
"
|
| 534 |
-
"
|
| 535 |
-
"
|
| 536 |
-
"
|
| 537 |
-
"
|
| 538 |
-
|
| 539 |
-
"
|
| 540 |
-
"
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 546 |
|
| 547 |
# 2. Match using keyword scores
|
| 548 |
matched = {cat: sum(1 for kw in kws if kw in text_lower) for cat, kws in category_keywords.items()}
|
|
@@ -669,7 +743,7 @@ async def analyze(input: TextInput):
|
|
| 669 |
urgency_score = get_urgency_score(text, parsed_dates)
|
| 670 |
detected_stores = detect_store_category(text)
|
| 671 |
expense_category = ""
|
| 672 |
-
if best_label == "expense":
|
| 673 |
expense_category = predict_expense_category(text, detected_stores)
|
| 674 |
|
| 675 |
# Define action triggers
|
|
|
|
| 233 |
|
| 234 |
def estimate_mood(text):
|
| 235 |
text_lower = text.lower()
|
| 236 |
+
# Expanded mood map with Hindi/Hinglish and phrases
|
| 237 |
mood_map = {
|
| 238 |
+
"happy": [
|
| 239 |
+
"happy", "excited", "good", "joy", "grateful", "glad", "pleased", "content", "satisfied", "cheerful", "elated",
|
| 240 |
+
"maza aa gaya", "acha lag raha hai", "khush", "khushi", "badiya", "mast", "enjoy", "enjoyed", "mazedaar"
|
| 241 |
+
],
|
| 242 |
+
"sad": [
|
| 243 |
+
"sad", "upset", "crying", "lonely", "depressed", "down", "disappointed", "heartbroken", "unhappy",
|
| 244 |
+
"bura lag raha hai", "dukhi", "udaas", "rona", "rona aa gaya", "dil toot gaya", "nirash"
|
| 245 |
+
],
|
| 246 |
+
"angry": [
|
| 247 |
+
"angry", "annoyed", "frustrated", "irritated", "mad", "furious", "gussa", "gusse mein", "chidh", "naraz",
|
| 248 |
+
"bhadak gaya", "chidh gaya", "irritate", "irritated"
|
| 249 |
+
],
|
| 250 |
+
"nervous": [
|
| 251 |
+
"nervous", "anxious", "scared", "worried", "fearful", "uneasy", "tensed", "tension", "ghabrahat", "chinta",
|
| 252 |
+
"parishan", "dara hua", "ghabra gaya", "stress", "stressed"
|
| 253 |
+
],
|
| 254 |
+
"unwell": [
|
| 255 |
+
"sick", "unwell", "not feeling well", "fever", "cold", "headache", "flu", "ill", "nauseous", "dizzy",
|
| 256 |
+
"thak gaya", "thaka hua", "bimaar", "bimar", "bukhar", "sardard", "beemar", "kamjor", "thakan"
|
| 257 |
+
],
|
| 258 |
+
"neutral": [
|
| 259 |
+
"ok", "fine", "theek", "normal", "usual", "routine", "nothing special", "kuch khaas nahi", "no stress"
|
| 260 |
+
]
|
| 261 |
}
|
| 262 |
|
| 263 |
+
detected_moods = []
|
| 264 |
for mood, keywords in mood_map.items():
|
| 265 |
for kw in keywords:
|
| 266 |
if kw in text_lower:
|
| 267 |
+
detected_moods.append(mood)
|
| 268 |
+
break # Only need one match per mood
|
| 269 |
+
|
| 270 |
+
# Use sentiment as a fallback if no mood keyword matched
|
| 271 |
+
if not detected_moods:
|
| 272 |
+
sentiment = get_sentiment_score(text)
|
| 273 |
+
if sentiment > 0.2:
|
| 274 |
+
return "happy"
|
| 275 |
+
elif sentiment < -0.2:
|
| 276 |
+
return "sad"
|
| 277 |
+
else:
|
| 278 |
+
return "neutral"
|
| 279 |
+
|
| 280 |
+
# Priority: angry > sad > unwell > nervous > happy > neutral
|
| 281 |
+
priority = ["angry", "sad", "unwell", "nervous", "happy", "neutral"]
|
| 282 |
+
for mood in priority:
|
| 283 |
+
if mood in detected_moods:
|
| 284 |
+
return mood
|
| 285 |
+
|
| 286 |
return "neutral"
|
| 287 |
|
| 288 |
def generate_tags(label, text):
|
|
|
|
| 560 |
|
| 561 |
# Category keyword mapping
|
| 562 |
category_keywords = {
|
| 563 |
+
"food": [
|
| 564 |
+
"food", "lunch", "dinner", "breakfast", "snacks", "swiggy", "zomato", "dominos", "pizza", "kfc", "mcdonald",
|
| 565 |
+
"restaurant", "hotel", "cafe", "canteen", "meal", "buffet", "thali", "tiffin", "order", "takeaway", "parcel",
|
| 566 |
+
"eat", "eating", "brunch", "supper", "kitchen", "cook", "cooking", "chef", "dish", "dishes", "menu", "serve",
|
| 567 |
+
"served", "serving", "food court", "food delivery", "delivery", "online order", "food app", "food bill",
|
| 568 |
+
"beverage", "juice", "shake", "smoothie", "coffee", "tea", "chai", "cold drink", "soft drink", "soda", "water bottle",
|
| 569 |
+
"ice cream", "dessert", "sweet", "sweets", "chocolate", "candy", "bakery", "bread", "cake", "pastry", "cookie",
|
| 570 |
+
"biscuit", "chips", "fries", "burger", "sandwich", "roll", "wrap", "noodles", "pasta", "rice", "biryani", "curry",
|
| 571 |
+
"gravy", "dal", "sabzi", "roti", "naan", "paratha", "chapati", "idli", "dosa", "vada", "sambar", "chutney", "samosa",
|
| 572 |
+
"pakora", "chaat", "pani puri", "golgappa", "sev", "poha", "upma", "maggi", "maggie", "momos", "spring roll",
|
| 573 |
+
"manchurian", "paneer", "butter chicken", "tandoori", "kebab", "shawarma", "pizza hut", "subway", "starbucks",
|
| 574 |
+
# Hindi/Hinglish
|
| 575 |
+
"khana", "nashta", "bhojan", "rasoi", "thali", "dabba", "tiffin", "chai", "paani", "jal", "kharcha khana",
|
| 576 |
+
"khane ka bill", "khane ka paisa", "khane ki cheez", "khana order", "khana mangwaya", "khana khaya", "khana khud banaya",
|
| 577 |
+
"khana kharch", "khana kharida", "khana diya", "khana laya", "khana banaya"
|
| 578 |
+
],
|
| 579 |
+
"transport": [
|
| 580 |
+
"uber", "ola", "taxi", "cab", "bus", "train", "metro", "flight", "auto", "rickshaw", "car", "gaadi", "yatra", "safar", "travel", "ticket", "plane", "udaan", "station", "airport"
|
| 581 |
+
],
|
| 582 |
+
"shopping": [
|
| 583 |
+
"amazon", "flipkart", "myntra", "shopping", "clothes", "kapde", "apparel", "shoes", "jeans", "tshirt", "store", "fashion", "dukaan", "mall", "bazaar", "market", "kharida", "order diya", "le liya"
|
| 584 |
+
],
|
| 585 |
+
"housing": [
|
| 586 |
+
"rent", "apartment", "house", "ghar", "flat", "maintenance", "landlord", "kiraya", "makaan", "room", "hostel", "pg", "society"
|
| 587 |
+
],
|
| 588 |
+
"utilities": [
|
| 589 |
+
"electricity", "power", "bijli", "water", "pani", "gas", "bill", "recharge", "broadband", "wifi", "airtel", "jio", "phone", "mobile", "internet", "light", "cylinder", "connection"
|
| 590 |
+
],
|
| 591 |
+
"entertainment": [
|
| 592 |
+
"movie", "netflix", "hotstar", "bookmyshow", "spotify", "gaming", "youtube premium", "cinema", "film", "picture", "game", "khel", "manoranjan", "show", "concert"
|
| 593 |
+
],
|
| 594 |
+
"health": [
|
| 595 |
+
"medicine", "hospital", "doctor", "clinic", "pharmacy", "tablet", "surgery", "checkup", "dawai", "aspatal", "ilaaj", "health", "bimari", "test", "medical", "pathology", "chemist"
|
| 596 |
+
],
|
| 597 |
+
"travel": [
|
| 598 |
+
"trip", "travel", "tour", "vacation", "hotel", "airbnb", "booking.com", "goibibo", "makemytrip", "yatra", "safar", "holiday", "journey", "musafir", "booking", "trip kiya"
|
| 599 |
+
],
|
| 600 |
+
"education": [
|
| 601 |
+
"course", "webinar", "class", "training", "workshop", "udemy", "coursera", "byjus", "unacademy", "skill", "padhai", "school", "college", "tuition", "kitab", "book", "fees", "shiksha"
|
| 602 |
+
],
|
| 603 |
+
"digital_services": [
|
| 604 |
+
"domain", "hosting", "license", "email", "software", "zoom", "notion", "figma", "aws", "google cloud", "saas", "subscription", "digital", "online", "app", "service", "renewal"
|
| 605 |
+
],
|
| 606 |
+
"gifts_donations": [
|
| 607 |
+
"gift", "donation", "present", "charity", "ngo", "temple", "mandir", "birthday gift", "festival gift", "uphaar", "daan", "tohfa", "chanda", "puja", "mandir", "gurudwara"
|
| 608 |
+
],
|
| 609 |
+
"finance": [
|
| 610 |
+
"insurance", "sip", "mutual fund", "stock", "demat", "zerodha", "investment", "trading", "upstox", "crypto", "policy", "premium", "loan", "emi", "fd", "rd", "paisa", "bank", "account"
|
| 611 |
+
],
|
| 612 |
+
"family_kids": [
|
| 613 |
+
"kid", "baby", "school", "daycare", "tuition", "books", "uniform", "toys", "creche", "baccha", "bachche", "parivar", "family", "beti", "beta", "child", "children"
|
| 614 |
+
],
|
| 615 |
+
"stationery": [
|
| 616 |
+
"pen", "pencil", "notebook", "diary", "eraser", "sharpener", "paper", "stationery", "register", "files", "file", "markers", "highlighter", "sticky notes", "geometry box",
|
| 617 |
+
"stapler", "ink", "printer paper", "stationary shop", "stationary", "copy", "kagaz", "likhne ka saman"
|
| 618 |
+
]
|
| 619 |
+
}
|
| 620 |
|
| 621 |
# 2. Match using keyword scores
|
| 622 |
matched = {cat: sum(1 for kw in kws if kw in text_lower) for cat, kws in category_keywords.items()}
|
|
|
|
| 743 |
urgency_score = get_urgency_score(text, parsed_dates)
|
| 744 |
detected_stores = detect_store_category(text)
|
| 745 |
expense_category = ""
|
| 746 |
+
if best_label == "expense" or best_label == "purchase":
|
| 747 |
expense_category = predict_expense_category(text, detected_stores)
|
| 748 |
|
| 749 |
# Define action triggers
|