└── Main /Main: -------------------------------------------------------------------------------- 1 | import pytesseract 2 | import pandas as pd 3 | import matplotlib.pyplot as plt 4 | from PIL import Image 5 | 6 | def extract_amount(text): 7 | words = text.split() 8 | for word in words: 9 | if word.replace(".", "").isdigit(): 10 | return float(word) 11 | return 0 12 | 13 | def analyze_expenses(receipts): 14 | categories = {"Food": 0, "Transport": 0, "Shopping": 0, "Other": 0} 15 | 16 | for receipt in receipts: 17 | text = pytesseract.image_to_string(Image.open(receipt)).lower() 18 | amount = extract_amount(text) 19 | 20 | if "food" in text or "restaurant" in text: 21 | categories["Food"] += amount 22 | elif "uber" in text or "bus" in text: 23 | categories["Transport"] += amount 24 | elif "shop" in text or "store" in text: 25 | categories["Shopping"] += amount 26 | else: 27 | categories["Other"] += amount 28 | 29 | return categories 30 | 31 | def plot_expenses(categories): 32 | plt.bar(categories.keys(), categories.values(), color=["blue", "green", "red", "purple"]) 33 | plt.xlabel("Categories") 34 | plt.ylabel("Amount Spent") 35 | plt.title("Expense Analysis") 36 | plt.show() 37 | 38 | if __name__ == "__main__": 39 | receipts = ["receipt1.jpg", "receipt2.jpg"] # Replace with actual file names 40 | expense_data = analyze_expenses(receipts) 41 | print(expense_data) 42 | plot_expenses(expense_data) 43 | --------------------------------------------------------------------------------