OHO-17(Perfect Prediction)
This commit is contained in:
parent
030c8bd99d
commit
16c7e05812
5 changed files with 335 additions and 7 deletions
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
|
|
@ -1,3 +1,7 @@
|
|||
{
|
||||
"postman.settings.dotenv-detection-notification-visibility": false
|
||||
"postman.settings.dotenv-detection-notification-visibility": false,
|
||||
"python.analysis.extraPaths": [
|
||||
"./AI/Rules/transaction_",
|
||||
"./AI/Rules/transaction_"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
BIN
AI/Rules/__pycache__/transaction_rules.cpython-313.pyc
Normal file
BIN
AI/Rules/__pycache__/transaction_rules.cpython-313.pyc
Normal file
Binary file not shown.
289
AI/Rules/transaction_rules.py
Normal file
289
AI/Rules/transaction_rules.py
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
# vendor_rules.py
|
||||
def get_category_from_rules(vendor_name: str):
|
||||
if not vendor_name:
|
||||
return None
|
||||
|
||||
vendor = vendor_name.lower()
|
||||
|
||||
# Food , Shopping , Bills , Travel , Entertainment , Other
|
||||
mapping = {
|
||||
# ---------- FOOD ----------
|
||||
"mcdonalds": "Food",
|
||||
"kfc": "Food",
|
||||
"hotel": "Food",
|
||||
"restaurant": "Food",
|
||||
"canteen": "Food",
|
||||
"dhaba": "Food",
|
||||
"mess": "Food",
|
||||
"biryani": "Food",
|
||||
"tiffins": "Food",
|
||||
"cafe": "Food",
|
||||
"coffee": "Food",
|
||||
"tea stall": "Food",
|
||||
"bakery": "Food",
|
||||
"sweets": "Food",
|
||||
"ice cream": "Food",
|
||||
"juice": "Food",
|
||||
"snacks": "Food",
|
||||
"lunch": "Food",
|
||||
"dinner": "Food",
|
||||
"food court": "Food",
|
||||
"catering": "Food",
|
||||
"canteen store": "Food",
|
||||
"dominos": "Food",
|
||||
"pizza hut": "Food",
|
||||
"subway": "Food",
|
||||
"starbucks": "Food",
|
||||
"cafe coffee day": "Food",
|
||||
"ccd": "Food",
|
||||
"swiggy": "Food",
|
||||
"zomato": "Food",
|
||||
"ubereats": "Food",
|
||||
"barbeque nation": "Food",
|
||||
"wow momo": "Food",
|
||||
"cream stone": "Food",
|
||||
"bikanervala": "Food",
|
||||
"haldiram": "Food",
|
||||
"paradise biryani": "Food",
|
||||
"behrouz biryani": "Food",
|
||||
"freshmenu": "Food",
|
||||
"burger king": "Food",
|
||||
"taco bell": "Food",
|
||||
"sagar ratna": "Food",
|
||||
"shs canteen": "Food",
|
||||
"babai hotel": "Food",
|
||||
"taj hotel": "Food",
|
||||
"itc hotel": "Food",
|
||||
"novotel": "Food",
|
||||
"radisson": "Food",
|
||||
"trident": "Food",
|
||||
|
||||
# ---------- SHOPPING ----------
|
||||
"mall": "Shopping",
|
||||
"store": "Shopping",
|
||||
"supermarket": "Shopping",
|
||||
"bazaar": "Shopping",
|
||||
"market": "Shopping",
|
||||
"mart": "Shopping",
|
||||
"fashion": "Shopping",
|
||||
"clothing": "Shopping",
|
||||
"footwear": "Shopping",
|
||||
"electronics": "Shopping",
|
||||
"mobile store": "Shopping",
|
||||
"accessories": "Shopping",
|
||||
"furniture": "Shopping",
|
||||
"home decor": "Shopping",
|
||||
"appliances": "Shopping",
|
||||
"cosmetics": "Shopping",
|
||||
"salon": "Shopping",
|
||||
"boutique": "Shopping",
|
||||
"jewellery": "Shopping",
|
||||
"stationery": "Shopping",
|
||||
"amazon": "Shopping",
|
||||
"flipkart": "Shopping",
|
||||
"myntra": "Shopping",
|
||||
"ajio": "Shopping",
|
||||
"tatacliq": "Shopping",
|
||||
"meesho": "Shopping",
|
||||
"snapdeal": "Shopping",
|
||||
"shopclues": "Shopping",
|
||||
"bigbasket": "Shopping",
|
||||
"grofers": "Shopping",
|
||||
"dmart": "Shopping",
|
||||
"reliance fresh": "Shopping",
|
||||
"more supermarket": "Shopping",
|
||||
"spencers": "Shopping",
|
||||
"vishal mega mart": "Shopping",
|
||||
"zudio": "Shopping",
|
||||
"pantaloons": "Shopping",
|
||||
"lifestyle": "Shopping",
|
||||
"shoppers stop": "Shopping",
|
||||
"westside": "Shopping",
|
||||
"max fashion": "Shopping",
|
||||
"nike": "Shopping",
|
||||
"adidas": "Shopping",
|
||||
"puma": "Shopping",
|
||||
"reebok": "Shopping",
|
||||
"levi": "Shopping",
|
||||
"h&m": "Shopping",
|
||||
"zara": "Shopping",
|
||||
"decathlon": "Shopping",
|
||||
"ikea": "Shopping",
|
||||
|
||||
# ---------- BILLS ----------
|
||||
"electricity": "Bills",
|
||||
"power": "Bills",
|
||||
"water bill": "Bills",
|
||||
"internet": "Bills",
|
||||
"wifi": "Bills",
|
||||
"broadband": "Bills",
|
||||
"dth": "Bills",
|
||||
"recharge": "Bills",
|
||||
"gas": "Bills",
|
||||
"cylinder": "Bills",
|
||||
"mobile bill": "Bills",
|
||||
"postpaid": "Bills",
|
||||
"prepaid": "Bills",
|
||||
"telecom": "Bills",
|
||||
"landline": "Bills",
|
||||
"sewage": "Bills",
|
||||
"municipal": "Bills",
|
||||
"property tax": "Bills",
|
||||
"credit card": "Bills",
|
||||
"loan emi": "Bills",
|
||||
"bescom": "Bills", # electricity
|
||||
"tsspdcl": "Bills",
|
||||
"apspdcl": "Bills",
|
||||
"torrent power": "Bills",
|
||||
"bese": "Bills",
|
||||
"bmtc pass": "Bills",
|
||||
"airtel": "Bills",
|
||||
"jio": "Bills",
|
||||
"vi": "Bills",
|
||||
"bsnl": "Bills",
|
||||
"act fibernet": "Bills",
|
||||
"hathway": "Bills",
|
||||
"den broadband": "Bills",
|
||||
"tatasky": "Bills",
|
||||
"airtel dth": "Bills",
|
||||
"sun direct": "Bills",
|
||||
"dishtv": "Bills",
|
||||
"dth recharge": "Bills",
|
||||
"gas bill": "Bills",
|
||||
"bharat gas": "Bills",
|
||||
"hp gas": "Bills",
|
||||
"indane gas": "Bills",
|
||||
|
||||
# ---------- TRAVEL ----------
|
||||
"cab": "Travel",
|
||||
"taxi": "Travel",
|
||||
"auto": "Travel",
|
||||
"bus": "Travel",
|
||||
"train": "Travel",
|
||||
"railway": "Travel",
|
||||
"metro": "Travel",
|
||||
"flight": "Travel",
|
||||
"airlines": "Travel",
|
||||
"airport": "Travel",
|
||||
"air ticket": "Travel",
|
||||
"ticket": "Travel",
|
||||
"boarding": "Travel",
|
||||
"lodge": "Travel",
|
||||
"resort": "Travel",
|
||||
"tour": "Travel",
|
||||
"travel agency": "Travel",
|
||||
"holiday": "Travel",
|
||||
"trip": "Travel",
|
||||
"taxi service": "Travel",
|
||||
"ola": "Travel",
|
||||
"uber": "Travel",
|
||||
"redbus": "Travel",
|
||||
"abhibus": "Travel",
|
||||
"irctc": "Travel",
|
||||
"indigo": "Travel",
|
||||
"air india": "Travel",
|
||||
"vistara": "Travel",
|
||||
"spicejet": "Travel",
|
||||
"goair": "Travel",
|
||||
"akasa air": "Travel",
|
||||
"makemytrip": "Travel",
|
||||
"yatra": "Travel",
|
||||
"cleartrip": "Travel",
|
||||
"booking.com": "Travel",
|
||||
"oyo": "Travel",
|
||||
"treebo": "Travel",
|
||||
"fabhotel": "Travel",
|
||||
"trivago": "Travel",
|
||||
"zoomcar": "Travel",
|
||||
"drivezy": "Travel",
|
||||
|
||||
# ---------- ENTERTAINMENT ----------
|
||||
"cinema": "Entertainment",
|
||||
"movie": "Entertainment",
|
||||
"theatre": "Entertainment",
|
||||
"concert": "Entertainment",
|
||||
"event": "Entertainment",
|
||||
"show": "Entertainment",
|
||||
"festival": "Entertainment",
|
||||
"ticketnew": "Entertainment",
|
||||
"games": "Entertainment",
|
||||
"gaming": "Entertainment",
|
||||
"amusement": "Entertainment",
|
||||
"theme park": "Entertainment",
|
||||
"club": "Entertainment",
|
||||
"pub": "Entertainment",
|
||||
"bar": "Entertainment",
|
||||
"karaoke": "Entertainment",
|
||||
"music": "Entertainment",
|
||||
"streaming": "Entertainment",
|
||||
"subscription": "Entertainment",
|
||||
"video": "Entertainment",
|
||||
"netflix": "Entertainment",
|
||||
"amazon prime": "Entertainment",
|
||||
"hotstar": "Entertainment",
|
||||
"disney+": "Entertainment",
|
||||
"sonyliv": "Entertainment",
|
||||
"zee5": "Entertainment",
|
||||
"aha": "Entertainment",
|
||||
"spotify": "Entertainment",
|
||||
"gaana": "Entertainment",
|
||||
"wynk": "Entertainment",
|
||||
"saregama": "Entertainment",
|
||||
"bookmyshow": "Entertainment",
|
||||
"pvr": "Entertainment",
|
||||
"inox": "Entertainment",
|
||||
"cinepolis": "Entertainment",
|
||||
"jio cinema": "Entertainment",
|
||||
"altbalaji": "Entertainment",
|
||||
"voot": "Entertainment",
|
||||
"apple music": "Entertainment",
|
||||
"youtube premium": "Entertainment",
|
||||
|
||||
# ---------- OTHER ----------
|
||||
"apollo pharmacy": "Other",
|
||||
"pharmacy": "Other",
|
||||
"medical": "Other",
|
||||
"chemist": "Other",
|
||||
"clinic": "Other",
|
||||
"hospital": "Other",
|
||||
"doctor": "Other",
|
||||
"diagnostic": "Other",
|
||||
"lab": "Other",
|
||||
"insurance": "Other",
|
||||
"policy": "Other",
|
||||
"atm": "Other",
|
||||
"bank": "Other",
|
||||
"branch": "Other",
|
||||
"transaction": "Other",
|
||||
"school": "Other",
|
||||
"college": "Other",
|
||||
"university": "Other",
|
||||
"coaching": "Other",
|
||||
"training": "Other",
|
||||
"service": "Other",
|
||||
"repair": "Other",
|
||||
"medplus": "Other",
|
||||
"1mg": "Other",
|
||||
"pharmeasy": "Other",
|
||||
"netmeds": "Other",
|
||||
"urbanclap": "Other",
|
||||
"urban company": "Other",
|
||||
"justdial": "Other",
|
||||
"olx": "Other",
|
||||
"quikr": "Other",
|
||||
"paytm": "Other",
|
||||
"phonepe": "Other",
|
||||
"google pay": "Other",
|
||||
"freecharge": "Other",
|
||||
"mobikwik": "Other",
|
||||
"upi": "Other",
|
||||
"insurance": "Other",
|
||||
"policybazaar": "Other",
|
||||
"bank": "Other"
|
||||
}
|
||||
|
||||
for keyword, category in mapping.items():
|
||||
if keyword in vendor:
|
||||
return category
|
||||
|
||||
return None
|
||||
|
|
@ -1,10 +1,39 @@
|
|||
# from flask import Flask, request, jsonify
|
||||
# import joblib
|
||||
# import sklearn
|
||||
# import numpy as np
|
||||
# from Rules.transaction_rules import get_category_from_rules
|
||||
|
||||
# model = joblib.load("model/category_model.pkl")
|
||||
# vectorizer = joblib.load("model/vectorizer.pkl")
|
||||
|
||||
# app = Flask(__name__)
|
||||
|
||||
# @app.route("/api/predict", methods=["POST"])
|
||||
# def predict():
|
||||
# data = request.json
|
||||
# description = data.get("description", "")
|
||||
|
||||
# if not description:
|
||||
# return jsonify({"error": "Description is required"}), 400
|
||||
|
||||
# category = get_category_from_rules(description)
|
||||
# if not category:
|
||||
# X = vectorizer.transform([description])
|
||||
# prediction = model.predict(X)[0]
|
||||
|
||||
# return jsonify({"category": prediction})
|
||||
|
||||
# if __name__ == "__main__":
|
||||
# app.run(host="0.0.0.0", port=5000)
|
||||
from flask import Flask, request, jsonify
|
||||
import joblib
|
||||
import sklearn
|
||||
import joblib
|
||||
import sklearn
|
||||
import numpy as np
|
||||
from Rules.transaction_rules import get_category_from_rules
|
||||
|
||||
model = joblib.load("model/category_model.pkl")
|
||||
vectorizer = joblib.load("model/vectorizer.pkl")
|
||||
vectorizer = joblib.load("model/vectorizer.pkl")
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
|
|
@ -16,9 +45,15 @@ def predict():
|
|||
if not description:
|
||||
return jsonify({"error": "Description is required"}), 400
|
||||
|
||||
# Preprocess and predict
|
||||
X = vectorizer.transform([description])
|
||||
prediction = model.predict(X)[0]
|
||||
# First try rules
|
||||
category = get_category_from_rules(description)
|
||||
|
||||
if category:
|
||||
prediction = category # ✅ assign directly
|
||||
else:
|
||||
# fallback to ML
|
||||
X = vectorizer.transform([description])
|
||||
prediction = model.predict(X)[0]
|
||||
|
||||
return jsonify({"category": prediction})
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue