Anushree2000 commited on
Commit
35644b8
Β·
verified Β·
1 Parent(s): ad7d573

Upload RDMU_Exam_Practice_HF_Ready.ipynb

Browse files
Files changed (1) hide show
  1. RDMU_Exam_Practice_HF_Ready.ipynb +826 -0
RDMU_Exam_Practice_HF_Ready.ipynb ADDED
@@ -0,0 +1,826 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": null,
6
+ "metadata": {
7
+ "id": "d904b962"
8
+ },
9
+ "outputs": [],
10
+ "source": [
11
+ "!pip install -r requirements.txt\n"
12
+ ]
13
+ },
14
+ {
15
+ "cell_type": "code",
16
+ "execution_count": null,
17
+ "metadata": {
18
+ "colab": {
19
+ "base_uri": "https://localhost:8080/",
20
+ "height": 206
21
+ },
22
+ "id": "a3GwBO8PF88q",
23
+ "outputId": "0e89b22a-5942-48b0-f9b7-cd51f9ea97f8"
24
+ },
25
+ "outputs": [
26
+ {
27
+ "data": {
28
+ "application/vnd.google.colaboratory.intrinsic+json": {
29
+ "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}",
30
+ "type": "dataframe",
31
+ "variable_name": "ecommerce_data"
32
+ },
33
+ "text/html": [
34
+ "\n",
35
+ " <div id=\"df-5707720b-4164-4067-9219-8c294017aaec\" class=\"colab-df-container\">\n",
36
+ " <div>\n",
37
+ "<style scoped>\n",
38
+ " .dataframe tbody tr th:only-of-type {\n",
39
+ " vertical-align: middle;\n",
40
+ " }\n",
41
+ "\n",
42
+ " .dataframe tbody tr th {\n",
43
+ " vertical-align: top;\n",
44
+ " }\n",
45
+ "\n",
46
+ " .dataframe thead th {\n",
47
+ " text-align: right;\n",
48
+ " }\n",
49
+ "</style>\n",
50
+ "<table border=\"1\" class=\"dataframe\">\n",
51
+ " <thead>\n",
52
+ " <tr style=\"text-align: right;\">\n",
53
+ " <th></th>\n",
54
+ " <th>Product</th>\n",
55
+ " <th>Category</th>\n",
56
+ " <th>Base_Price</th>\n",
57
+ " <th>Competitor_Price</th>\n",
58
+ " <th>Seasonality_Factor</th>\n",
59
+ " <th>Demand</th>\n",
60
+ " </tr>\n",
61
+ " </thead>\n",
62
+ " <tbody>\n",
63
+ " <tr>\n",
64
+ " <th>0</th>\n",
65
+ " <td>Product_1</td>\n",
66
+ " <td>Beauty</td>\n",
67
+ " <td>46.173185</td>\n",
68
+ " <td>47.795620</td>\n",
69
+ " <td>0.550769</td>\n",
70
+ " <td>2.381883</td>\n",
71
+ " </tr>\n",
72
+ " <tr>\n",
73
+ " <th>1</th>\n",
74
+ " <td>Product_2</td>\n",
75
+ " <td>Sports</td>\n",
76
+ " <td>172.257137</td>\n",
77
+ " <td>180.360668</td>\n",
78
+ " <td>1.386617</td>\n",
79
+ " <td>1.734155</td>\n",
80
+ " </tr>\n",
81
+ " <tr>\n",
82
+ " <th>2</th>\n",
83
+ " <td>Product_3</td>\n",
84
+ " <td>Home &amp; Kitchen</td>\n",
85
+ " <td>145.846189</td>\n",
86
+ " <td>137.360030</td>\n",
87
+ " <td>0.527617</td>\n",
88
+ " <td>0.679632</td>\n",
89
+ " </tr>\n",
90
+ " <tr>\n",
91
+ " <th>3</th>\n",
92
+ " <td>Product_4</td>\n",
93
+ " <td>Sports</td>\n",
94
+ " <td>32.650872</td>\n",
95
+ " <td>32.921534</td>\n",
96
+ " <td>1.078865</td>\n",
97
+ " <td>7.762725</td>\n",
98
+ " </tr>\n",
99
+ " <tr>\n",
100
+ " <th>4</th>\n",
101
+ " <td>Product_5</td>\n",
102
+ " <td>Sports</td>\n",
103
+ " <td>83.601377</td>\n",
104
+ " <td>86.874946</td>\n",
105
+ " <td>0.938474</td>\n",
106
+ " <td>1.831284</td>\n",
107
+ " </tr>\n",
108
+ " </tbody>\n",
109
+ "</table>\n",
110
+ "</div>\n",
111
+ " <div class=\"colab-df-buttons\">\n",
112
+ "\n",
113
+ " <div class=\"colab-df-container\">\n",
114
+ " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-5707720b-4164-4067-9219-8c294017aaec')\"\n",
115
+ " title=\"Convert this dataframe to an interactive table.\"\n",
116
+ " style=\"display:none;\">\n",
117
+ "\n",
118
+ " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
119
+ " <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
120
+ " </svg>\n",
121
+ " </button>\n",
122
+ "\n",
123
+ " <style>\n",
124
+ " .colab-df-container {\n",
125
+ " display:flex;\n",
126
+ " gap: 12px;\n",
127
+ " }\n",
128
+ "\n",
129
+ " .colab-df-convert {\n",
130
+ " background-color: #E8F0FE;\n",
131
+ " border: none;\n",
132
+ " border-radius: 50%;\n",
133
+ " cursor: pointer;\n",
134
+ " display: none;\n",
135
+ " fill: #1967D2;\n",
136
+ " height: 32px;\n",
137
+ " padding: 0 0 0 0;\n",
138
+ " width: 32px;\n",
139
+ " }\n",
140
+ "\n",
141
+ " .colab-df-convert:hover {\n",
142
+ " background-color: #E2EBFA;\n",
143
+ " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
144
+ " fill: #174EA6;\n",
145
+ " }\n",
146
+ "\n",
147
+ " .colab-df-buttons div {\n",
148
+ " margin-bottom: 4px;\n",
149
+ " }\n",
150
+ "\n",
151
+ " [theme=dark] .colab-df-convert {\n",
152
+ " background-color: #3B4455;\n",
153
+ " fill: #D2E3FC;\n",
154
+ " }\n",
155
+ "\n",
156
+ " [theme=dark] .colab-df-convert:hover {\n",
157
+ " background-color: #434B5C;\n",
158
+ " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
159
+ " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
160
+ " fill: #FFFFFF;\n",
161
+ " }\n",
162
+ " </style>\n",
163
+ "\n",
164
+ " <script>\n",
165
+ " const buttonEl =\n",
166
+ " document.querySelector('#df-5707720b-4164-4067-9219-8c294017aaec button.colab-df-convert');\n",
167
+ " buttonEl.style.display =\n",
168
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
169
+ "\n",
170
+ " async function convertToInteractive(key) {\n",
171
+ " const element = document.querySelector('#df-5707720b-4164-4067-9219-8c294017aaec');\n",
172
+ " const dataTable =\n",
173
+ " await google.colab.kernel.invokeFunction('convertToInteractive',\n",
174
+ " [key], {});\n",
175
+ " if (!dataTable) return;\n",
176
+ "\n",
177
+ " const docLinkHtml = 'Like what you see? Visit the ' +\n",
178
+ " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
179
+ " + ' to learn more about interactive tables.';\n",
180
+ " element.innerHTML = '';\n",
181
+ " dataTable['output_type'] = 'display_data';\n",
182
+ " await google.colab.output.renderOutput(dataTable, element);\n",
183
+ " const docLink = document.createElement('div');\n",
184
+ " docLink.innerHTML = docLinkHtml;\n",
185
+ " element.appendChild(docLink);\n",
186
+ " }\n",
187
+ " </script>\n",
188
+ " </div>\n",
189
+ "\n",
190
+ "\n",
191
+ "<div id=\"df-5262573a-6195-41a9-81df-d2bbab0590cb\">\n",
192
+ " <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-5262573a-6195-41a9-81df-d2bbab0590cb')\"\n",
193
+ " title=\"Suggest charts\"\n",
194
+ " style=\"display:none;\">\n",
195
+ "\n",
196
+ "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
197
+ " width=\"24px\">\n",
198
+ " <g>\n",
199
+ " <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",
200
+ " </g>\n",
201
+ "</svg>\n",
202
+ " </button>\n",
203
+ "\n",
204
+ "<style>\n",
205
+ " .colab-df-quickchart {\n",
206
+ " --bg-color: #E8F0FE;\n",
207
+ " --fill-color: #1967D2;\n",
208
+ " --hover-bg-color: #E2EBFA;\n",
209
+ " --hover-fill-color: #174EA6;\n",
210
+ " --disabled-fill-color: #AAA;\n",
211
+ " --disabled-bg-color: #DDD;\n",
212
+ " }\n",
213
+ "\n",
214
+ " [theme=dark] .colab-df-quickchart {\n",
215
+ " --bg-color: #3B4455;\n",
216
+ " --fill-color: #D2E3FC;\n",
217
+ " --hover-bg-color: #434B5C;\n",
218
+ " --hover-fill-color: #FFFFFF;\n",
219
+ " --disabled-bg-color: #3B4455;\n",
220
+ " --disabled-fill-color: #666;\n",
221
+ " }\n",
222
+ "\n",
223
+ " .colab-df-quickchart {\n",
224
+ " background-color: var(--bg-color);\n",
225
+ " border: none;\n",
226
+ " border-radius: 50%;\n",
227
+ " cursor: pointer;\n",
228
+ " display: none;\n",
229
+ " fill: var(--fill-color);\n",
230
+ " height: 32px;\n",
231
+ " padding: 0;\n",
232
+ " width: 32px;\n",
233
+ " }\n",
234
+ "\n",
235
+ " .colab-df-quickchart:hover {\n",
236
+ " background-color: var(--hover-bg-color);\n",
237
+ " box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
238
+ " fill: var(--button-hover-fill-color);\n",
239
+ " }\n",
240
+ "\n",
241
+ " .colab-df-quickchart-complete:disabled,\n",
242
+ " .colab-df-quickchart-complete:disabled:hover {\n",
243
+ " background-color: var(--disabled-bg-color);\n",
244
+ " fill: var(--disabled-fill-color);\n",
245
+ " box-shadow: none;\n",
246
+ " }\n",
247
+ "\n",
248
+ " .colab-df-spinner {\n",
249
+ " border: 2px solid var(--fill-color);\n",
250
+ " border-color: transparent;\n",
251
+ " border-bottom-color: var(--fill-color);\n",
252
+ " animation:\n",
253
+ " spin 1s steps(1) infinite;\n",
254
+ " }\n",
255
+ "\n",
256
+ " @keyframes spin {\n",
257
+ " 0% {\n",
258
+ " border-color: transparent;\n",
259
+ " border-bottom-color: var(--fill-color);\n",
260
+ " border-left-color: var(--fill-color);\n",
261
+ " }\n",
262
+ " 20% {\n",
263
+ " border-color: transparent;\n",
264
+ " border-left-color: var(--fill-color);\n",
265
+ " border-top-color: var(--fill-color);\n",
266
+ " }\n",
267
+ " 30% {\n",
268
+ " border-color: transparent;\n",
269
+ " border-left-color: var(--fill-color);\n",
270
+ " border-top-color: var(--fill-color);\n",
271
+ " border-right-color: var(--fill-color);\n",
272
+ " }\n",
273
+ " 40% {\n",
274
+ " border-color: transparent;\n",
275
+ " border-right-color: var(--fill-color);\n",
276
+ " border-top-color: var(--fill-color);\n",
277
+ " }\n",
278
+ " 60% {\n",
279
+ " border-color: transparent;\n",
280
+ " border-right-color: var(--fill-color);\n",
281
+ " }\n",
282
+ " 80% {\n",
283
+ " border-color: transparent;\n",
284
+ " border-right-color: var(--fill-color);\n",
285
+ " border-bottom-color: var(--fill-color);\n",
286
+ " }\n",
287
+ " 90% {\n",
288
+ " border-color: transparent;\n",
289
+ " border-bottom-color: var(--fill-color);\n",
290
+ " }\n",
291
+ " }\n",
292
+ "</style>\n",
293
+ "\n",
294
+ " <script>\n",
295
+ " async function quickchart(key) {\n",
296
+ " const quickchartButtonEl =\n",
297
+ " document.querySelector('#' + key + ' button');\n",
298
+ " quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
299
+ " quickchartButtonEl.classList.add('colab-df-spinner');\n",
300
+ " try {\n",
301
+ " const charts = await google.colab.kernel.invokeFunction(\n",
302
+ " 'suggestCharts', [key], {});\n",
303
+ " } catch (error) {\n",
304
+ " console.error('Error during call to suggestCharts:', error);\n",
305
+ " }\n",
306
+ " quickchartButtonEl.classList.remove('colab-df-spinner');\n",
307
+ " quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
308
+ " }\n",
309
+ " (() => {\n",
310
+ " let quickchartButtonEl =\n",
311
+ " document.querySelector('#df-5262573a-6195-41a9-81df-d2bbab0590cb button');\n",
312
+ " quickchartButtonEl.style.display =\n",
313
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
314
+ " })();\n",
315
+ " </script>\n",
316
+ "</div>\n",
317
+ "\n",
318
+ " </div>\n",
319
+ " </div>\n"
320
+ ],
321
+ "text/plain": [
322
+ " Product Category Base_Price Competitor_Price \\\n",
323
+ "0 Product_1 Beauty 46.173185 47.795620 \n",
324
+ "1 Product_2 Sports 172.257137 180.360668 \n",
325
+ "2 Product_3 Home & Kitchen 145.846189 137.360030 \n",
326
+ "3 Product_4 Sports 32.650872 32.921534 \n",
327
+ "4 Product_5 Sports 83.601377 86.874946 \n",
328
+ "\n",
329
+ " Seasonality_Factor Demand \n",
330
+ "0 0.550769 2.381883 \n",
331
+ "1 1.386617 1.734155 \n",
332
+ "2 0.527617 0.679632 \n",
333
+ "3 1.078865 7.762725 \n",
334
+ "4 0.938474 1.831284 "
335
+ ]
336
+ },
337
+ "execution_count": 1,
338
+ "metadata": {},
339
+ "output_type": "execute_result"
340
+ }
341
+ ],
342
+ "source": [
343
+ "import numpy as np\n",
344
+ "import pandas as pd\n",
345
+ "\n",
346
+ "# Set random seed for reproducibility\n",
347
+ "np.random.seed(42)\n",
348
+ "\n",
349
+ "# Generate synthetic data for an e-commerce store\n",
350
+ "num_products = 100 # Number of products\n",
351
+ "\n",
352
+ "# Product categories\n",
353
+ "categories = [\"Electronics\", \"Clothing\", \"Home & Kitchen\", \"Beauty\", \"Sports\"]\n",
354
+ "product_names = [f\"Product_{i+1}\" for i in range(num_products)]\n",
355
+ "category_data = np.random.choice(categories, num_products)\n",
356
+ "\n",
357
+ "# Base price range per category\n",
358
+ "price_ranges = {\n",
359
+ " \"Electronics\": (50, 500),\n",
360
+ " \"Clothing\": (10, 100),\n",
361
+ " \"Home & Kitchen\": (20, 300),\n",
362
+ " \"Beauty\": (5, 50),\n",
363
+ " \"Sports\": (15, 200),\n",
364
+ "}\n",
365
+ "\n",
366
+ "# Generate base prices based on category\n",
367
+ "base_prices = [np.random.uniform(*price_ranges[cat]) for cat in category_data]\n",
368
+ "\n",
369
+ "# Competitor pricing (fluctuating around base price)\n",
370
+ "competitor_prices = [price * np.random.uniform(0.9, 1.1) for price in base_prices]\n",
371
+ "\n",
372
+ "# Seasonal demand factor (scale between 0.5 and 1.5)\n",
373
+ "seasonality = np.random.uniform(0.5, 1.5, num_products)\n",
374
+ "\n",
375
+ "# Customer demand (influenced by price and seasonality)\n",
376
+ "demand = [(200 / price) * season * np.random.uniform(0.8, 1.2) for price, season in zip(base_prices, seasonality)]\n",
377
+ "\n",
378
+ "# Assemble dataset\n",
379
+ "ecommerce_data = pd.DataFrame({\n",
380
+ " \"Product\": product_names,\n",
381
+ " \"Category\": category_data,\n",
382
+ " \"Base_Price\": base_prices,\n",
383
+ " \"Competitor_Price\": competitor_prices,\n",
384
+ " \"Seasonality_Factor\": seasonality,\n",
385
+ " \"Demand\": demand\n",
386
+ "})\n",
387
+ "\n",
388
+ "# Display the first few rows of the dataset\n",
389
+ "ecommerce_data.head()\n"
390
+ ]
391
+ },
392
+ {
393
+ "cell_type": "code",
394
+ "execution_count": null,
395
+ "metadata": {
396
+ "colab": {
397
+ "base_uri": "https://localhost:8080/"
398
+ },
399
+ "id": "VdaRPQzpHtX4",
400
+ "outputId": "56834fc9-1078-4e3d-f0da-e7c6e4c1fe73"
401
+ },
402
+ "outputs": [
403
+ {
404
+ "name": "stderr",
405
+ "output_type": "stream",
406
+ "text": [
407
+ "2025-03-13 19:15:59.867 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
408
+ "2025-03-13 19:15:59.871 WARNING streamlit.runtime.caching.cache_data_api: No runtime found, using MemoryCacheStorageManager\n",
409
+ "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",
410
+ "2025-03-13 19:16:00.237 \n",
411
+ " \u001b[33m\u001b[1mWarning:\u001b[0m to view this Streamlit app on a browser, run it with the following\n",
412
+ " command:\n",
413
+ "\n",
414
+ " streamlit run /usr/local/lib/python3.11/dist-packages/colab_kernel_launcher.py [ARGUMENTS]\n",
415
+ "2025-03-13 19:16:00.239 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
416
+ "2025-03-13 19:16:00.241 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
417
+ "2025-03-13 19:16:00.244 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
418
+ "2025-03-13 19:16:00.245 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
419
+ "2025-03-13 19:16:00.246 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
420
+ "2025-03-13 19:16:00.247 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
421
+ "2025-03-13 19:16:00.248 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
422
+ "2025-03-13 19:16:00.249 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
423
+ "2025-03-13 19:16:00.249 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
424
+ "2025-03-13 19:16:00.250 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
425
+ "2025-03-13 19:16:00.251 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
426
+ "2025-03-13 19:16:00.252 Session state does not function when running a script without `streamlit run`\n",
427
+ "2025-03-13 19:16:00.253 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
428
+ "2025-03-13 19:16:00.254 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
429
+ "2025-03-13 19:16:00.255 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
430
+ "2025-03-13 19:16:00.256 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
431
+ "2025-03-13 19:16:00.257 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
432
+ "2025-03-13 19:16:00.258 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
433
+ "2025-03-13 19:16:00.258 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n",
434
+ "2025-03-13 19:16:00.259 Thread 'MainThread': missing ScriptRunContext! This warning can be ignored when running in bare mode.\n"
435
+ ]
436
+ }
437
+ ],
438
+ "source": [
439
+ "import streamlit as st\n",
440
+ "import pandas as pd\n",
441
+ "import matplotlib.pyplot as plt\n",
442
+ "import seaborn as sns\n",
443
+ "\n",
444
+ "# Load the synthetic dataset (Replace this with actual dataset loading)\n",
445
+ "@st.cache_data\n",
446
+ "def load_data():\n",
447
+ " return ecommerce_data # Use the generated dataset from previous steps\n",
448
+ "\n",
449
+ "data = load_data()\n",
450
+ "\n",
451
+ "# Streamlit UI Configuration\n",
452
+ "st.set_page_config(page_title=\"E-Commerce Pricing Optimization\", layout=\"wide\")\n",
453
+ "\n",
454
+ "# Sidebar Navigation\n",
455
+ "st.sidebar.title(\"Navigation\")\n",
456
+ "page = st.sidebar.selectbox(\"Choose a Page\", [\"Introduction\", \"Visualizations\", \"Solution Implementation\"])\n",
457
+ "\n",
458
+ "if page == \"Introduction\":\n",
459
+ " st.title(\"E-Commerce Pricing Optimization\")\n",
460
+ " st.write(\"\"\"\n",
461
+ " **Business Problem:**\n",
462
+ " - E-commerce companies struggle to set optimal prices that maximize revenue while staying competitive.\n",
463
+ " - Prices need to adjust dynamically based on demand, competitor pricing, and seasonal trends.\n",
464
+ "\n",
465
+ " **Solution Approach:**\n",
466
+ " - Use **Multi-Armed Bandits** for adaptive pricing strategy.\n",
467
+ " - Apply **Bayesian Networks** to predict customer demand based on price.\n",
468
+ " - Use **Multi-Criteria Decision Making (AHP)** to decide the best price based on multiple factors.\n",
469
+ " \"\"\")\n",
470
+ "\n",
471
+ "elif page == \"Visualizations\":\n",
472
+ " st.title(\"Data Visualizations\")\n",
473
+ "\n",
474
+ " # Plot 1: Price Distribution Across Categories\n",
475
+ " st.subheader(\"Price Distribution Across Categories\")\n",
476
+ " fig, ax = plt.subplots()\n",
477
+ " sns.boxplot(x=\"Category\", y=\"Base_Price\", data=data, ax=ax, palette=\"Set2\")\n",
478
+ " plt.xticks(rotation=30)\n",
479
+ " st.pyplot(fig)\n",
480
+ "\n",
481
+ " # Plot 2: Competitor Price vs. Base Price\n",
482
+ " st.subheader(\"Competitor Price vs. Base Price\")\n",
483
+ " fig, ax = plt.subplots()\n",
484
+ " sns.scatterplot(x=\"Base_Price\", y=\"Competitor_Price\", data=data, color=\"blue\", alpha=0.7, ax=ax)\n",
485
+ " st.pyplot(fig)\n",
486
+ "\n",
487
+ " # Plot 3: Seasonality Impact on Demand\n",
488
+ " st.subheader(\"Seasonality Impact on Demand\")\n",
489
+ " fig, ax = plt.subplots()\n",
490
+ " sns.scatterplot(x=\"Seasonality_Factor\", y=\"Demand\", data=data, color=\"green\", alpha=0.7, ax=ax)\n",
491
+ " st.pyplot(fig)\n",
492
+ "\n",
493
+ " # Plot 4: Price vs. Demand Relationship\n",
494
+ " st.subheader(\"Price vs. Demand Relationship\")\n",
495
+ " fig, ax = plt.subplots()\n",
496
+ " sns.scatterplot(x=\"Base_Price\", y=\"Demand\", data=data, color=\"red\", alpha=0.7, ax=ax)\n",
497
+ " st.pyplot(fig)\n",
498
+ "\n",
499
+ "elif page == \"Solution Implementation\":\n",
500
+ " st.title(\"Solution Implementation\")\n",
501
+ " st.write(\"\"\"\n",
502
+ " **Concepts Used:**\n",
503
+ " - **Multi-Armed Bandits**: To continuously optimize pricing strategy.\n",
504
+ " - **Bayesian Networks**: To model demand uncertainty based on price changes.\n",
505
+ " - **Multi-Criteria Decision Making (AHP)**: To balance revenue, demand, and competitiveness.\n",
506
+ "\n",
507
+ " **Next Steps:**\n",
508
+ " - Implement these models and test them in a real-world simulation.\n",
509
+ " - Analyze results and fine-tune the pricing strategy dynamically.\n",
510
+ " \"\"\")\n"
511
+ ]
512
+ },
513
+ {
514
+ "cell_type": "code",
515
+ "execution_count": null,
516
+ "metadata": {
517
+ "colab": {
518
+ "base_uri": "https://localhost:8080/"
519
+ },
520
+ "id": "FBiiIfnJG5CZ",
521
+ "outputId": "872566bf-aa7b-4397-9f50-2860be11e508"
522
+ },
523
+ "outputs": [
524
+ {
525
+ "name": "stdout",
526
+ "output_type": "stream",
527
+ "text": [
528
+ "Requirement already satisfied: streamlit in /usr/local/lib/python3.11/dist-packages (1.43.2)\n",
529
+ "Requirement already satisfied: altair<6,>=4.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (5.5.0)\n",
530
+ "Requirement already satisfied: blinker<2,>=1.0.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (1.9.0)\n",
531
+ "Requirement already satisfied: cachetools<6,>=4.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (5.5.2)\n",
532
+ "Requirement already satisfied: click<9,>=7.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (8.1.8)\n",
533
+ "Requirement already satisfied: numpy<3,>=1.23 in /usr/local/lib/python3.11/dist-packages (from streamlit) (1.26.4)\n",
534
+ "Requirement already satisfied: packaging<25,>=20 in /usr/local/lib/python3.11/dist-packages (from streamlit) (24.2)\n",
535
+ "Requirement already satisfied: pandas<3,>=1.4.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (2.2.2)\n",
536
+ "Requirement already satisfied: pillow<12,>=7.1.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (11.1.0)\n",
537
+ "Requirement already satisfied: protobuf<6,>=3.20 in /usr/local/lib/python3.11/dist-packages (from streamlit) (4.25.6)\n",
538
+ "Requirement already satisfied: pyarrow>=7.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (18.1.0)\n",
539
+ "Requirement already satisfied: requests<3,>=2.27 in /usr/local/lib/python3.11/dist-packages (from streamlit) (2.32.3)\n",
540
+ "Requirement already satisfied: tenacity<10,>=8.1.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (9.0.0)\n",
541
+ "Requirement already satisfied: toml<2,>=0.10.1 in /usr/local/lib/python3.11/dist-packages (from streamlit) (0.10.2)\n",
542
+ "Requirement already satisfied: typing-extensions<5,>=4.4.0 in /usr/local/lib/python3.11/dist-packages (from streamlit) (4.12.2)\n",
543
+ "Requirement already satisfied: watchdog<7,>=2.1.5 in /usr/local/lib/python3.11/dist-packages (from streamlit) (6.0.0)\n",
544
+ "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",
545
+ "Requirement already satisfied: pydeck<1,>=0.8.0b4 in /usr/local/lib/python3.11/dist-packages (from streamlit) (0.9.1)\n",
546
+ "Requirement already satisfied: tornado<7,>=6.0.3 in /usr/local/lib/python3.11/dist-packages (from streamlit) (6.4.2)\n",
547
+ "Requirement already satisfied: jinja2 in /usr/local/lib/python3.11/dist-packages (from altair<6,>=4.0->streamlit) (3.1.6)\n",
548
+ "Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.11/dist-packages (from altair<6,>=4.0->streamlit) (4.23.0)\n",
549
+ "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",
550
+ "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",
551
+ "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",
552
+ "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas<3,>=1.4.0->streamlit) (2025.1)\n",
553
+ "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas<3,>=1.4.0->streamlit) (2025.1)\n",
554
+ "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",
555
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests<3,>=2.27->streamlit) (3.10)\n",
556
+ "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",
557
+ "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",
558
+ "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",
559
+ "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",
560
+ "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",
561
+ "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",
562
+ "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",
563
+ "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",
564
+ "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",
565
+ "Requirement already satisfied: pyngrok in /usr/local/lib/python3.11/dist-packages (7.2.3)\n",
566
+ "Requirement already satisfied: PyYAML>=5.1 in /usr/local/lib/python3.11/dist-packages (from pyngrok) (6.0.2)\n"
567
+ ]
568
+ }
569
+ ],
570
+ "source": [
571
+ "!pip install streamlit\n"
572
+ ]
573
+ },
574
+ {
575
+ "cell_type": "code",
576
+ "execution_count": null,
577
+ "metadata": {
578
+ "id": "Ua2k4X94HmhK"
579
+ },
580
+ "outputs": [],
581
+ "source": [
582
+ "!streamlit run app.py &>/dev/null &\n"
583
+ ]
584
+ },
585
+ {
586
+ "cell_type": "code",
587
+ "execution_count": null,
588
+ "metadata": {
589
+ "colab": {
590
+ "base_uri": "https://localhost:8080/"
591
+ },
592
+ "id": "kAkim2pmJU3j",
593
+ "outputId": "04a6f08f-f878-4670-c7c2-8373b123a065"
594
+ },
595
+ "outputs": [
596
+ {
597
+ "name": "stdout",
598
+ "output_type": "stream",
599
+ "text": [
600
+ "Overwriting app.py\n"
601
+ ]
602
+ }
603
+ ],
604
+ "source": [
605
+ "%%writefile app.py\n",
606
+ "import streamlit as st\n",
607
+ "import matplotlib.pyplot as plt\n",
608
+ "import numpy as np\n",
609
+ "from sklearn.linear_model import LinearRegression\n",
610
+ "from sklearn.cluster import KMeans\n",
611
+ "import pandas as pd\n",
612
+ "\n",
613
+ "# App Title\n",
614
+ "st.title(\"Business Performance Analysis\")\n",
615
+ "\n",
616
+ "# Sidebar Navigation\n",
617
+ "st.sidebar.header(\"Navigation\")\n",
618
+ "page = st.sidebar.selectbox(\"Select a Page\", [\"Introduction\", \"Visualizations\", \"Solution\", \"Forecasting\", \"Customer Segmentation\", \"Expense Optimization\", \"Goal Tracker\"])\n",
619
+ "\n",
620
+ "# Page 1: Introduction\n",
621
+ "if page == \"Introduction\":\n",
622
+ " st.header(\"πŸ“Œ Introduction\")\n",
623
+ " st.markdown(\"\"\"\n",
624
+ " ## Understanding the Business Problem\n",
625
+ " Businesses today face significant challenges in optimizing **profitability, reducing costs, and maximizing customer value**.\n",
626
+ " Here are three key business issues:\n",
627
+ "\n",
628
+ " 1️⃣ **Revenue and Profitability Issues**\n",
629
+ " - Unpredictable revenue impacts long-term growth.\n",
630
+ " - High operational costs reduce net profit margins.\n",
631
+ "\n",
632
+ " 2️⃣ **Customer Retention & Engagement**\n",
633
+ " - Businesses struggle to understand customer behavior.\n",
634
+ " - Acquiring new customers is costlier than retaining existing ones.\n",
635
+ "\n",
636
+ " 3️⃣ **Data-Driven Decision Making**\n",
637
+ " - Many businesses lack real-time insights.\n",
638
+ " - Without proper data analysis, decisions are based on intuition rather than facts.\n",
639
+ "\n",
640
+ " ### πŸ” Our Key Approaches\n",
641
+ " - **Revenue & Cost Analysis**\n",
642
+ " - **Data Visualization for Business Insights**\n",
643
+ " - **Strategic Business Solutions**\n",
644
+ " - **Forecasting Future Trends**\n",
645
+ " - **Competitor Benchmarking**\n",
646
+ " - **Customer Segmentation**\n",
647
+ " - **Expense Optimization**\n",
648
+ " - **Goal Tracking & Business Strategy**\n",
649
+ " \"\"\")\n",
650
+ "\n",
651
+ "# Page 2: Visualizations\n",
652
+ "elif page == \"Visualizations\":\n",
653
+ " st.header(\"πŸ“Š Business Data Visualizations\")\n",
654
+ " st.subheader(\"πŸ“ˆ Revenue vs Costs\")\n",
655
+ " revenue = st.sidebar.number_input(\"Monthly Revenue ($)\", min_value=0, value=10000)\n",
656
+ " costs = st.sidebar.number_input(\"Monthly Costs ($)\", min_value=0, value=5000)\n",
657
+ " fig, ax = plt.subplots()\n",
658
+ " ax.bar([\"Revenue\", \"Costs\"], [revenue, costs], color=['green', 'red'])\n",
659
+ " st.pyplot(fig)\n",
660
+ "\n",
661
+ "\n",
662
+ "\n",
663
+ "# Page 3: Solution\n",
664
+ "elif page == \"Solution\":\n",
665
+ " st.header(\"πŸ“ˆ Business Solution & Insights\")\n",
666
+ " st.subheader(\"πŸ“Š Key Business Metrics\")\n",
667
+ " # Define revenue and costs globally so they can be accessed on multiple pages\n",
668
+ " revenues = st.sidebar.number_input(\"Monthly Revenue ($)\", min_value=0, value=10000)\n",
669
+ " costs = st.sidebar.number_input(\"Monthly Costs ($)\", min_value=0, value=5000)\n",
670
+ "\n",
671
+ " # Calculate profit using global revenue and costs\n",
672
+ " profit = revenues - costs\n",
673
+ "\n",
674
+ " # Display the result\n",
675
+ " st.metric(label=\"Total Profit ($)\", value=f\"${profit:,.2f}\")\n",
676
+ "\n",
677
+ "\n",
678
+ "# Page 4: Forecasting\n",
679
+ "elif page == \"Forecasting\":\n",
680
+ " st.header(\"πŸ“ˆ Future Revenue Prediction\")\n",
681
+ " months = np.array([1, 2, 3, 4, 5, 6]).reshape(-1, 1)\n",
682
+ " revenue_data = np.array([8000, 8500, 9000, 9400, 10000, 10500])\n",
683
+ " model = LinearRegression()\n",
684
+ " model.fit(months, revenue_data)\n",
685
+ " future_months = np.array([7, 8, 9]).reshape(-1, 1)\n",
686
+ " predicted_revenue = model.predict(future_months)\n",
687
+ " st.line_chart(np.append(revenue_data, predicted_revenue))\n",
688
+ "\n",
689
+ "# Page 5: Customer Segmentation\n",
690
+ "elif page == \"Customer Segmentation\":\n",
691
+ " st.header(\"πŸ›’ Customer Segmentation\")\n",
692
+ " customer_data = pd.DataFrame({\n",
693
+ " 'revenue': [200, 500, 800, 1200, 1500, 300],\n",
694
+ " 'purchases': [2, 5, 8, 12, 15, 3]\n",
695
+ " })\n",
696
+ " kmeans = KMeans(n_clusters=3)\n",
697
+ " customer_data['segment'] = kmeans.fit_predict(customer_data)\n",
698
+ " st.scatter_chart(customer_data, x='revenue', y='purchases', color='segment')\n",
699
+ "\n",
700
+ "# Page 6: Expense Optimization\n",
701
+ "elif page == \"Expense Optimization\":\n",
702
+ " st.header(\"πŸ’° Expense Optimization\")\n",
703
+ " expense_categories = [\"Marketing\", \"Salaries\", \"Infrastructure\", \"Miscellaneous\"]\n",
704
+ " expenses = [3000, 5000, 2000, 1000]\n",
705
+ " fig, ax = plt.subplots()\n",
706
+ " ax.pie(expenses, labels=expense_categories, autopct='%1.1f%%', startangle=140)\n",
707
+ " st.pyplot(fig)\n",
708
+ "\n",
709
+ "# Page 7: Goal Tracker\n",
710
+ "elif page == \"Goal Tracker\":\n",
711
+ " st.header(\"🎯 Business Goal Tracker\")\n",
712
+ "\n",
713
+ "# User inputs revenue goal\n",
714
+ " goal = st.number_input(\"Enter your revenue goal ($)\", min_value=0)\n",
715
+ "\n",
716
+ "# User inputs monthly revenue\n",
717
+ " revenue = st.sidebar.number_input(\"Monthly Revenue ($)\", min_value=0, value=10000)\n",
718
+ "\n",
719
+ "# Check if the goal is met\n",
720
+ " if goal < revenue:\n",
721
+ " st.warning(\"You have reached your revenue goal yet.\")\n",
722
+ " else:\n",
723
+ " progress = (revenue / goal) * 100 if goal else 0\n",
724
+ " st.progress(progress / 100)\n",
725
+ " st.write(f\"**Progress:** {progress:.2f}% of goal achieved\")"
726
+ ]
727
+ },
728
+ {
729
+ "cell_type": "code",
730
+ "execution_count": null,
731
+ "metadata": {
732
+ "id": "RJLfA30SJWwL"
733
+ },
734
+ "outputs": [],
735
+ "source": [
736
+ "!streamlit run app.py --server.port 8501 &>/dev/null &\n"
737
+ ]
738
+ },
739
+ {
740
+ "cell_type": "code",
741
+ "execution_count": null,
742
+ "metadata": {
743
+ "colab": {
744
+ "base_uri": "https://localhost:8080/"
745
+ },
746
+ "id": "kBDkEzTuJY76",
747
+ "outputId": "967997db-fa81-49f7-c61b-a0fd6522cb6d"
748
+ },
749
+ "outputs": [
750
+ {
751
+ "name": "stderr",
752
+ "output_type": "stream",
753
+ "text": [
754
+ "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"
755
+ ]
756
+ },
757
+ {
758
+ "name": "stdout",
759
+ "output_type": "stream",
760
+ "text": [
761
+ "Disconnecting: https://f327-34-171-10-70.ngrok-free.app\n",
762
+ "Access the Streamlit app at: NgrokTunnel: \"https://fb68-34-171-10-70.ngrok-free.app\" -> \"http://localhost:8501\"\n"
763
+ ]
764
+ }
765
+ ],
766
+ "source": [
767
+ "from pyngrok import ngrok\n",
768
+ "\n",
769
+ "# List all existing ngrok tunnels\n",
770
+ "tunnels = ngrok.get_tunnels()\n",
771
+ "# Check if there are any active tunnels before attempting to disconnect\n",
772
+ "if tunnels:\n",
773
+ " for tunnel in tunnels:\n",
774
+ " print(\"Disconnecting:\", tunnel.public_url)\n",
775
+ " ngrok.disconnect(tunnel.public_url) # Disconnect each active tunnel\n",
776
+ "else:\n",
777
+ " print(\"No active tunnels found.\")\n",
778
+ "\n",
779
+ "# Start a new tunnel\n",
780
+ "public_url = ngrok.connect(addr=\"8501\")\n",
781
+ "print(\"Access the Streamlit app at:\", public_url)"
782
+ ]
783
+ },
784
+ {
785
+ "cell_type": "code",
786
+ "execution_count": null,
787
+ "metadata": {
788
+ "id": "QLCKfkUZ3c9f"
789
+ },
790
+ "outputs": [],
791
+ "source": []
792
+ },
793
+ {
794
+ "cell_type": "code",
795
+ "execution_count": null,
796
+ "metadata": {
797
+ "id": "_ub8lpzdaUwe"
798
+ },
799
+ "outputs": [],
800
+ "source": []
801
+ },
802
+ {
803
+ "cell_type": "code",
804
+ "execution_count": null,
805
+ "metadata": {
806
+ "id": "fEj20rRGJafC"
807
+ },
808
+ "outputs": [],
809
+ "source": []
810
+ }
811
+ ],
812
+ "metadata": {
813
+ "colab": {
814
+ "provenance": []
815
+ },
816
+ "kernelspec": {
817
+ "display_name": "Python 3",
818
+ "name": "python3"
819
+ },
820
+ "language_info": {
821
+ "name": "python"
822
+ }
823
+ },
824
+ "nbformat": 4,
825
+ "nbformat_minor": 0
826
+ }