Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -59,61 +59,124 @@ def load_data():
|
|
| 59 |
|
| 60 |
data = load_data()
|
| 61 |
|
| 62 |
-
|
| 63 |
-
st
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
|
|
|
| 66 |
if page == "Introduction":
|
| 67 |
-
st.
|
| 68 |
-
st.
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
**
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
""")
|
| 78 |
|
|
|
|
| 79 |
elif page == "Visualizations":
|
| 80 |
-
st.
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
st.
|
| 84 |
fig, ax = plt.subplots()
|
| 85 |
-
|
| 86 |
-
plt.xticks(rotation=30)
|
| 87 |
st.pyplot(fig)
|
| 88 |
|
| 89 |
-
# Plot 2: Competitor Price vs. Base Price
|
| 90 |
-
st.subheader("Competitor Price vs. Base Price")
|
| 91 |
-
fig, ax = plt.subplots()
|
| 92 |
-
sns.scatterplot(x="Base_Price", y="Competitor_Price", data=data, color="blue", alpha=0.7, ax=ax)
|
| 93 |
-
st.pyplot(fig)
|
| 94 |
|
| 95 |
-
# Plot 3: Seasonality Impact on Demand
|
| 96 |
-
st.subheader("Seasonality Impact on Demand")
|
| 97 |
-
fig, ax = plt.subplots()
|
| 98 |
-
sns.scatterplot(x="Seasonality_Factor", y="Demand", data=data, color="green", alpha=0.7, ax=ax)
|
| 99 |
-
st.pyplot(fig)
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
fig, ax = plt.subplots()
|
| 104 |
-
|
| 105 |
st.pyplot(fig)
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
st.
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
- Implement these models and test them in a real-world simulation.
|
| 117 |
-
- Analyze results and fine-tune the pricing strategy dynamically.
|
| 118 |
-
""")
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
data = load_data()
|
| 61 |
|
| 62 |
+
%%writefile app.py
|
| 63 |
+
import streamlit as st
|
| 64 |
+
import matplotlib.pyplot as plt
|
| 65 |
+
import numpy as np
|
| 66 |
+
from sklearn.linear_model import LinearRegression
|
| 67 |
+
from sklearn.cluster import KMeans
|
| 68 |
+
import pandas as pd
|
| 69 |
+
|
| 70 |
+
# App Title
|
| 71 |
+
st.title("Business Performance Analysis")
|
| 72 |
+
|
| 73 |
+
# Sidebar Navigation
|
| 74 |
+
st.sidebar.header("Navigation")
|
| 75 |
+
page = st.sidebar.selectbox("Select a Page", ["Introduction", "Visualizations", "Solution", "Forecasting", "Customer Segmentation", "Expense Optimization", "Goal Tracker"])
|
| 76 |
|
| 77 |
+
# Page 1: Introduction
|
| 78 |
if page == "Introduction":
|
| 79 |
+
st.header("π Introduction")
|
| 80 |
+
st.markdown("""
|
| 81 |
+
## Understanding the Business Problem
|
| 82 |
+
Businesses today face significant challenges in optimizing **profitability, reducing costs, and maximizing customer value**.
|
| 83 |
+
Here are three key business issues:
|
| 84 |
+
|
| 85 |
+
1οΈβ£ **Revenue and Profitability Issues**
|
| 86 |
+
- Unpredictable revenue impacts long-term growth.
|
| 87 |
+
- High operational costs reduce net profit margins.
|
| 88 |
+
|
| 89 |
+
2οΈβ£ **Customer Retention & Engagement**
|
| 90 |
+
- Businesses struggle to understand customer behavior.
|
| 91 |
+
- Acquiring new customers is costlier than retaining existing ones.
|
| 92 |
+
|
| 93 |
+
3οΈβ£ **Data-Driven Decision Making**
|
| 94 |
+
- Many businesses lack real-time insights.
|
| 95 |
+
- Without proper data analysis, decisions are based on intuition rather than facts.
|
| 96 |
+
|
| 97 |
+
### π Our Key Approaches
|
| 98 |
+
- **Revenue & Cost Analysis**
|
| 99 |
+
- **Data Visualization for Business Insights**
|
| 100 |
+
- **Strategic Business Solutions**
|
| 101 |
+
- **Forecasting Future Trends**
|
| 102 |
+
- **Competitor Benchmarking**
|
| 103 |
+
- **Customer Segmentation**
|
| 104 |
+
- **Expense Optimization**
|
| 105 |
+
- **Goal Tracking & Business Strategy**
|
| 106 |
""")
|
| 107 |
|
| 108 |
+
# Page 2: Visualizations
|
| 109 |
elif page == "Visualizations":
|
| 110 |
+
st.header("π Business Data Visualizations")
|
| 111 |
+
st.subheader("π Revenue vs Costs")
|
| 112 |
+
revenue = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
|
| 113 |
+
costs = st.sidebar.number_input("Monthly Costs ($)", min_value=0, value=5000)
|
| 114 |
fig, ax = plt.subplots()
|
| 115 |
+
ax.bar(["Revenue", "Costs"], [revenue, costs], color=['green', 'red'])
|
|
|
|
| 116 |
st.pyplot(fig)
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
|
| 120 |
+
# Page 3: Solution
|
| 121 |
+
elif page == "Solution":
|
| 122 |
+
st.header("π Business Solution & Insights")
|
| 123 |
+
st.subheader("π Key Business Metrics")
|
| 124 |
+
# Define revenue and costs globally so they can be accessed on multiple pages
|
| 125 |
+
revenues = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
|
| 126 |
+
costs = st.sidebar.number_input("Monthly Costs ($)", min_value=0, value=5000)
|
| 127 |
+
|
| 128 |
+
# Calculate profit using global revenue and costs
|
| 129 |
+
profit = revenues - costs
|
| 130 |
+
|
| 131 |
+
# Display the result
|
| 132 |
+
st.metric(label="Total Profit ($)", value=f"${profit:,.2f}")
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
# Page 4: Forecasting
|
| 136 |
+
elif page == "Forecasting":
|
| 137 |
+
st.header("π Future Revenue Prediction")
|
| 138 |
+
months = np.array([1, 2, 3, 4, 5, 6]).reshape(-1, 1)
|
| 139 |
+
revenue_data = np.array([8000, 8500, 9000, 9400, 10000, 10500])
|
| 140 |
+
model = LinearRegression()
|
| 141 |
+
model.fit(months, revenue_data)
|
| 142 |
+
future_months = np.array([7, 8, 9]).reshape(-1, 1)
|
| 143 |
+
predicted_revenue = model.predict(future_months)
|
| 144 |
+
st.line_chart(np.append(revenue_data, predicted_revenue))
|
| 145 |
+
|
| 146 |
+
# Page 5: Customer Segmentation
|
| 147 |
+
elif page == "Customer Segmentation":
|
| 148 |
+
st.header("π Customer Segmentation")
|
| 149 |
+
customer_data = pd.DataFrame({
|
| 150 |
+
'revenue': [200, 500, 800, 1200, 1500, 300],
|
| 151 |
+
'purchases': [2, 5, 8, 12, 15, 3]
|
| 152 |
+
})
|
| 153 |
+
kmeans = KMeans(n_clusters=3)
|
| 154 |
+
customer_data['segment'] = kmeans.fit_predict(customer_data)
|
| 155 |
+
st.scatter_chart(customer_data, x='revenue', y='purchases', color='segment')
|
| 156 |
+
|
| 157 |
+
# Page 6: Expense Optimization
|
| 158 |
+
elif page == "Expense Optimization":
|
| 159 |
+
st.header("π° Expense Optimization")
|
| 160 |
+
expense_categories = ["Marketing", "Salaries", "Infrastructure", "Miscellaneous"]
|
| 161 |
+
expenses = [3000, 5000, 2000, 1000]
|
| 162 |
fig, ax = plt.subplots()
|
| 163 |
+
ax.pie(expenses, labels=expense_categories, autopct='%1.1f%%', startangle=140)
|
| 164 |
st.pyplot(fig)
|
| 165 |
|
| 166 |
+
# Page 7: Goal Tracker
|
| 167 |
+
elif page == "Goal Tracker":
|
| 168 |
+
st.header("π― Business Goal Tracker")
|
| 169 |
+
|
| 170 |
+
# User inputs revenue goal
|
| 171 |
+
goal = st.number_input("Enter your revenue goal ($)", min_value=0)
|
| 172 |
+
|
| 173 |
+
# User inputs monthly revenue
|
| 174 |
+
revenue = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
+
# Check if the goal is met
|
| 177 |
+
if goal < revenue:
|
| 178 |
+
st.warning("You have reached your revenue goal yet.")
|
| 179 |
+
else:
|
| 180 |
+
progress = (revenue / goal) * 100 if goal else 0
|
| 181 |
+
st.progress(progress / 100)
|
| 182 |
+
st.write(f"**Progress:** {progress:.2f}% of goal achieved")
|