import streamlit as st # Set Streamlit page configuration at the very top st.set_page_config(page_title="E-Commerce Pricing Optimization", layout="wide") import numpy as np import pandas as pd import matplotlib.pyplot as plt # Set random seed for reproducibility np.random.seed(42) # Generate synthetic data for an e-commerce store num_products = 100 # Number of products # Product categories categories = ["Electronics", "Clothing", "Home & Kitchen", "Beauty", "Sports"] product_names = [f"Product_{i+1}" for i in range(num_products)] category_data = np.random.choice(categories, num_products) # Base price range per category price_ranges = { "Electronics": (50, 500), "Clothing": (10, 100), "Home & Kitchen": (20, 300), "Beauty": (5, 50), "Sports": (15, 200), } # Generate base prices based on category base_prices = [np.random.uniform(*price_ranges[cat]) for cat in category_data] # Competitor pricing (fluctuating around base price) competitor_prices = [price * np.random.uniform(0.9, 1.1) for price in base_prices] # Seasonal demand factor (scale between 0.5 and 1.5) seasonality = np.random.uniform(0.5, 1.5, num_products) # Customer demand (influenced by price and seasonality) demand = [(200 / price) * season * np.random.uniform(0.8, 1.2) for price, season in zip(base_prices, seasonality)] # Assemble dataset ecommerce_data = pd.DataFrame({ "Product": product_names, "Category": category_data, "Base_Price": base_prices, "Competitor_Price": competitor_prices, "Seasonality_Factor": seasonality, "Demand": demand }) # Load the synthetic dataset (Replace this with actual dataset loading) @st.cache_data def load_data(): return ecommerce_data # Use the generated dataset from previous steps data = load_data() import streamlit as st import matplotlib.pyplot as plt import numpy as np from sklearn.linear_model import LinearRegression from sklearn.cluster import KMeans import pandas as pd # App Title st.title("Business Performance Analysis") # Sidebar Navigation st.sidebar.header("Navigation") page = st.sidebar.selectbox("Select a Page", ["Introduction", "Visualizations", "Solution", "Forecasting", "Customer Segmentation", "Expense Optimization", "Goal Tracker"]) # Page 1: Introduction if page == "Introduction": st.header("📌 Introduction") st.markdown(""" ## Understanding the Business Problem Businesses today face significant challenges in optimizing **profitability, reducing costs, and maximizing customer value**. Here are three key business issues: 1️⃣ **Revenue and Profitability Issues** - Unpredictable revenue impacts long-term growth. - High operational costs reduce net profit margins. 2️⃣ **Customer Retention & Engagement** - Businesses struggle to understand customer behavior. - Acquiring new customers is costlier than retaining existing ones. 3️⃣ **Data-Driven Decision Making** - Many businesses lack real-time insights. - Without proper data analysis, decisions are based on intuition rather than facts. ### 🔍 Our Key Approaches - **Revenue & Cost Analysis** - **Data Visualization for Business Insights** - **Strategic Business Solutions** - **Forecasting Future Trends** - **Competitor Benchmarking** - **Customer Segmentation** - **Expense Optimization** - **Goal Tracking & Business Strategy** """) # Page 2: Visualizations elif page == "Visualizations": st.header("📊 Business Data Visualizations") st.subheader("📈 Revenue vs Costs") revenue = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000) costs = st.sidebar.number_input("Monthly Costs ($)", min_value=0, value=5000) fig, ax = plt.subplots() ax.bar(["Revenue", "Costs"], [revenue, costs], color=['green', 'red']) st.pyplot(fig) # Page 3: Solution elif page == "Solution": st.header("📈 Business Solution & Insights") st.subheader("📊 Key Business Metrics") # Define revenue and costs globally so they can be accessed on multiple pages revenues = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000) costs = st.sidebar.number_input("Monthly Costs ($)", min_value=0, value=5000) # Calculate profit using global revenue and costs profit = revenues - costs # Display the result st.metric(label="Total Profit ($)", value=f"${profit:,.2f}") # Page 4: Forecasting elif page == "Forecasting": st.header("📈 Future Revenue Prediction") months = np.array([1, 2, 3, 4, 5, 6]).reshape(-1, 1) revenue_data = np.array([8000, 8500, 9000, 9400, 10000, 10500]) model = LinearRegression() model.fit(months, revenue_data) future_months = np.array([7, 8, 9]).reshape(-1, 1) predicted_revenue = model.predict(future_months) st.line_chart(np.append(revenue_data, predicted_revenue)) # Page 5: Customer Segmentation elif page == "Customer Segmentation": st.header("🛒 Customer Segmentation") customer_data = pd.DataFrame({ 'revenue': [200, 500, 800, 1200, 1500, 300], 'purchases': [2, 5, 8, 12, 15, 3] }) kmeans = KMeans(n_clusters=3) customer_data['segment'] = kmeans.fit_predict(customer_data) st.scatter_chart(customer_data, x='revenue', y='purchases', color='segment') # Page 6: Expense Optimization elif page == "Expense Optimization": st.header("💰 Expense Optimization") expense_categories = ["Marketing", "Salaries", "Infrastructure", "Miscellaneous"] expenses = [3000, 5000, 2000, 1000] fig, ax = plt.subplots() ax.pie(expenses, labels=expense_categories, autopct='%1.1f%%', startangle=140) st.pyplot(fig) # Page 7: Goal Tracker elif page == "Goal Tracker": st.header("🎯 Business Goal Tracker") # User inputs revenue goal goal = st.number_input("Enter your revenue goal ($)", min_value=0) # User inputs monthly revenue revenue = st.sidebar.number_input("Monthly Revenue ($)", min_value=0, value=10000) # Check if the goal is met if goal < revenue: st.warning("You have reached your revenue goal yet.") else: progress = (revenue / goal) * 100 if goal else 0 st.progress(progress / 100) st.write(f"**Progress:** {progress:.2f}% of goal achieved")