import streamlit as st import pandas as pd import matplotlib.pyplot as plt # Set the title and style of the page st.set_page_config(page_title="Expense Tracker", page_icon="💸", layout="wide") st.title("💰 Expense Tracker") # Add a description to explain the app st.write(""" This app helps you track your expenses across various categories. Fill in the amounts for each category, and the app will generate charts to help you visualize your spending. """) # Create a list of expense categories categories = [ "Food 🍔", "Transport 🚗", "Utilities 💡", "Entertainment 🎮", "Other 🛍️", "School Fees 🎓", "Health 💊", "Savings 💸", "Charity 💖", "Vacation 🏖️" ] # Collect user input for each category amounts = [] for category in categories: amount = st.number_input(f"Enter amount for {category}:", min_value=0.0, step=1.0) amounts.append(amount) # Create a DataFrame from the user input df = pd.DataFrame({ "Category": categories, "Amount": amounts }) # Show the data in a table format st.subheader("📊 Expense Overview") st.dataframe(df) # Total expenses calculation total_expenses = df["Amount"].sum() # Display total expenses st.markdown(f"### Total Expenses: 💸 **{total_expenses:.2f} PKR**") # Generate the Pie chart and Bar chart if there are any expenses if total_expenses > 0: # 🥧 Pie chart st.subheader("🥧 Expense Distribution") fig1, ax1 = plt.subplots(figsize=(8, 6)) ax1.pie(df["Amount"], labels=df["Category"], autopct="%1.1f%%", startangle=90, colors=plt.cm.Paired.colors) ax1.axis("equal") # Equal aspect ratio ensures that pie is drawn as a circle. st.pyplot(fig1) # 📊 Bar chart st.subheader("📊 Expense Comparison") fig2, ax2 = plt.subplots(figsize=(8, 6)) ax2.bar(df["Category"], df["Amount"], color=plt.cm.Paired.colors) ax2.set_ylabel("Amount (PKR)") ax2.set_title("Monthly Expenses by Category") ax2.set_xticklabels(ax2.get_xticklabels(), rotation=45, ha="right") st.pyplot(fig2) else: st.warning("Please enter some expenses to see the charts.") # Add some fun interactivity with a slider st.subheader("💡 Quick Tip") st.slider("What percentage of your expenses do you want to save this month?", 0, 100, 10)