Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import pandas as pd | |
| st.set_page_config(page_title="Xpense Tracker", page_icon="π°", layout="centered") | |
| st.title("ποΈ Small Business / Xpense Tracker") | |
| # Number of products | |
| num_products = st.number_input("Enter number of products:", min_value=1, step=1) | |
| # Store product data | |
| products = [] | |
| for i in range(int(num_products)): | |
| st.subheader(f"Product {i+1}") | |
| name = st.text_input(f"Name of Product {i+1}", key=f"name{i}") | |
| expense = st.number_input(f"Expense for {name or f'Product {i+1}'}", min_value=0.0, step=0.01, key=f"exp{i}") | |
| sales = st.number_input(f"Sales for {name or f'Product {i+1}'}", min_value=0.0, step=0.01, key=f"sale{i}") | |
| profit = sales - expense | |
| products.append({"Product": name or f"Product {i+1}", "Expense": expense, "Sales": sales, "Profit": profit}) | |
| # Convert to DataFrame | |
| df = pd.DataFrame(products) | |
| if not df.empty: | |
| st.subheader("π Product-wise Details") | |
| st.dataframe(df, use_container_width=True) | |
| st.subheader("π Totals") | |
| total_expense = df['Expense'].sum() | |
| total_sales = df['Sales'].sum() | |
| total_profit = df['Profit'].sum() | |
| st.write(f"**Total Expenses:** {total_expense:.2f}") | |
| st.write(f"**Total Sales:** {total_sales:.2f}") | |
| st.write(f"**Total Profit:** {total_profit:.2f}") | |
| # π Simple Streamlit Graphs | |
| st.subheader("π Visual Analysis") | |
| # Bar chart comparing Expenses, Sales, Profit | |
| st.bar_chart(df.set_index("Product")[["Expense", "Sales", "Profit"]]) | |
| # Line chart for trends (optional) | |
| st.line_chart(df.set_index("Product")[["Sales", "Profit"]]) | |