Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,14 @@
|
|
| 1 |
-
|
| 2 |
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import numpy as np
|
| 5 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# Set random seed for reproducibility
|
| 8 |
np.random.seed(42)
|
|
@@ -46,17 +52,6 @@ ecommerce_data = pd.DataFrame({
|
|
| 46 |
"Demand": demand
|
| 47 |
})
|
| 48 |
|
| 49 |
-
# Display the first few rows of the dataset
|
| 50 |
-
ecommerce_data.head()
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
import streamlit as st
|
| 56 |
-
import pandas as pd
|
| 57 |
-
import matplotlib.pyplot as plt
|
| 58 |
-
import seaborn as sns
|
| 59 |
-
|
| 60 |
# Load the synthetic dataset (Replace this with actual dataset loading)
|
| 61 |
@st.cache_data
|
| 62 |
def load_data():
|
|
@@ -65,8 +60,6 @@ def load_data():
|
|
| 65 |
data = load_data()
|
| 66 |
|
| 67 |
# Streamlit UI Configuration
|
| 68 |
-
|
| 69 |
-
# Sidebar Navigation
|
| 70 |
st.sidebar.title("Navigation")
|
| 71 |
page = st.sidebar.selectbox("Choose a Page", ["Introduction", "Visualizations", "Solution Implementation"])
|
| 72 |
|
|
@@ -124,152 +117,3 @@ elif page == "Solution Implementation":
|
|
| 124 |
- Analyze results and fine-tune the pricing strategy dynamically.
|
| 125 |
""")
|
| 126 |
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
import streamlit as st
|
| 134 |
-
|
| 135 |
-
# Streamlit UI
|
| 136 |
-
st.title("Streamlit in Google Colab")
|
| 137 |
-
st.write("This is a test application running inside Google Colab using ngrok.")
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
import streamlit as st
|
| 148 |
-
import matplotlib.pyplot as plt
|
| 149 |
-
import numpy as np
|
| 150 |
-
from sklearn.linear_model import LinearRegression
|
| 151 |
-
from sklearn.cluster import KMeans
|
| 152 |
-
import pandas as pd
|
| 153 |
-
|
| 154 |
-
# App Title
|
| 155 |
-
st.title("Business Performance Analysis")
|
| 156 |
-
|
| 157 |
-
# Sidebar Navigation
|
| 158 |
-
st.sidebar.header("Navigation")
|
| 159 |
-
page = st.sidebar.selectbox("Select a Page", ["Introduction", "Visualizations", "Solution", "Forecasting", "Customer Segmentation", "Expense Optimization", "Goal Tracker"])
|
| 160 |
-
|
| 161 |
-
# Page 1: Introduction
|
| 162 |
-
if page == "Introduction":
|
| 163 |
-
st.header("📌 Introduction")
|
| 164 |
-
st.markdown("""
|
| 165 |
-
## Understanding the Business Problem
|
| 166 |
-
Businesses today face significant challenges in optimizing **profitability, reducing costs, and maximizing customer value**.
|
| 167 |
-
Here are three key business issues:
|
| 168 |
-
|
| 169 |
-
1️⃣ **Revenue and Profitability Issues**
|
| 170 |
-
- Unpredictable revenue impacts long-term growth.
|
| 171 |
-
- High operational costs reduce net profit margins.
|
| 172 |
-
|
| 173 |
-
2️⃣ **Customer Retention & Engagement**
|
| 174 |
-
- Businesses struggle to understand customer behavior.
|
| 175 |
-
- Acquiring new customers is costlier than retaining existing ones.
|
| 176 |
-
|
| 177 |
-
3️⃣ **Data-Driven Decision Making**
|
| 178 |
-
- Many businesses lack real-time insights.
|
| 179 |
-
- Without proper data analysis, decisions are based on intuition rather than facts.
|
| 180 |
-
|
| 181 |
-
### 🔍 Our Key Approaches
|
| 182 |
-
- **Revenue & Cost Analysis**
|
| 183 |
-
- **Data Visualization for Business Insights**
|
| 184 |
-
- **Strategic Business Solutions**
|
| 185 |
-
- **Forecasting Future Trends**
|
| 186 |
-
- **Competitor Benchmarking**
|
| 187 |
-
- **Customer Segmentation**
|
| 188 |
-
- **Expense Optimization**
|
| 189 |
-
- **Goal Tracking & Business Strategy**
|
| 190 |
-
""")
|
| 191 |
-
|
| 192 |
-
# Page 2: Visualizations
|
| 193 |
-
elif page == "Visualizations":
|
| 194 |
-
st.header("📊 Business Data Visualizations")
|
| 195 |
-
st.subheader("📈 Revenue vs Costs")
|
| 196 |
-
revenue = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
|
| 197 |
-
costs = st.sidebar.number_input("Monthly Costs ($)", min_value=0, value=5000)
|
| 198 |
-
fig, ax = plt.subplots()
|
| 199 |
-
ax.bar(["Revenue", "Costs"], [revenue, costs], color=['green', 'red'])
|
| 200 |
-
st.pyplot(fig)
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
# Page 3: Solution
|
| 205 |
-
elif page == "Solution":
|
| 206 |
-
st.header("📈 Business Solution & Insights")
|
| 207 |
-
st.subheader("📊 Key Business Metrics")
|
| 208 |
-
# Define revenue and costs globally so they can be accessed on multiple pages
|
| 209 |
-
revenues = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
|
| 210 |
-
costs = st.sidebar.number_input("Monthly Costs ($)", min_value=0, value=5000)
|
| 211 |
-
|
| 212 |
-
# Calculate profit using global revenue and costs
|
| 213 |
-
profit = revenues - costs
|
| 214 |
-
|
| 215 |
-
# Display the result
|
| 216 |
-
st.metric(label="Total Profit ($)", value=f"${profit:,.2f}")
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
# Page 4: Forecasting
|
| 220 |
-
elif page == "Forecasting":
|
| 221 |
-
st.header("📈 Future Revenue Prediction")
|
| 222 |
-
months = np.array([1, 2, 3, 4, 5, 6]).reshape(-1, 1)
|
| 223 |
-
revenue_data = np.array([8000, 8500, 9000, 9400, 10000, 10500])
|
| 224 |
-
model = LinearRegression()
|
| 225 |
-
model.fit(months, revenue_data)
|
| 226 |
-
future_months = np.array([7, 8, 9]).reshape(-1, 1)
|
| 227 |
-
predicted_revenue = model.predict(future_months)
|
| 228 |
-
st.line_chart(np.append(revenue_data, predicted_revenue))
|
| 229 |
-
|
| 230 |
-
# Page 5: Customer Segmentation
|
| 231 |
-
elif page == "Customer Segmentation":
|
| 232 |
-
st.header("🛒 Customer Segmentation")
|
| 233 |
-
customer_data = pd.DataFrame({
|
| 234 |
-
'revenue': [200, 500, 800, 1200, 1500, 300],
|
| 235 |
-
'purchases': [2, 5, 8, 12, 15, 3]
|
| 236 |
-
})
|
| 237 |
-
kmeans = KMeans(n_clusters=3)
|
| 238 |
-
customer_data['segment'] = kmeans.fit_predict(customer_data)
|
| 239 |
-
st.scatter_chart(customer_data, x='revenue', y='purchases', color='segment')
|
| 240 |
-
|
| 241 |
-
# Page 6: Expense Optimization
|
| 242 |
-
elif page == "Expense Optimization":
|
| 243 |
-
st.header("💰 Expense Optimization")
|
| 244 |
-
expense_categories = ["Marketing", "Salaries", "Infrastructure", "Miscellaneous"]
|
| 245 |
-
expenses = [3000, 5000, 2000, 1000]
|
| 246 |
-
fig, ax = plt.subplots()
|
| 247 |
-
ax.pie(expenses, labels=expense_categories, autopct='%1.1f%%', startangle=140)
|
| 248 |
-
st.pyplot(fig)
|
| 249 |
-
|
| 250 |
-
# Page 7: Goal Tracker
|
| 251 |
-
elif page == "Goal Tracker":
|
| 252 |
-
st.header("🎯 Business Goal Tracker")
|
| 253 |
-
|
| 254 |
-
# User inputs revenue goal
|
| 255 |
-
goal = st.number_input("Enter your revenue goal ($)", min_value=0)
|
| 256 |
-
|
| 257 |
-
# User inputs monthly revenue
|
| 258 |
-
revenue = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000)
|
| 259 |
-
|
| 260 |
-
# Check if the goal is met
|
| 261 |
-
if goal < revenue:
|
| 262 |
-
st.warning("You have reached your revenue goal yet.")
|
| 263 |
-
else:
|
| 264 |
-
progress = (revenue / goal) * 100 if goal else 0
|
| 265 |
-
st.progress(progress / 100)
|
| 266 |
-
st.write(f"**Progress:** {progress:.2f}% of goal achieved")
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
|
| 3 |
+
# Set Streamlit page configuration at the very top
|
| 4 |
+
st.set_page_config(page_title="E-Commerce Pricing Optimization", layout="wide")
|
| 5 |
|
| 6 |
import numpy as np
|
| 7 |
import pandas as pd
|
| 8 |
+
import matplotlib.pyplot as plt
|
| 9 |
+
import seaborn as sns
|
| 10 |
+
from sklearn.linear_model import LinearRegression
|
| 11 |
+
from sklearn.cluster import KMeans
|
| 12 |
|
| 13 |
# Set random seed for reproducibility
|
| 14 |
np.random.seed(42)
|
|
|
|
| 52 |
"Demand": demand
|
| 53 |
})
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
# Load the synthetic dataset (Replace this with actual dataset loading)
|
| 56 |
@st.cache_data
|
| 57 |
def load_data():
|
|
|
|
| 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 |
|
|
|
|
| 117 |
- Analyze results and fine-tune the pricing strategy dynamically.
|
| 118 |
""")
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|