Spaces:
Sleeping
Sleeping
| 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) | |