Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,33 +2,65 @@ import streamlit as st
|
|
| 2 |
import pandas as pd
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
amounts = []
|
| 8 |
for category in categories:
|
| 9 |
amount = st.number_input(f"Enter amount for {category}:", min_value=0.0, step=1.0)
|
| 10 |
amounts.append(amount)
|
| 11 |
|
| 12 |
-
# Create DataFrame
|
| 13 |
df = pd.DataFrame({
|
| 14 |
"Category": categories,
|
| 15 |
"Amount": amounts
|
| 16 |
})
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
# ๐ฅง Pie chart
|
| 20 |
st.subheader("๐ฅง Expense Distribution")
|
| 21 |
-
fig1, ax1 = plt.subplots()
|
| 22 |
ax1.pie(df["Amount"], labels=df["Category"], autopct="%1.1f%%", startangle=90, colors=plt.cm.Paired.colors)
|
| 23 |
-
ax1.axis("equal")
|
| 24 |
st.pyplot(fig1)
|
| 25 |
|
| 26 |
# ๐ Bar chart
|
| 27 |
st.subheader("๐ Expense Comparison")
|
| 28 |
-
fig2, ax2 = plt.subplots()
|
| 29 |
ax2.bar(df["Category"], df["Amount"], color=plt.cm.Paired.colors)
|
| 30 |
ax2.set_ylabel("Amount (PKR)")
|
| 31 |
ax2.set_title("Monthly Expenses by Category")
|
|
|
|
| 32 |
st.pyplot(fig2)
|
|
|
|
| 33 |
else:
|
| 34 |
-
st.warning("Please enter some expenses to see charts.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import pandas as pd
|
| 3 |
import matplotlib.pyplot as plt
|
| 4 |
|
| 5 |
+
# Set the title and style of the page
|
| 6 |
+
st.set_page_config(page_title="Expense Tracker", page_icon="๐ธ", layout="wide")
|
| 7 |
+
st.title("๐ฐ Expense Tracker")
|
| 8 |
+
|
| 9 |
+
# Add a description to explain the app
|
| 10 |
+
st.write("""
|
| 11 |
+
This app helps you track your expenses across various categories.
|
| 12 |
+
Fill in the amounts for each category, and the app will generate charts to help you visualize your spending.
|
| 13 |
+
""")
|
| 14 |
+
|
| 15 |
+
# Create a list of expense categories
|
| 16 |
+
categories = [
|
| 17 |
+
"Food ๐", "Transport ๐", "Utilities ๐ก", "Entertainment ๐ฎ",
|
| 18 |
+
"Other ๐๏ธ", "School Fees ๐", "Health ๐", "Savings ๐ธ", "Charity ๐", "Vacation ๐๏ธ"
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
# Collect user input for each category
|
| 22 |
amounts = []
|
| 23 |
for category in categories:
|
| 24 |
amount = st.number_input(f"Enter amount for {category}:", min_value=0.0, step=1.0)
|
| 25 |
amounts.append(amount)
|
| 26 |
|
| 27 |
+
# Create a DataFrame from the user input
|
| 28 |
df = pd.DataFrame({
|
| 29 |
"Category": categories,
|
| 30 |
"Amount": amounts
|
| 31 |
})
|
| 32 |
|
| 33 |
+
# Show the data in a table format
|
| 34 |
+
st.subheader("๐ Expense Overview")
|
| 35 |
+
st.dataframe(df)
|
| 36 |
+
|
| 37 |
+
# Total expenses calculation
|
| 38 |
+
total_expenses = df["Amount"].sum()
|
| 39 |
+
|
| 40 |
+
# Display total expenses
|
| 41 |
+
st.markdown(f"### Total Expenses: ๐ธ **{total_expenses:.2f} PKR**")
|
| 42 |
+
|
| 43 |
+
# Generate the Pie chart and Bar chart if there are any expenses
|
| 44 |
+
if total_expenses > 0:
|
| 45 |
# ๐ฅง Pie chart
|
| 46 |
st.subheader("๐ฅง Expense Distribution")
|
| 47 |
+
fig1, ax1 = plt.subplots(figsize=(8, 6))
|
| 48 |
ax1.pie(df["Amount"], labels=df["Category"], autopct="%1.1f%%", startangle=90, colors=plt.cm.Paired.colors)
|
| 49 |
+
ax1.axis("equal") # Equal aspect ratio ensures that pie is drawn as a circle.
|
| 50 |
st.pyplot(fig1)
|
| 51 |
|
| 52 |
# ๐ Bar chart
|
| 53 |
st.subheader("๐ Expense Comparison")
|
| 54 |
+
fig2, ax2 = plt.subplots(figsize=(8, 6))
|
| 55 |
ax2.bar(df["Category"], df["Amount"], color=plt.cm.Paired.colors)
|
| 56 |
ax2.set_ylabel("Amount (PKR)")
|
| 57 |
ax2.set_title("Monthly Expenses by Category")
|
| 58 |
+
ax2.set_xticklabels(ax2.get_xticklabels(), rotation=45, ha="right")
|
| 59 |
st.pyplot(fig2)
|
| 60 |
+
|
| 61 |
else:
|
| 62 |
+
st.warning("Please enter some expenses to see the charts.")
|
| 63 |
+
|
| 64 |
+
# Add some fun interactivity with a slider
|
| 65 |
+
st.subheader("๐ก Quick Tip")
|
| 66 |
+
st.slider("What percentage of your expenses do you want to save this month?", 0, 100, 10)
|