Spaces:
Sleeping
Sleeping
Delete app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "d904b962" }, "outputs": [], "source": [ "!pip install -r requirements.txt\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 206 }, "id": "a3GwBO8PF88q", "outputId": "0e89b22a-5942-48b0-f9b7-cd51f9ea97f8" }, "outputs": [ { "data": { "application/vnd.google.colaboratory.intrinsic+json": { "summary": "{\n \"name\": \"ecommerce_data\",\n \"rows\": 100,\n \"fields\": [\n {\n \"column\": \"Product\",\n \"properties\": {\n \"dtype\": \"string\",\n \"num_unique_values\": 100,\n \"samples\": [\n \"Product_84\",\n \"Product_54\",\n \"Product_71\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Category\",\n \"properties\": {\n \"dtype\": \"category\",\n \"num_unique_values\": 5,\n \"samples\": [\n \"Sports\",\n \"Electronics\",\n \"Home & Kitchen\"\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Base_Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 103.99778593633096,\n \"min\": 6.487282980524677,\n \"max\": 426.9695476582976,\n \"num_unique_values\": 100,\n \"samples\": [\n 88.78252185224231,\n 64.84128175272647,\n 205.28206161200734\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Competitor_Price\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 103.61148829537314,\n \"min\": 7.0927800355235515,\n \"max\": 418.15551513719623,\n \"num_unique_values\": 100,\n \"samples\": [\n 84.41732761253404,\n 67.03193226221237,\n 187.84730240434342\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Seasonality_Factor\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 0.29969008626449944,\n \"min\": 0.5153045402903847,\n \"max\": 1.481840888310531,\n \"num_unique_values\": 100,\n \"samples\": [\n 1.311204176736003,\n 0.8418796667164016,\n 1.433436308079483\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n },\n {\n \"column\": \"Demand\",\n \"properties\": {\n \"dtype\": \"number\",\n \"std\": 6.056754520232466,\n \"min\": 0.2958097058381191,\n \"max\": 39.906944745269236,\n \"num_unique_values\": 100,\n \"samples\": [\n 3.1676415776104316,\n 2.9778047625288178,\n 1.386311706800177\n ],\n \"semantic_type\": \"\",\n \"description\": \"\"\n }\n }\n ]\n}", "type": "dataframe", "variable_name": "ecommerce_data" }, "text/html": [ "\n", " <div id=\"df-5707720b-4164-4067-9219-8c294017aaec\" class=\"colab-df-container\">\n", " <div>\n", "<style scoped>\n", " .dataframe tbody tr th:only-of-type {\n", " vertical-align: middle;\n", " }\n", "\n", " .dataframe tbody tr th {\n", " vertical-align: top;\n", " }\n", "\n", " .dataframe thead th {\n", " text-align: right;\n", " }\n", "</style>\n", "<table border=\"1\" class=\"dataframe\">\n", " <thead>\n", " <tr style=\"text-align: right;\">\n", " <th></th>\n", " <th>Product</th>\n", " <th>Category</th>\n", " <th>Base_Price</th>\n", " <th>Competitor_Price</th>\n", " <th>Seasonality_Factor</th>\n", " <th>Demand</th>\n", " </tr>\n", " </thead>\n", " <tbody>\n", " <tr>\n", " <th>0</th>\n", " <td>Product_1</td>\n", " <td>Beauty</td>\n", " <td>46.173185</td>\n", " <td>47.795620</td>\n", " <td>0.550769</td>\n", " <td>2.381883</td>\n", " </tr>\n", " <tr>\n", " <th>1</th>\n", " <td>Product_2</td>\n", " <td>Sports</td>\n", " <td>172.257137</td>\n", " <td>180.360668</td>\n", " <td>1.386617</td>\n", " <td>1.734155</td>\n", " </tr>\n", " <tr>\n", " <th>2</th>\n", " <td>Product_3</td>\n", " <td>Home & Kitchen</td>\n", " <td>145.846189</td>\n", " <td>137.360030</td>\n", " <td>0.527617</td>\n", " <td>0.679632</td>\n", " </tr>\n", " <tr>\n", " <th>3</th>\n", " <td>Product_4</td>\n", " <td>Sports</td>\n", " <td>32.650872</td>\n", " <td>32.921534</td>\n", " <td>1.078865</td>\n", " <td>7.762725</td>\n", " </tr>\n", " <tr>\n", " <th>4</th>\n", " <td>Product_5</td>\n", " <td>Sports</td>\n", " <td>83.601377</td>\n", " <td>86.874946</td>\n", " <td>0.938474</td>\n", " <td>1.831284</td>\n", " </tr>\n", " </tbody>\n", "</table>\n", "</div>\n", " <div class=\"colab-df-buttons\">\n", "\n", " <div class=\"colab-df-container\">\n", " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-5707720b-4164-4067-9219-8c294017aaec')\"\n", " title=\"Convert this dataframe to an interactive table.\"\n", " style=\"display:none;\">\n", "\n", " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n", " <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n", " </svg>\n", " </button>\n", "\n", " <style>\n", " .colab-df-container {\n", " display:flex;\n", " gap: 12px;\n", " }\n", "\n", " .colab-df-convert {\n", " background-color: #E8F0FE;\n", " border: none;\n", " border-radius: 50%;\n", " cursor: pointer;\n", " display: none;\n", " fill: #1967D2;\n", " height: 32px;\n", " padding: 0 0 0 0;\n", " width: 32px;\n", " }\n", "\n", " .colab-df-convert:hover {\n", " background-color: #E2EBFA;\n", " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n", " fill: #174EA6;\n", " }\n", "\n", " .colab-df-buttons div {\n", " margin-bottom: 4px;\n", " }\n", "\n", " [theme=dark] .colab-df-convert {\n", " background-color: #3B4455;\n", " fill: #D2E3FC;\n", " }\n", "\n", " [theme=dark] .colab-df-convert:hover {\n", " background-color: #434B5C;\n", " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n", " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n", " fill: #FFFFFF;\n", " }\n", " </style>\n", "\n", " <script>\n", " const buttonEl =\n", " document.querySelector('#df-5707720b-4164-4067-9219-8c294017aaec button.colab-df-convert');\n", " buttonEl.style.display =\n", " google.colab.kernel.accessAllowed ? 'block' : 'none';\n", "\n", " async function convertToInteractive(key) {\n", " const element = document.querySelector('#df-5707720b-4164-4067-9219-8c294017aaec');\n", " const dataTable =\n", " await google.colab.kernel.invokeFunction('convertToInteractive',\n", " [key], {});\n", " if (!dataTable) return;\n", "\n", " const docLinkHtml = 'Like what you see? Visit the ' +\n", " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n", " + ' to learn more about interactive tables.';\n", " element.innerHTML = '';\n", " dataTable['output_type'] = 'display_data';\n", " await google.colab.output.renderOutput(dataTable, element);\n", " const docLink = document.createElement('div');\n", " docLink.innerHTML = docLinkHtml;\n", " element.appendChild(docLink);\n", " }\n", " </script>\n", " </div>\n", "\n", "\n", "<div id=\"df-5262573a-6195-41a9-81df-d2bbab0590cb\">\n", " <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-5262573a-6195-41a9-81df-d2bbab0590cb')\"\n", " title=\"Suggest charts\"\n", " style=\"display:none;\">\n", "\n", "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n", " width=\"24px\">\n", " <g>\n", " <path d=\"M19 3H5c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2zM9 17H7v-7h2v7zm4 0h-2V7h2v10zm4 0h-2v-4h2v4z\"/>\n", " </g>\n", "</svg>\n", " </button>\n", "\n", "<style>\n", " .colab-df-quickchart {\n", " --bg-color: #E8F0FE;\n", " --fill-color: #1967D2;\n", " --hover-bg-color: #E2EBFA;\n", " --hover-fill-color: #174EA6;\n", " --disabled-fill-color: #AAA;\n", " --disabled-bg-color: #DDD;\n", " }\n", "\n", " [theme=dark] .colab-df-quickchart {\n", " --bg-color: #3B4455;\n", " --fill-color: #D2E3FC;\n", " --hover-bg-color: #434B5C;\n", " --hover-fill-color: #FFFFFF;\n", " --disabled-bg-color: #3B4455;\n", " --disabled-fill-color: #666;\n", " }\n", "\n", " .colab-df-quickchart {\n", " background-color: var(--bg-color);\n", " border: none;\n", " border-radius: 50%;\n", " cursor: pointer;\n", " display: none;\n", " fill: var(--fill-color);\n", " height: 32px;\n", " padding: 0;\n", " width: 32px;\n", " }\n", "\n", " .colab-df-quickchart:hover {\n", " background-color: var(--hover-bg-color);\n", " box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n", " fill: var(--button-hover-fill-color);\n", " }\n", "\n", " .colab-df-quickchart-complete:disabled,\n", " .colab-df-quickchart-complete:disabled:hover {\n", " background-color: var(--disabled-bg-color);\n", " fill: var(--disabled-fill-color);\n", " box-shadow: none;\n", " }\n", "\n", " .colab-df-spinner {\n", " border: 2px solid var(--fill-color);\n", " border-color: transparent;\n", " border-bottom-color: var(--fill-color);\n", " animation:\n", " spin 1s steps(1) infinite;\n", " }\n", "\n", " @keyframes spin {\n", " 0% {\n", " border-color: transparent;\n", " border-bottom-color: var(--fill-color);\n", " border-left-color: var(--fill-color);\n", " }\n", " 20% {\n", " border-color: transparent;\n", " border-left-color: var(--fill-color);\n", " border-top-color: var(--fill-color);\n", " }\n", " 30% {\n", " border-color: transparent;\n", " border-left-color: var(--fill-color);\n", " border-top-color: var(--fill-color);\n", " border-right-color: var(--fill-color);\n", " }\n", " 40% {\n", " border-color: transparent;\n", " border-right-color: var(--fill-color);\n", " border-top-color: var(--fill-color);\n", " }\n", " 60% {\n", " border-color: transparent;\n", " border-right-color: var(--fill-color);\n", " }\n", " 80% {\n", " border-color: transparent;\n", " border-right-color: var(--fill-color);\n", " border-bottom-color: var(--fill-color);\n", " }\n", " 90% {\n", " border-color: transparent;\n", " border-bottom-color: var(--fill-color);\n", " }\n", " }\n", "</style>\n", "\n", " <script>\n", " async function quickchart(key) {\n", " const quickchartButtonEl =\n", " document.querySelector('#' + key + ' button');\n", " quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n", " quickchartButtonEl.classList.add('colab-df-spinner');\n", " try {\n", " const charts = await google.colab.kernel.invokeFunction(\n", " 'suggestCharts', [key], {});\n", " } catch (error) {\n", " console.error('Error during call to suggestCharts:', error);\n", " }\n", " quickchartButtonEl.classList.remove('colab-df-spinner');\n", " quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n", " }\n", " (() => {\n", " let quickchartButtonEl =\n", " document.querySelector('#df-5262573a-6195-41a9-81df-d2bbab0590cb button');\n", " quickchartButtonEl.style.display =\n", " google.colab.kernel.accessAllowed ? 'block' : 'none';\n", " })();\n", " </script>\n", "</div>\n", "\n", " </div>\n", " </div>\n" ], "text/plain": [ " Product Category Base_Price Competitor_Price \\\n", "0 Product_1 Beauty 46.173185 47.795620 \n", "1 Product_2 Sports 172.257137 180.360668 \n", "2 Product_3 Home & Kitchen 145.846189 137.360030 \n", "3 Product_4 Sports 32.650872 32.921534 \n", "4 Product_5 Sports 83.601377 86.874946 \n", "\n", " Seasonality_Factor Demand \n", "0 0.550769 2.381883 \n", "1 1.386617 1.734155 \n", "2 0.527617 0.679632 \n", "3 1.078865 7.762725 \n", "4 0.938474 1.831284 " ] }, "execution_count": 1, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "import pandas as pd\n", "\n", "# Set random seed for reproducibility\n", "np.random.seed(42)\n", "\n", "# Generate synthetic data for an e-commerce store\n", "num_products = 100 # Number of products\n", "\n", "# Product categories\n", "categories = [\"Electronics\", \"Clothing\", \"Home & Kitchen\", \"Beauty\", \"Sports\"]\n", "product_names = [f\"Product_{i+1}\" for i in range(num_products)]\n", "category_data = np.random.choice(categories, num_products)\n", "\n", "# Base price range per category\n", "price_ranges = {\n", " \"Electronics\": (50, 500),\n", " \"Clothing\": (10, 100),\n", " \"Home & Kitchen\": (20, 300),\n", " \"Beauty\": (5, 50),\n", " \"Sports\": (15, 200),\n", "}\n", "\n", "# Generate base prices based on category\n", "base_prices = [np.random.uniform(*price_ranges[cat]) for cat in category_data]\n", "\n", "# Competitor pricing (fluctuating around base price)\n", "competitor_prices = [price * np.random.uniform(0.9, 1.1) for price in base_prices]\n", "\n", "# Seasonal demand factor (scale between 0.5 and 1.5)\n", "seasonality = np.random.uniform(0.5, 1.5, num_products)\n", "\n", "# Customer demand (influenced by price and seasonality)\n", "demand = [(200 / price) * season * np.random.uniform(0.8, 1.2) for price, season in zip(base_prices, seasonality)]\n", "\n", "# Assemble dataset\n", "ecommerce_data = pd.DataFrame({\n", " \"Product\": product_names,\n", " \"Category\": category_data,\n", " \"Base_Price\": base_prices,\n", " \"Competitor_Price\": competitor_prices,\n", " \"Seasonality_Factor\": seasonality,\n", " \"Demand\": demand\n", "})\n", "\n", "# Display the first few rows of the dataset\n", "ecommerce_data.head()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "VdaRPQzpHtX4", "outputId": "56834fc9-1078-4e3d-f0da-e7c6e4c1fe73" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2025-03-13 19:15:59.867 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n", "2025-03-13 19:15:59.871 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n", "2025-03-13 19:15:59.872 WARNING streamlit.runtime.scriptrunner_utils.script_run_context: Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.237 \n", " \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n", " command:\n", "\n", " streamlit run /usr/local/lib/python3.11/dist-packages/colab_kernel_launcher.py [ARGUMENTS]\n", "2025-03-13 19:16:00.239 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.241 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.244 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.245 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.246 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.247 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.248 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.249 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.249 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.250 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.251 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.252 Session state does not function when running a script without `streamlit run`\n", "2025-03-13 19:16:00.253 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.254 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.255 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.256 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.257 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.258 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.258 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n", "2025-03-13 19:16:00.259 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n" ] } ], "source": [ "import streamlit as st\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "\n", "# Load the synthetic dataset (Replace this with actual dataset loading)\n", "@st.cache_data\n", "def load_data():\n", " return ecommerce_data # Use the generated dataset from previous steps\n", "\n", "data = load_data()\n", "\n", "# Streamlit UI Configuration\n", "st.set_page_config(page_title=\"E-Commerce Pricing Optimization\", layout=\"wide\")\n", "\n", "# Sidebar Navigation\n", "st.sidebar.title(\"Navigation\")\n", "page = st.sidebar.selectbox(\"Choose a Page\", [\"Introduction\", \"Visualizations\", \"Solution Implementation\"])\n", "\n", "if page == \"Introduction\":\n", " st.title(\"E-Commerce Pricing Optimization\")\n", " st.write(\"\"\"\n", " **Business Problem:**\n", " - E-commerce companies struggle to set optimal prices that maximize revenue while staying competitive.\n", " - Prices need to adjust dynamically based on demand, competitor pricing, and seasonal trends.\n", "\n", " **Solution Approach:**\n", " - Use **Multi-Armed Bandits** for adaptive pricing strategy.\n", " - Apply **Bayesian Networks** to predict customer demand based on price.\n", " - Use **Multi-Criteria Decision Making (AHP)** to decide the best price based on multiple factors.\n", " \"\"\")\n", "\n", "elif page == \"Visualizations\":\n", " st.title(\"Data Visualizations\")\n", "\n", " # Plot 1: Price Distribution Across Categories\n", " st.subheader(\"Price Distribution Across Categories\")\n", " fig, ax = plt.subplots()\n", " sns.boxplot(x=\"Category\", y=\"Base_Price\", data=data, ax=ax, palette=\"Set2\")\n", " plt.xticks(rotation=30)\n", " st.pyplot(fig)\n", "\n", " # Plot 2: Competitor Price vs. Base Price\n", " st.subheader(\"Competitor Price vs. Base Price\")\n", " fig, ax = plt.subplots()\n", " sns.scatterplot(x=\"Base_Price\", y=\"Competitor_Price\", data=data, color=\"blue\", alpha=0.7, ax=ax)\n", " st.pyplot(fig)\n", "\n", " # Plot 3: Seasonality Impact on Demand\n", " st.subheader(\"Seasonality Impact on Demand\")\n", " fig, ax = plt.subplots()\n", " sns.scatterplot(x=\"Seasonality_Factor\", y=\"Demand\", data=data, color=\"green\", alpha=0.7, ax=ax)\n", " st.pyplot(fig)\n", "\n", " # Plot 4: Price vs. Demand Relationship\n", " st.subheader(\"Price vs. Demand Relationship\")\n", " fig, ax = plt.subplots()\n", " sns.scatterplot(x=\"Base_Price\", y=\"Demand\", data=data, color=\"red\", alpha=0.7, ax=ax)\n", " st.pyplot(fig)\n", "\n", "elif page == \"Solution Implementation\":\n", " st.title(\"Solution Implementation\")\n", " st.write(\"\"\"\n", " **Concepts Used:**\n", " - **Multi-Armed Bandits**: To continuously optimize pricing strategy.\n", " - **Bayesian Networks**: To model demand uncertainty based on price changes.\n", " - **Multi-Criteria Decision Making (AHP)**: To balance revenue, demand, and competitiveness.\n", "\n", " **Next Steps:**\n", " - Implement these models and test them in a real-world simulation.\n", " - Analyze results and fine-tune the pricing strategy dynamically.\n", " \"\"\")\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "FBiiIfnJG5CZ", "outputId": "872566bf-aa7b-4397-9f50-2860be11e508" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: streamlit in /usr/local/lib/python3.11/dist-packages (1.43.2)\n", "Requirement already satisfied: altair<6,>=4.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (5.5.0)\n", "Requirement already satisfied: blinker<2,>=1.0.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (1.9.0)\n", "Requirement already satisfied: cachetools<6,>=4.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (5.5.2)\n", "Requirement already satisfied: click<9,>=7.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (8.1.8)\n", "Requirement already satisfied: numpy<3,>=1.23 in /usr/local/lib/python3.11/dist-packages (from streamlit) (1.26.4)\n", "Requirement already satisfied: packaging<25,>=20 in /usr/local/lib/python3.11/dist-packages (from streamlit) (24.2)\n", "Requirement already satisfied: pandas<3,>=1.4.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (2.2.2)\n", "Requirement already satisfied: pillow<12,>=7.1.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (11.1.0)\n", "Requirement already satisfied: protobuf<6,>=3.20 in /usr/local/lib/python3.11/dist-packages (from streamlit) (4.25.6)\n", "Requirement already satisfied: pyarrow>=7.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (18.1.0)\n", "Requirement already satisfied: requests<3,>=2.27 in /usr/local/lib/python3.11/dist-packages (from streamlit) (2.32.3)\n", "Requirement already satisfied: tenacity<10,>=8.1.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (9.0.0)\n", "Requirement already satisfied: toml<2,>=0.10.1 in /usr/local/lib/python3.11/dist-packages (from streamlit) (0.10.2)\n", "Requirement already satisfied: typing-extensions<5,>=4.4.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (4.12.2)\n", "Requirement already satisfied: watchdog<7,>=2.1.5 in /usr/local/lib/python3.11/dist-packages (from streamlit) (6.0.0)\n", "Requirement already satisfied: gitpython!=3.1.19,<4,>=3.0.7 in /usr/local/lib/python3.11/dist-packages (from streamlit) (3.1.44)\n", "Requirement already satisfied: pydeck<1,>=0.8.0b4 in /usr/local/lib/python3.11/dist-packages (from streamlit) (0.9.1)\n", "Requirement already satisfied: tornado<7,>=6.0.3 in /usr/local/lib/python3.11/dist-packages (from streamlit) (6.4.2)\n", "Requirement already satisfied: jinja2 in /usr/local/lib/python3.11/dist-packages (from altair<6,>=4.0->streamlit) (3.1.6)\n", "Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.11/dist-packages (from altair<6,>=4.0->streamlit) (4.23.0)\n", "Requirement already satisfied: narwhals>=1.14.2 in /usr/local/lib/python3.11/dist-packages (from altair<6,>=4.0->streamlit) (1.29.1)\n", "Requirement already satisfied: gitdb<5,>=4.0.1 in /usr/local/lib/python3.11/dist-packages (from gitpython!=3.1.19,<4,>=3.0.7->streamlit) (4.0.12)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas<3,>=1.4.0->streamlit) (2.8.2)\n", "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas<3,>=1.4.0->streamlit) (2025.1)\n", "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas<3,>=1.4.0->streamlit) (2025.1)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2.27->streamlit) (3.4.1)\n", "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2.27->streamlit) (3.10)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2.27->streamlit) (2.3.0)\n", "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2.27->streamlit) (2025.1.31)\n", "Requirement already satisfied: smmap<6,>=3.0.1 in /usr/local/lib/python3.11/dist-packages (from gitdb<5,>=4.0.1->gitpython!=3.1.19,<4,>=3.0.7->streamlit) (5.0.2)\n", "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2->altair<6,>=4.0->streamlit) (3.0.2)\n", "Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.11/dist-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (25.1.0)\n", "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.11/dist-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (2024.10.1)\n", "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.11/dist-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (0.36.2)\n", "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.11/dist-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit) (0.23.1)\n", "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.8.2->pandas<3,>=1.4.0->streamlit) (1.17.0)\n", "Requirement already satisfied: pyngrok in /usr/local/lib/python3.11/dist-packages (7.2.3)\n", "Requirement already satisfied: PyYAML>=5.1 in /usr/local/lib/python3.11/dist-packages (from pyngrok) (6.0.2)\n" ] } ], "source": [ "!pip install streamlit\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "Ua2k4X94HmhK" }, "outputs": [], "source": [ "!streamlit run app.py &>/dev/null &\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "kAkim2pmJU3j", "outputId": "04a6f08f-f878-4670-c7c2-8373b123a065" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Overwriting app.py\n" ] } ], "source": [ "%%writefile app.py\n", "import streamlit as st\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "from sklearn.linear_model import LinearRegression\n", "from sklearn.cluster import KMeans\n", "import pandas as pd\n", "\n", "# App Title\n", "st.title(\"Business Performance Analysis\")\n", "\n", "# Sidebar Navigation\n", "st.sidebar.header(\"Navigation\")\n", "page = st.sidebar.selectbox(\"Select a Page\", [\"Introduction\", \"Visualizations\", \"Solution\", \"Forecasting\", \"Customer Segmentation\", \"Expense Optimization\", \"Goal Tracker\"])\n", "\n", "# Page 1: Introduction\n", "if page == \"Introduction\":\n", " st.header(\"π Introduction\")\n", " st.markdown(\"\"\"\n", " ## Understanding the Business Problem\n", " Businesses today face significant challenges in optimizing **profitability, reducing costs, and maximizing customer value**.\n", " Here are three key business issues:\n", "\n", " 1οΈβ£ **Revenue and Profitability Issues**\n", " - Unpredictable revenue impacts long-term growth.\n", " - High operational costs reduce net profit margins.\n", "\n", " 2οΈβ£ **Customer Retention & Engagement**\n", " - Businesses struggle to understand customer behavior.\n", " - Acquiring new customers is costlier than retaining existing ones.\n", "\n", " 3οΈβ£ **Data-Driven Decision Making**\n", " - Many businesses lack real-time insights.\n", " - Without proper data analysis, decisions are based on intuition rather than facts.\n", "\n", " ### π Our Key Approaches\n", " - **Revenue & Cost Analysis**\n", " - **Data Visualization for Business Insights**\n", " - **Strategic Business Solutions**\n", " - **Forecasting Future Trends**\n", " - **Competitor Benchmarking**\n", " - **Customer Segmentation**\n", " - **Expense Optimization**\n", " - **Goal Tracking & Business Strategy**\n", " \"\"\")\n", "\n", "# Page 2: Visualizations\n", "elif page == \"Visualizations\":\n", " st.header(\"π Business Data Visualizations\")\n", " st.subheader(\"π Revenue vs Costs\")\n", " revenue = st.sidebar.number_input(\"Monthly Revenue ($)\", min_value=0, value=10000)\n", " costs = st.sidebar.number_input(\"Monthly Costs ($)\", min_value=0, value=5000)\n", " fig, ax = plt.subplots()\n", " ax.bar([\"Revenue\", \"Costs\"], [revenue, costs], color=['green', 'red'])\n", " st.pyplot(fig)\n", "\n", "\n", "\n", "# Page 3: Solution\n", "elif page == \"Solution\":\n", " st.header(\"π Business Solution & Insights\")\n", " st.subheader(\"π Key Business Metrics\")\n", " # Define revenue and costs globally so they can be accessed on multiple pages\n", " revenues = st.sidebar.number_input(\"Monthly Revenue ($)\", min_value=0, value=10000)\n", " costs = st.sidebar.number_input(\"Monthly Costs ($)\", min_value=0, value=5000)\n", "\n", " # Calculate profit using global revenue and costs\n", " profit = revenues - costs\n", "\n", " # Display the result\n", " st.metric(label=\"Total Profit ($)\", value=f\"${profit:,.2f}\")\n", "\n", "\n", "# Page 4: Forecasting\n", "elif page == \"Forecasting\":\n", " st.header(\"π Future Revenue Prediction\")\n", " months = np.array([1, 2, 3, 4, 5, 6]).reshape(-1, 1)\n", " revenue_data = np.array([8000, 8500, 9000, 9400, 10000, 10500])\n", " model = LinearRegression()\n", " model.fit(months, revenue_data)\n", " future_months = np.array([7, 8, 9]).reshape(-1, 1)\n", " predicted_revenue = model.predict(future_months)\n", " st.line_chart(np.append(revenue_data, predicted_revenue))\n", "\n", "# Page 5: Customer Segmentation\n", "elif page == \"Customer Segmentation\":\n", " st.header(\"π Customer Segmentation\")\n", " customer_data = pd.DataFrame({\n", " 'revenue': [200, 500, 800, 1200, 1500, 300],\n", " 'purchases': [2, 5, 8, 12, 15, 3]\n", " })\n", " kmeans = KMeans(n_clusters=3)\n", " customer_data['segment'] = kmeans.fit_predict(customer_data)\n", " st.scatter_chart(customer_data, x='revenue', y='purchases', color='segment')\n", "\n", "# Page 6: Expense Optimization\n", "elif page == \"Expense Optimization\":\n", " st.header(\"π° Expense Optimization\")\n", " expense_categories = [\"Marketing\", \"Salaries\", \"Infrastructure\", \"Miscellaneous\"]\n", " expenses = [3000, 5000, 2000, 1000]\n", " fig, ax = plt.subplots()\n", " ax.pie(expenses, labels=expense_categories, autopct='%1.1f%%', startangle=140)\n", " st.pyplot(fig)\n", "\n", "# Page 7: Goal Tracker\n", "elif page == \"Goal Tracker\":\n", " st.header(\"π― Business Goal Tracker\")\n", "\n", "# User inputs revenue goal\n", " goal = st.number_input(\"Enter your revenue goal ($)\", min_value=0)\n", "\n", "# User inputs monthly revenue\n", " revenue = st.sidebar.number_input(\"Monthly Revenue ($)\", min_value=0, value=10000)\n", "\n", "# Check if the goal is met\n", " if goal < revenue:\n", " st.warning(\"You have reached your revenue goal yet.\")\n", " else:\n", " progress = (revenue / goal) * 100 if goal else 0\n", " st.progress(progress / 100)\n", " st.write(f\"**Progress:** {progress:.2f}% of goal achieved\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "RJLfA30SJWwL" }, "outputs": [], "source": [ "!streamlit run app.py --server.port 8501 &>/dev/null &\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "kBDkEzTuJY76", "outputId": "967997db-fa81-49f7-c61b-a0fd6522cb6d" }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "WARNING:pyngrok.process.ngrok:t=2025-03-13T19:22:20+0000 lvl=warn msg=\"Stopping forwarder\" name=http-8501-4adcf033-e86b-464e-b23c-d09fbef43d83 acceptErr=\"failed to accept connection: Listener closed\"\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Disconnecting: https://f327-34-171-10-70.ngrok-free.app\n", "Access the Streamlit app at: NgrokTunnel: \"https://fb68-34-171-10-70.ngrok-free.app\" -> \"http://localhost:8501\"\n" ] } ], "source": [ "from pyngrok import ngrok\n", "\n", "# List all existing ngrok tunnels\n", "tunnels = ngrok.get_tunnels()\n", "# Check if there are any active tunnels before attempting to disconnect\n", "if tunnels:\n", " for tunnel in tunnels:\n", " print(\"Disconnecting:\", tunnel.public_url)\n", " ngrok.disconnect(tunnel.public_url) # Disconnect each active tunnel\n", "else:\n", " print(\"No active tunnels found.\")\n", "\n", "# Start a new tunnel\n", "public_url = ngrok.connect(addr=\"8501\")\n", "print(\"Access the Streamlit app at:\", public_url)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "QLCKfkUZ3c9f" }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "_ub8lpzdaUwe" }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "fEj20rRGJafC" }, "outputs": [], "source": [] } ], "metadata": { "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0}app.pyDeleted-826