Anushree2000 commited on
Commit
f24789e
Β·
verified Β·
1 Parent(s): 525e0e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +107 -44
app.py CHANGED
@@ -59,61 +59,124 @@ def load_data():
59
 
60
  data = load_data()
61
 
62
- # Streamlit UI Configuration
63
- st.sidebar.title("Navigation")
64
- page = st.sidebar.selectbox("Choose a Page", ["Introduction", "Visualizations", "Solution Implementation"])
 
 
 
 
 
 
 
 
 
 
 
65
 
 
66
  if page == "Introduction":
67
- st.title("E-Commerce Pricing Optimization")
68
- st.write("""
69
- **Business Problem:**
70
- - E-commerce companies struggle to set optimal prices that maximize revenue while staying competitive.
71
- - Prices need to adjust dynamically based on demand, competitor pricing, and seasonal trends.
72
-
73
- **Solution Approach:**
74
- - Use **Multi-Armed Bandits** for adaptive pricing strategy.
75
- - Apply **Bayesian Networks** to predict customer demand based on price.
76
- - Use **Multi-Criteria Decision Making (AHP)** to decide the best price based on multiple factors.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
77
  """)
78
 
 
79
  elif page == "Visualizations":
80
- st.title("Data Visualizations")
81
-
82
- # Plot 1: Price Distribution Across Categories
83
- st.subheader("Price Distribution Across Categories")
84
  fig, ax = plt.subplots()
85
- sns.boxplot(x="Category", y="Base_Price", data=data, ax=ax, palette="Set2")
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
- # Plot 4: Price vs. Demand Relationship
102
- st.subheader("Price vs. Demand Relationship")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  fig, ax = plt.subplots()
104
- sns.scatterplot(x="Base_Price", y="Demand", data=data, color="red", alpha=0.7, ax=ax)
105
  st.pyplot(fig)
106
 
107
- elif page == "Solution Implementation":
108
- st.title("Solution Implementation")
109
- st.write("""
110
- **Concepts Used:**
111
- - **Multi-Armed Bandits**: To continuously optimize pricing strategy.
112
- - **Bayesian Networks**: To model demand uncertainty based on price changes.
113
- - **Multi-Criteria Decision Making (AHP)**: To balance revenue, demand, and competitiveness.
114
-
115
- **Next Steps:**
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")