mitesh001 commited on
Commit
8efae68
·
1 Parent(s): 168d99e

Update mood and expense category

Browse files
Files changed (1) hide show
  1. main.py +102 -28
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": ["happy", "excited", "joy", "grateful", "glad", "pleased", "content", "satisfied", "cheerful", "elated", "joyful", "optimistic", "hopeful", "proud", "relieved", "enthusiastic", "calm", "peaceful", "blessed", "loved", "appreciative", "thankful", "delighted", "ecstatic", "thrilled", "overjoyed", "jubilant", "exhilarated", "radiant", "buoyant", "upbeat", "positive", "motivated", "inspired", "confident", "empowered", "fulfilled", "satisfied", "contented", "serene", "tranquil", "harmonious", "balanced", "centered", "grounded"],
238
- "sad": ["sad", "upset", "crying", "lonely", "depressed", "down", "disappointed", "heartbroken", "unhappy", "dismayed", "discouraged", "disheartened", "miserable", "sorrowful", "melancholy", "gloomy", "despondent", "forlorn", "dejected", "woeful", "doleful", "glum", "downcast", "crestfallen", "dispirited", "desolate", "blue", "heavy-hearted", "low-spirited", "disconsolate"],
239
- "angry": ["angry", "annoyed", "frustrated", "irritated", "mad", "furious", "enraged", "livid", "outraged", "infuriated", "exasperated", "indignant", "resentful", "incensed", "fuming", "seething", "irate", "cross", "peeved", "vexed", "agitated", "upset", "displeased", "disgruntled", "miffed", "huffy", "snappy", "testy", "touchy", "ticked off", "riled up", "worked up"],
240
- "nervous": ["nervous", "anxious", "scared", "worried", "fearful", "uneasy", "apprehensive", "tense", "jittery", "restless", "on edge", "panicky", "fidgety", "edgy", "stressed", "agitated", "distressed", "troubled", "concerned", "uneasy", "jumpy", "hyper", "frenzied", "overwhelmed", "frazzled", "flustered", "perturbed", "disconcerted", "disquieted", "unsettled"],
241
- "unwell": ["sick", "unwell", "not feeling well", "fever", "cold", "headache", "flu", "ill", "nauseous", "dizzy", "tired", "exhausted", "fatigued", "weak", "pain", "ache", "vomit", "cough", "sneeze", "chills", "shivers", "congestion", "runny nose", "coughing", "sore throat", "stomachache", "upset stomach", "diarrhea", "vomiting", "nausea", "drowsy", "sleepy", "lethargic", "groggy", "uncomfortable", "feeling off", "under the weather"],
242
- "neutral": [],
243
- "anxious": ["anxious", "restless", "uneasy", "jittery", "on edge", "tense", "fidgety", "nervous", "worried", "apprehensive", "scared", "panicky", "hyper", "edgy", "stressed", "agitated", "distressed", "troubled", "concerned", "unsettled", "disconcerted", "disquieted", "perturbed", "flustered", "overwhelmed", "frazzled", "discombobulated", "disoriented", "confused"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
244
  }
245
 
 
246
  for mood, keywords in mood_map.items():
247
  for kw in keywords:
248
  if kw in text_lower:
249
- return mood
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
- "food": ["food", "lunch", "dinner", "breakfast", "snacks", "swiggy", "zomato", "dominos", "pizza", "kfc", "mcdonald"],
528
- "transport": ["uber", "ola", "taxi", "cab", "bus", "train", "metro", "flight", "auto"],
529
- "shopping": ["amazon", "flipkart", "myntra", "shopping", "clothes", "apparel", "shoes", "jeans", "tshirt", "store", "fashion"],
530
- "housing": ["rent", "apartment", "house", "flat", "maintenance", "landlord"],
531
- "utilities": ["electricity", "power", "water", "gas", "bill", "recharge", "broadband", "wifi", "airtel", "jio"],
532
- "entertainment": ["movie", "netflix", "hotstar", "bookmyshow", "spotify", "gaming", "youtube premium"],
533
- "health": ["medicine", "hospital", "doctor", "clinic", "pharmacy", "tablet", "surgery", "checkup"],
534
- "travel": ["trip", "travel", "tour", "vacation", "hotel", "airbnb", "booking.com", "goibibo", "makemytrip", "yatra"],
535
- "education": ["course", "webinar", "class", "training", "workshop", "udemy", "coursera", "byjus", "unacademy", "skill"],
536
- "digital_services": ["domain", "hosting", "license", "email", "software", "zoom", "notion", "figma", "aws", "google cloud", "saas"],
537
- "gifts_donations": ["gift", "donation", "present", "charity", "ngo", "temple", "mandir", "birthday gift", "festival gift"],
538
- "finance": ["insurance", "sip", "mutual fund", "stock", "demat", "zerodha", "investment", "trading", "upstox", "crypto"],
539
- "family_kids": ["kid", "baby", "school", "daycare", "tuition", "books", "uniform", "toys", "creche"],
540
- "stationery": [
541
- "pen", "pencil", "notebook", "diary", "eraser", "sharpener", "paper", "stationery",
542
- "register", "files", "file", "markers", "highlighter", "sticky notes", "geometry box",
543
- "stapler", "ink", "printer paper", "stationary shop", "stationary"
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