Anushree2000 commited on
Commit
1b44a2c
·
verified ·
1 Parent(s): 742ac58

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -272
app.py DELETED
@@ -1,272 +0,0 @@
1
-
2
-
3
- import numpy as np
4
- import pandas as pd
5
-
6
- # Set random seed for reproducibility
7
- np.random.seed(42)
8
-
9
- # Generate synthetic data for an e-commerce store
10
- num_products = 100 # Number of products
11
-
12
- # Product categories
13
- categories = ["Electronics", "Clothing", "Home & Kitchen", "Beauty", "Sports"]
14
- product_names = [f"Product_{i+1}" for i in range(num_products)]
15
- category_data = np.random.choice(categories, num_products)
16
-
17
- # Base price range per category
18
- price_ranges = {
19
- "Electronics": (50, 500),
20
- "Clothing": (10, 100),
21
- "Home & Kitchen": (20, 300),
22
- "Beauty": (5, 50),
23
- "Sports": (15, 200),
24
- }
25
-
26
- # Generate base prices based on category
27
- base_prices = [np.random.uniform(*price_ranges[cat]) for cat in category_data]
28
-
29
- # Competitor pricing (fluctuating around base price)
30
- competitor_prices = [price * np.random.uniform(0.9, 1.1) for price in base_prices]
31
-
32
- # Seasonal demand factor (scale between 0.5 and 1.5)
33
- seasonality = np.random.uniform(0.5, 1.5, num_products)
34
-
35
- # Customer demand (influenced by price and seasonality)
36
- demand = [(200 / price) * season * np.random.uniform(0.8, 1.2) for price, season in zip(base_prices, seasonality)]
37
-
38
- # Assemble dataset
39
- ecommerce_data = pd.DataFrame({
40
- "Product": product_names,
41
- "Category": category_data,
42
- "Base_Price": base_prices,
43
- "Competitor_Price": competitor_prices,
44
- "Seasonality_Factor": seasonality,
45
- "Demand": demand
46
- })
47
-
48
- # Display the first few rows of the dataset
49
- ecommerce_data.head()
50
-
51
-
52
-
53
-
54
- import streamlit as st
55
- import pandas as pd
56
- import matplotlib.pyplot as plt
57
-
58
-
59
- # Load the synthetic dataset (Replace this with actual dataset loading)
60
- @st.cache_data
61
- def load_data():
62
- return ecommerce_data # Use the generated dataset from previous steps
63
-
64
- data = load_data()
65
-
66
- # Streamlit UI Configuration
67
- st.set_page_config(page_title="E-Commerce Pricing Optimization", layout="wide")
68
-
69
- # Sidebar Navigation
70
- st.sidebar.title("Navigation")
71
- page = st.sidebar.selectbox("Choose a Page", ["Introduction", "Visualizations", "Solution Implementation"])
72
-
73
- if page == "Introduction":
74
- st.title("E-Commerce Pricing Optimization")
75
- st.write("""
76
- **Business Problem:**
77
- - E-commerce companies struggle to set optimal prices that maximize revenue while staying competitive.
78
- - Prices need to adjust dynamically based on demand, competitor pricing, and seasonal trends.
79
-
80
- **Solution Approach:**
81
- - Use **Multi-Armed Bandits** for adaptive pricing strategy.
82
- - Apply **Bayesian Networks** to predict customer demand based on price.
83
- - Use **Multi-Criteria Decision Making (AHP)** to decide the best price based on multiple factors.
84
- """)
85
-
86
- elif page == "Visualizations":
87
- st.title("Data Visualizations")
88
-
89
- # Plot 1: Price Distribution Across Categories
90
- st.subheader("Price Distribution Across Categories")
91
- fig, ax = plt.subplots()
92
- sns.boxplot(x="Category", y="Base_Price", data=data, ax=ax, palette="Set2")
93
- plt.xticks(rotation=30)
94
- st.pyplot(fig)
95
-
96
- # Plot 2: Competitor Price vs. Base Price
97
- st.subheader("Competitor Price vs. Base Price")
98
- fig, ax = plt.subplots()
99
- sns.scatterplot(x="Base_Price", y="Competitor_Price", data=data, color="blue", alpha=0.7, ax=ax)
100
- st.pyplot(fig)
101
-
102
- # Plot 3: Seasonality Impact on Demand
103
- st.subheader("Seasonality Impact on Demand")
104
- fig, ax = plt.subplots()
105
- sns.scatterplot(x="Seasonality_Factor", y="Demand", data=data, color="green", alpha=0.7, ax=ax)
106
- st.pyplot(fig)
107
-
108
- # Plot 4: Price vs. Demand Relationship
109
- st.subheader("Price vs. Demand Relationship")
110
- fig, ax = plt.subplots()
111
- sns.scatterplot(x="Base_Price", y="Demand", data=data, color="red", alpha=0.7, ax=ax)
112
- st.pyplot(fig)
113
-
114
- elif page == "Solution Implementation":
115
- st.title("Solution Implementation")
116
- st.write("""
117
- **Concepts Used:**
118
- - **Multi-Armed Bandits**: To continuously optimize pricing strategy.
119
- - **Bayesian Networks**: To model demand uncertainty based on price changes.
120
- - **Multi-Criteria Decision Making (AHP)**: To balance revenue, demand, and competitiveness.
121
-
122
- **Next Steps:**
123
- - Implement these models and test them in a real-world simulation.
124
- - Analyze results and fine-tune the pricing strategy dynamically.
125
- """)
126
-
127
-
128
-
129
-
130
-
131
- import streamlit as st
132
-
133
- # Streamlit UI
134
- st.title("Streamlit in Google Colab")
135
- st.write("This is a test application running inside Google Colab using ngrok.")
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
- import streamlit as st
145
- import matplotlib.pyplot as plt
146
- import numpy as np
147
- from sklearn.linear_model import LinearRegression
148
- from sklearn.cluster import KMeans
149
- import pandas as pd
150
-
151
- # App Title
152
- st.title("Business Performance Analysis")
153
-
154
- # Sidebar Navigation
155
- st.sidebar.header("Navigation")
156
- page = st.sidebar.selectbox("Select a Page", ["Introduction", "Visualizations", "Solution", "Forecasting", "Customer Segmentation", "Expense Optimization", "Goal Tracker"])
157
-
158
- # Page 1: Introduction
159
- if page == "Introduction":
160
- st.header("📌 Introduction")
161
- st.markdown("""
162
- ## Understanding the Business Problem
163
- Businesses today face significant challenges in optimizing **profitability, reducing costs, and maximizing customer value**.
164
- Here are three key business issues:
165
-
166
- 1️⃣ **Revenue and Profitability Issues**
167
- - Unpredictable revenue impacts long-term growth.
168
- - High operational costs reduce net profit margins.
169
-
170
- 2️⃣ **Customer Retention & Engagement**
171
- - Businesses struggle to understand customer behavior.
172
- - Acquiring new customers is costlier than retaining existing ones.
173
-
174
- 3️⃣ **Data-Driven Decision Making**
175
- - Many businesses lack real-time insights.
176
- - Without proper data analysis, decisions are based on intuition rather than facts.
177
-
178
- ### 🔍 Our Key Approaches
179
- - **Revenue & Cost Analysis**
180
- - **Data Visualization for Business Insights**
181
- - **Strategic Business Solutions**
182
- - **Forecasting Future Trends**
183
- - **Competitor Benchmarking**
184
- - **Customer Segmentation**
185
- - **Expense Optimization**
186
- - **Goal Tracking & Business Strategy**
187
- """)
188
-
189
- # Page 2: Visualizations
190
- elif page == "Visualizations":
191
- st.header("📊 Business Data Visualizations")
192
- st.subheader("📈 Revenue vs Costs")
193
- revenue = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
194
- costs = st.sidebar.number_input("Monthly Costs ($)", min_value=0, value=5000)
195
- fig, ax = plt.subplots()
196
- ax.bar(["Revenue", "Costs"], [revenue, costs], color=['green', 'red'])
197
- st.pyplot(fig)
198
-
199
-
200
-
201
- # Page 3: Solution
202
- elif page == "Solution":
203
- st.header("📈 Business Solution & Insights")
204
- st.subheader("📊 Key Business Metrics")
205
- # Define revenue and costs globally so they can be accessed on multiple pages
206
- revenues = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
207
- costs = st.sidebar.number_input("Monthly Costs ($)", min_value=0, value=5000)
208
-
209
- # Calculate profit using global revenue and costs
210
- profit = revenues - costs
211
-
212
- # Display the result
213
- st.metric(label="Total Profit ($)", value=f"${profit:,.2f}")
214
-
215
-
216
- # Page 4: Forecasting
217
- elif page == "Forecasting":
218
- st.header("📈 Future Revenue Prediction")
219
- months = np.array([1, 2, 3, 4, 5, 6]).reshape(-1, 1)
220
- revenue_data = np.array([8000, 8500, 9000, 9400, 10000, 10500])
221
- model = LinearRegression()
222
- model.fit(months, revenue_data)
223
- future_months = np.array([7, 8, 9]).reshape(-1, 1)
224
- predicted_revenue = model.predict(future_months)
225
- st.line_chart(np.append(revenue_data, predicted_revenue))
226
-
227
- # Page 5: Customer Segmentation
228
- elif page == "Customer Segmentation":
229
- st.header("🛒 Customer Segmentation")
230
- customer_data = pd.DataFrame({
231
- 'revenue': [200, 500, 800, 1200, 1500, 300],
232
- 'purchases': [2, 5, 8, 12, 15, 3]
233
- })
234
- kmeans = KMeans(n_clusters=3)
235
- customer_data['segment'] = kmeans.fit_predict(customer_data)
236
- st.scatter_chart(customer_data, x='revenue', y='purchases', color='segment')
237
-
238
- # Page 6: Expense Optimization
239
- elif page == "Expense Optimization":
240
- st.header("💰 Expense Optimization")
241
- expense_categories = ["Marketing", "Salaries", "Infrastructure", "Miscellaneous"]
242
- expenses = [3000, 5000, 2000, 1000]
243
- fig, ax = plt.subplots()
244
- ax.pie(expenses, labels=expense_categories, autopct='%1.1f%%', startangle=140)
245
- st.pyplot(fig)
246
-
247
- # Page 7: Goal Tracker
248
- elif page == "Goal Tracker":
249
- st.header("🎯 Business Goal Tracker")
250
-
251
- # User inputs revenue goal
252
- goal = st.number_input("Enter your revenue goal ($)", min_value=0)
253
-
254
- # User inputs monthly revenue
255
- revenue = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
256
-
257
- # Check if the goal is met
258
- if goal < revenue:
259
- st.warning("You have reached your revenue goal yet.")
260
- else:
261
- progress = (revenue / goal) * 100 if goal else 0
262
- st.progress(progress / 100)
263
- st.write(f"**Progress:** {progress:.2f}% of goal achieved")
264
-
265
-
266
-
267
-
268
-
269
-
270
-
271
-
272
-