bartmiller commited on
Commit
e9627f4
1 Parent(s): 6bb6d93

Upload kaggle_data_and_huggingface.ipynb

Browse files
Files changed (1) hide show
  1. kaggle_data_and_huggingface.ipynb +813 -0
kaggle_data_and_huggingface.ipynb ADDED
@@ -0,0 +1,813 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "source": [
6
+ "https://www.kdnuggets.com/deploying-your-first-machine-learning-model"
7
+ ],
8
+ "metadata": {
9
+ "id": "MP7O1gtliL6n"
10
+ }
11
+ },
12
+ {
13
+ "cell_type": "code",
14
+ "source": [
15
+ "try:\n",
16
+ " import opendatasets as od\n",
17
+ " import pandas as pd\n",
18
+ "except:\n",
19
+ " !pip install opendatasets\n",
20
+ " import opendatasets as od\n",
21
+ "from os import path\n",
22
+ "\n",
23
+ "url = \"https://www.kaggle.com/datasets/uciml/glass\" ### kaggle dataset url here\n",
24
+ "data_dir = \"/content/\" ### directory where you want to save data\n",
25
+ "\n",
26
+ "# Go to the account tab and under API section, click Create New API Token.\n",
27
+ "\n",
28
+ "# A JSON file will be downloaded, open it locally or you can also use any online JSON viewer and upload it there.\n",
29
+ "\n",
30
+ "# On opening this file, you will find the username and key in it. Copy the username and password and paste it into the prompted Notebook cell.\n",
31
+ "# The content of the downloaded file would look like this.\n",
32
+ "\n",
33
+ "# {\"username\":<KAGGLE USERNAME>,\"key\":<KAGGLE KEY>}\n",
34
+ "\n",
35
+ "\n",
36
+ "def download_data(url, data_dir):\n",
37
+ " od.download(url, data_dir)"
38
+ ],
39
+ "metadata": {
40
+ "id": "5ewudtMkfnPL"
41
+ },
42
+ "execution_count": 4,
43
+ "outputs": []
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "source": [
48
+ "# comment out below if you already have the data downloaded\n",
49
+ "# download_data(url, data_dir)"
50
+ ],
51
+ "metadata": {
52
+ "id": "y-gTjPFggtAM"
53
+ },
54
+ "execution_count": 2,
55
+ "outputs": []
56
+ },
57
+ {
58
+ "cell_type": "code",
59
+ "execution_count": 5,
60
+ "metadata": {
61
+ "colab": {
62
+ "base_uri": "https://localhost:8080/",
63
+ "height": 143
64
+ },
65
+ "id": "lIYdn1woOS1n",
66
+ "outputId": "405db65f-b99a-4643-b8b0-2e06bcf6ea53"
67
+ },
68
+ "outputs": [
69
+ {
70
+ "output_type": "execute_result",
71
+ "data": {
72
+ "text/plain": [
73
+ " RI Na Mg Al Si K Ca Ba Fe Type\n",
74
+ "55 1.51769 12.45 2.71 1.29 73.70 0.56 9.06 0.0 0.24 1\n",
75
+ "184 1.51115 17.38 0.00 0.34 75.41 0.00 6.65 0.0 0.00 6\n",
76
+ "103 1.52725 13.80 3.15 0.66 70.57 0.08 11.64 0.0 0.00 2"
77
+ ],
78
+ "text/html": [
79
+ "\n",
80
+ " <div id=\"df-b2950a69-76d4-46ec-8a3d-96971bd2b1f1\" class=\"colab-df-container\">\n",
81
+ " <div>\n",
82
+ "<style scoped>\n",
83
+ " .dataframe tbody tr th:only-of-type {\n",
84
+ " vertical-align: middle;\n",
85
+ " }\n",
86
+ "\n",
87
+ " .dataframe tbody tr th {\n",
88
+ " vertical-align: top;\n",
89
+ " }\n",
90
+ "\n",
91
+ " .dataframe thead th {\n",
92
+ " text-align: right;\n",
93
+ " }\n",
94
+ "</style>\n",
95
+ "<table border=\"1\" class=\"dataframe\">\n",
96
+ " <thead>\n",
97
+ " <tr style=\"text-align: right;\">\n",
98
+ " <th></th>\n",
99
+ " <th>RI</th>\n",
100
+ " <th>Na</th>\n",
101
+ " <th>Mg</th>\n",
102
+ " <th>Al</th>\n",
103
+ " <th>Si</th>\n",
104
+ " <th>K</th>\n",
105
+ " <th>Ca</th>\n",
106
+ " <th>Ba</th>\n",
107
+ " <th>Fe</th>\n",
108
+ " <th>Type</th>\n",
109
+ " </tr>\n",
110
+ " </thead>\n",
111
+ " <tbody>\n",
112
+ " <tr>\n",
113
+ " <th>55</th>\n",
114
+ " <td>1.51769</td>\n",
115
+ " <td>12.45</td>\n",
116
+ " <td>2.71</td>\n",
117
+ " <td>1.29</td>\n",
118
+ " <td>73.70</td>\n",
119
+ " <td>0.56</td>\n",
120
+ " <td>9.06</td>\n",
121
+ " <td>0.0</td>\n",
122
+ " <td>0.24</td>\n",
123
+ " <td>1</td>\n",
124
+ " </tr>\n",
125
+ " <tr>\n",
126
+ " <th>184</th>\n",
127
+ " <td>1.51115</td>\n",
128
+ " <td>17.38</td>\n",
129
+ " <td>0.00</td>\n",
130
+ " <td>0.34</td>\n",
131
+ " <td>75.41</td>\n",
132
+ " <td>0.00</td>\n",
133
+ " <td>6.65</td>\n",
134
+ " <td>0.0</td>\n",
135
+ " <td>0.00</td>\n",
136
+ " <td>6</td>\n",
137
+ " </tr>\n",
138
+ " <tr>\n",
139
+ " <th>103</th>\n",
140
+ " <td>1.52725</td>\n",
141
+ " <td>13.80</td>\n",
142
+ " <td>3.15</td>\n",
143
+ " <td>0.66</td>\n",
144
+ " <td>70.57</td>\n",
145
+ " <td>0.08</td>\n",
146
+ " <td>11.64</td>\n",
147
+ " <td>0.0</td>\n",
148
+ " <td>0.00</td>\n",
149
+ " <td>2</td>\n",
150
+ " </tr>\n",
151
+ " </tbody>\n",
152
+ "</table>\n",
153
+ "</div>\n",
154
+ " <div class=\"colab-df-buttons\">\n",
155
+ "\n",
156
+ " <div class=\"colab-df-container\">\n",
157
+ " <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-b2950a69-76d4-46ec-8a3d-96971bd2b1f1')\"\n",
158
+ " title=\"Convert this dataframe to an interactive table.\"\n",
159
+ " style=\"display:none;\">\n",
160
+ "\n",
161
+ " <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\" viewBox=\"0 -960 960 960\">\n",
162
+ " <path d=\"M120-120v-720h720v720H120Zm60-500h600v-160H180v160Zm220 220h160v-160H400v160Zm0 220h160v-160H400v160ZM180-400h160v-160H180v160Zm440 0h160v-160H620v160ZM180-180h160v-160H180v160Zm440 0h160v-160H620v160Z\"/>\n",
163
+ " </svg>\n",
164
+ " </button>\n",
165
+ "\n",
166
+ " <style>\n",
167
+ " .colab-df-container {\n",
168
+ " display:flex;\n",
169
+ " gap: 12px;\n",
170
+ " }\n",
171
+ "\n",
172
+ " .colab-df-convert {\n",
173
+ " background-color: #E8F0FE;\n",
174
+ " border: none;\n",
175
+ " border-radius: 50%;\n",
176
+ " cursor: pointer;\n",
177
+ " display: none;\n",
178
+ " fill: #1967D2;\n",
179
+ " height: 32px;\n",
180
+ " padding: 0 0 0 0;\n",
181
+ " width: 32px;\n",
182
+ " }\n",
183
+ "\n",
184
+ " .colab-df-convert:hover {\n",
185
+ " background-color: #E2EBFA;\n",
186
+ " box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
187
+ " fill: #174EA6;\n",
188
+ " }\n",
189
+ "\n",
190
+ " .colab-df-buttons div {\n",
191
+ " margin-bottom: 4px;\n",
192
+ " }\n",
193
+ "\n",
194
+ " [theme=dark] .colab-df-convert {\n",
195
+ " background-color: #3B4455;\n",
196
+ " fill: #D2E3FC;\n",
197
+ " }\n",
198
+ "\n",
199
+ " [theme=dark] .colab-df-convert:hover {\n",
200
+ " background-color: #434B5C;\n",
201
+ " box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n",
202
+ " filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n",
203
+ " fill: #FFFFFF;\n",
204
+ " }\n",
205
+ " </style>\n",
206
+ "\n",
207
+ " <script>\n",
208
+ " const buttonEl =\n",
209
+ " document.querySelector('#df-b2950a69-76d4-46ec-8a3d-96971bd2b1f1 button.colab-df-convert');\n",
210
+ " buttonEl.style.display =\n",
211
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
212
+ "\n",
213
+ " async function convertToInteractive(key) {\n",
214
+ " const element = document.querySelector('#df-b2950a69-76d4-46ec-8a3d-96971bd2b1f1');\n",
215
+ " const dataTable =\n",
216
+ " await google.colab.kernel.invokeFunction('convertToInteractive',\n",
217
+ " [key], {});\n",
218
+ " if (!dataTable) return;\n",
219
+ "\n",
220
+ " const docLinkHtml = 'Like what you see? Visit the ' +\n",
221
+ " '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n",
222
+ " + ' to learn more about interactive tables.';\n",
223
+ " element.innerHTML = '';\n",
224
+ " dataTable['output_type'] = 'display_data';\n",
225
+ " await google.colab.output.renderOutput(dataTable, element);\n",
226
+ " const docLink = document.createElement('div');\n",
227
+ " docLink.innerHTML = docLinkHtml;\n",
228
+ " element.appendChild(docLink);\n",
229
+ " }\n",
230
+ " </script>\n",
231
+ " </div>\n",
232
+ "\n",
233
+ "\n",
234
+ "<div id=\"df-c39206fc-c582-432b-bf27-e108ba1cc6c6\">\n",
235
+ " <button class=\"colab-df-quickchart\" onclick=\"quickchart('df-c39206fc-c582-432b-bf27-e108ba1cc6c6')\"\n",
236
+ " title=\"Suggest charts\"\n",
237
+ " style=\"display:none;\">\n",
238
+ "\n",
239
+ "<svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n",
240
+ " width=\"24px\">\n",
241
+ " <g>\n",
242
+ " <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",
243
+ " </g>\n",
244
+ "</svg>\n",
245
+ " </button>\n",
246
+ "\n",
247
+ "<style>\n",
248
+ " .colab-df-quickchart {\n",
249
+ " --bg-color: #E8F0FE;\n",
250
+ " --fill-color: #1967D2;\n",
251
+ " --hover-bg-color: #E2EBFA;\n",
252
+ " --hover-fill-color: #174EA6;\n",
253
+ " --disabled-fill-color: #AAA;\n",
254
+ " --disabled-bg-color: #DDD;\n",
255
+ " }\n",
256
+ "\n",
257
+ " [theme=dark] .colab-df-quickchart {\n",
258
+ " --bg-color: #3B4455;\n",
259
+ " --fill-color: #D2E3FC;\n",
260
+ " --hover-bg-color: #434B5C;\n",
261
+ " --hover-fill-color: #FFFFFF;\n",
262
+ " --disabled-bg-color: #3B4455;\n",
263
+ " --disabled-fill-color: #666;\n",
264
+ " }\n",
265
+ "\n",
266
+ " .colab-df-quickchart {\n",
267
+ " background-color: var(--bg-color);\n",
268
+ " border: none;\n",
269
+ " border-radius: 50%;\n",
270
+ " cursor: pointer;\n",
271
+ " display: none;\n",
272
+ " fill: var(--fill-color);\n",
273
+ " height: 32px;\n",
274
+ " padding: 0;\n",
275
+ " width: 32px;\n",
276
+ " }\n",
277
+ "\n",
278
+ " .colab-df-quickchart:hover {\n",
279
+ " background-color: var(--hover-bg-color);\n",
280
+ " box-shadow: 0 1px 2px rgba(60, 64, 67, 0.3), 0 1px 3px 1px rgba(60, 64, 67, 0.15);\n",
281
+ " fill: var(--button-hover-fill-color);\n",
282
+ " }\n",
283
+ "\n",
284
+ " .colab-df-quickchart-complete:disabled,\n",
285
+ " .colab-df-quickchart-complete:disabled:hover {\n",
286
+ " background-color: var(--disabled-bg-color);\n",
287
+ " fill: var(--disabled-fill-color);\n",
288
+ " box-shadow: none;\n",
289
+ " }\n",
290
+ "\n",
291
+ " .colab-df-spinner {\n",
292
+ " border: 2px solid var(--fill-color);\n",
293
+ " border-color: transparent;\n",
294
+ " border-bottom-color: var(--fill-color);\n",
295
+ " animation:\n",
296
+ " spin 1s steps(1) infinite;\n",
297
+ " }\n",
298
+ "\n",
299
+ " @keyframes spin {\n",
300
+ " 0% {\n",
301
+ " border-color: transparent;\n",
302
+ " border-bottom-color: var(--fill-color);\n",
303
+ " border-left-color: var(--fill-color);\n",
304
+ " }\n",
305
+ " 20% {\n",
306
+ " border-color: transparent;\n",
307
+ " border-left-color: var(--fill-color);\n",
308
+ " border-top-color: var(--fill-color);\n",
309
+ " }\n",
310
+ " 30% {\n",
311
+ " border-color: transparent;\n",
312
+ " border-left-color: var(--fill-color);\n",
313
+ " border-top-color: var(--fill-color);\n",
314
+ " border-right-color: var(--fill-color);\n",
315
+ " }\n",
316
+ " 40% {\n",
317
+ " border-color: transparent;\n",
318
+ " border-right-color: var(--fill-color);\n",
319
+ " border-top-color: var(--fill-color);\n",
320
+ " }\n",
321
+ " 60% {\n",
322
+ " border-color: transparent;\n",
323
+ " border-right-color: var(--fill-color);\n",
324
+ " }\n",
325
+ " 80% {\n",
326
+ " border-color: transparent;\n",
327
+ " border-right-color: var(--fill-color);\n",
328
+ " border-bottom-color: var(--fill-color);\n",
329
+ " }\n",
330
+ " 90% {\n",
331
+ " border-color: transparent;\n",
332
+ " border-bottom-color: var(--fill-color);\n",
333
+ " }\n",
334
+ " }\n",
335
+ "</style>\n",
336
+ "\n",
337
+ " <script>\n",
338
+ " async function quickchart(key) {\n",
339
+ " const quickchartButtonEl =\n",
340
+ " document.querySelector('#' + key + ' button');\n",
341
+ " quickchartButtonEl.disabled = true; // To prevent multiple clicks.\n",
342
+ " quickchartButtonEl.classList.add('colab-df-spinner');\n",
343
+ " try {\n",
344
+ " const charts = await google.colab.kernel.invokeFunction(\n",
345
+ " 'suggestCharts', [key], {});\n",
346
+ " } catch (error) {\n",
347
+ " console.error('Error during call to suggestCharts:', error);\n",
348
+ " }\n",
349
+ " quickchartButtonEl.classList.remove('colab-df-spinner');\n",
350
+ " quickchartButtonEl.classList.add('colab-df-quickchart-complete');\n",
351
+ " }\n",
352
+ " (() => {\n",
353
+ " let quickchartButtonEl =\n",
354
+ " document.querySelector('#df-c39206fc-c582-432b-bf27-e108ba1cc6c6 button');\n",
355
+ " quickchartButtonEl.style.display =\n",
356
+ " google.colab.kernel.accessAllowed ? 'block' : 'none';\n",
357
+ " })();\n",
358
+ " </script>\n",
359
+ "</div>\n",
360
+ "\n",
361
+ " </div>\n",
362
+ " </div>\n"
363
+ ]
364
+ },
365
+ "metadata": {},
366
+ "execution_count": 5
367
+ }
368
+ ],
369
+ "source": [
370
+ "import pandas as pd\n",
371
+ "# use path below for colab\n",
372
+ "# glass_df = pd.read_csv(\"/content/glass/glass.csv\")\n",
373
+ "glass_df = pd.read_csv(\"glass.csv\")\n",
374
+ "\n",
375
+ "glass_df = glass_df.sample(frac = 1)\n",
376
+ "glass_df.head(3)"
377
+ ]
378
+ },
379
+ {
380
+ "cell_type": "code",
381
+ "source": [
382
+ "from sklearn.model_selection import train_test_split\n",
383
+ "\n",
384
+ "X = glass_df.drop(\"Type\",axis=1)\n",
385
+ "y = glass_df.Type\n",
386
+ "\n",
387
+ "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=125)"
388
+ ],
389
+ "metadata": {
390
+ "id": "7_eWUKS6hV2o"
391
+ },
392
+ "execution_count": 6,
393
+ "outputs": []
394
+ },
395
+ {
396
+ "cell_type": "code",
397
+ "source": [
398
+ "from sklearn.ensemble import RandomForestClassifier\n",
399
+ "from sklearn.preprocessing import StandardScaler\n",
400
+ "from sklearn.impute import SimpleImputer\n",
401
+ "from sklearn.pipeline import Pipeline\n",
402
+ "\n",
403
+ "\n",
404
+ "pipe = Pipeline(\n",
405
+ " steps=[\n",
406
+ " (\"imputer\", SimpleImputer()),\n",
407
+ " (\"scaler\", StandardScaler()),\n",
408
+ " (\"model\", RandomForestClassifier(n_estimators=100, random_state=125)),\n",
409
+ " ]\n",
410
+ ")\n",
411
+ "pipe.fit(X_train, y_train)\n",
412
+ "\n",
413
+ "pipe.score(X_test, y_test)"
414
+ ],
415
+ "metadata": {
416
+ "colab": {
417
+ "base_uri": "https://localhost:8080/"
418
+ },
419
+ "id": "MTMLGHGuhvAA",
420
+ "outputId": "d4c7a6b6-6774-47d7-d288-2d1a29dbd9c5"
421
+ },
422
+ "execution_count": 7,
423
+ "outputs": [
424
+ {
425
+ "output_type": "execute_result",
426
+ "data": {
427
+ "text/plain": [
428
+ "0.7846153846153846"
429
+ ]
430
+ },
431
+ "metadata": {},
432
+ "execution_count": 7
433
+ }
434
+ ]
435
+ },
436
+ {
437
+ "cell_type": "code",
438
+ "source": [
439
+ "from sklearn.metrics import classification_report\n",
440
+ "\n",
441
+ "y_pred = pipe.predict(X_test)\n",
442
+ "print(classification_report(y_test,y_pred))"
443
+ ],
444
+ "metadata": {
445
+ "colab": {
446
+ "base_uri": "https://localhost:8080/"
447
+ },
448
+ "id": "EREHPUy_h0Zq",
449
+ "outputId": "2a4255fb-c2b4-4fc8-cec8-f07bd619cbe0"
450
+ },
451
+ "execution_count": 8,
452
+ "outputs": [
453
+ {
454
+ "output_type": "stream",
455
+ "name": "stdout",
456
+ "text": [
457
+ " precision recall f1-score support\n",
458
+ "\n",
459
+ " 1 0.70 0.91 0.79 23\n",
460
+ " 2 0.87 0.80 0.83 25\n",
461
+ " 3 1.00 0.33 0.50 6\n",
462
+ " 5 0.67 1.00 0.80 2\n",
463
+ " 6 1.00 1.00 1.00 2\n",
464
+ " 7 0.80 0.57 0.67 7\n",
465
+ "\n",
466
+ " accuracy 0.78 65\n",
467
+ " macro avg 0.84 0.77 0.77 65\n",
468
+ "weighted avg 0.81 0.78 0.77 65\n",
469
+ "\n"
470
+ ]
471
+ }
472
+ ]
473
+ },
474
+ {
475
+ "cell_type": "code",
476
+ "source": [
477
+ "!pip install skops"
478
+ ],
479
+ "metadata": {
480
+ "colab": {
481
+ "base_uri": "https://localhost:8080/"
482
+ },
483
+ "id": "56jjXsBxiAiB",
484
+ "outputId": "27f71a89-8eec-4e8a-b23b-f3f1f7329cbe"
485
+ },
486
+ "execution_count": 8,
487
+ "outputs": [
488
+ {
489
+ "output_type": "stream",
490
+ "name": "stdout",
491
+ "text": [
492
+ "Collecting skops\n",
493
+ " Downloading skops-0.9.0-py3-none-any.whl (120 kB)\n",
494
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m120.7/120.7 kB\u001b[0m \u001b[31m1.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
495
+ "\u001b[?25hRequirement already satisfied: scikit-learn>=0.24 in /usr/local/lib/python3.10/dist-packages (from skops) (1.2.2)\n",
496
+ "Requirement already satisfied: huggingface-hub>=0.17.0 in /usr/local/lib/python3.10/dist-packages (from skops) (0.19.4)\n",
497
+ "Requirement already satisfied: tabulate>=0.8.8 in /usr/local/lib/python3.10/dist-packages (from skops) (0.9.0)\n",
498
+ "Requirement already satisfied: packaging>=17.0 in /usr/local/lib/python3.10/dist-packages (from skops) (23.2)\n",
499
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.17.0->skops) (3.13.1)\n",
500
+ "Requirement already satisfied: fsspec>=2023.5.0 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.17.0->skops) (2023.6.0)\n",
501
+ "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.17.0->skops) (2.31.0)\n",
502
+ "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.17.0->skops) (4.66.1)\n",
503
+ "Requirement already satisfied: pyyaml>=5.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.17.0->skops) (6.0.1)\n",
504
+ "Requirement already satisfied: typing-extensions>=3.7.4.3 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.17.0->skops) (4.5.0)\n",
505
+ "Requirement already satisfied: numpy>=1.17.3 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=0.24->skops) (1.23.5)\n",
506
+ "Requirement already satisfied: scipy>=1.3.2 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=0.24->skops) (1.11.4)\n",
507
+ "Requirement already satisfied: joblib>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=0.24->skops) (1.3.2)\n",
508
+ "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn>=0.24->skops) (3.2.0)\n",
509
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.17.0->skops) (3.3.2)\n",
510
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.17.0->skops) (3.6)\n",
511
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.17.0->skops) (2.0.7)\n",
512
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.17.0->skops) (2023.11.17)\n",
513
+ "Installing collected packages: skops\n",
514
+ "Successfully installed skops-0.9.0\n"
515
+ ]
516
+ }
517
+ ]
518
+ },
519
+ {
520
+ "cell_type": "code",
521
+ "source": [
522
+ "import skops.io as sio\n",
523
+ "sio.dump(pipe, \"glass_pipeline.skops\")"
524
+ ],
525
+ "metadata": {
526
+ "id": "wZARmF26h4S9"
527
+ },
528
+ "execution_count": 9,
529
+ "outputs": []
530
+ },
531
+ {
532
+ "cell_type": "code",
533
+ "source": [
534
+ "sio.load(\"glass_pipeline.skops\", trusted=True)\n"
535
+ ],
536
+ "metadata": {
537
+ "colab": {
538
+ "base_uri": "https://localhost:8080/",
539
+ "height": 161
540
+ },
541
+ "id": "DQ1zj-mjiIRL",
542
+ "outputId": "b93c6edf-c16f-403c-ef69-38970b7c2b4f"
543
+ },
544
+ "execution_count": 10,
545
+ "outputs": [
546
+ {
547
+ "output_type": "execute_result",
548
+ "data": {
549
+ "text/plain": [
550
+ "Pipeline(steps=[('imputer', SimpleImputer()), ('scaler', StandardScaler()),\n",
551
+ " ('model', RandomForestClassifier(random_state=125))])"
552
+ ],
553
+ "text/html": [
554
+ "<style>#sk-container-id-1 {color: black;background-color: white;}#sk-container-id-1 pre{padding: 0;}#sk-container-id-1 div.sk-toggleable {background-color: white;}#sk-container-id-1 label.sk-toggleable__label {cursor: pointer;display: block;width: 100%;margin-bottom: 0;padding: 0.3em;box-sizing: border-box;text-align: center;}#sk-container-id-1 label.sk-toggleable__label-arrow:before {content: \"▸\";float: left;margin-right: 0.25em;color: #696969;}#sk-container-id-1 label.sk-toggleable__label-arrow:hover:before {color: black;}#sk-container-id-1 div.sk-estimator:hover label.sk-toggleable__label-arrow:before {color: black;}#sk-container-id-1 div.sk-toggleable__content {max-height: 0;max-width: 0;overflow: hidden;text-align: left;background-color: #f0f8ff;}#sk-container-id-1 div.sk-toggleable__content pre {margin: 0.2em;color: black;border-radius: 0.25em;background-color: #f0f8ff;}#sk-container-id-1 input.sk-toggleable__control:checked~div.sk-toggleable__content {max-height: 200px;max-width: 100%;overflow: auto;}#sk-container-id-1 input.sk-toggleable__control:checked~label.sk-toggleable__label-arrow:before {content: \"▾\";}#sk-container-id-1 div.sk-estimator input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-label input.sk-toggleable__control:checked~label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 input.sk-hidden--visually {border: 0;clip: rect(1px 1px 1px 1px);clip: rect(1px, 1px, 1px, 1px);height: 1px;margin: -1px;overflow: hidden;padding: 0;position: absolute;width: 1px;}#sk-container-id-1 div.sk-estimator {font-family: monospace;background-color: #f0f8ff;border: 1px dotted black;border-radius: 0.25em;box-sizing: border-box;margin-bottom: 0.5em;}#sk-container-id-1 div.sk-estimator:hover {background-color: #d4ebff;}#sk-container-id-1 div.sk-parallel-item::after {content: \"\";width: 100%;border-bottom: 1px solid gray;flex-grow: 1;}#sk-container-id-1 div.sk-label:hover label.sk-toggleable__label {background-color: #d4ebff;}#sk-container-id-1 div.sk-serial::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: 0;}#sk-container-id-1 div.sk-serial {display: flex;flex-direction: column;align-items: center;background-color: white;padding-right: 0.2em;padding-left: 0.2em;position: relative;}#sk-container-id-1 div.sk-item {position: relative;z-index: 1;}#sk-container-id-1 div.sk-parallel {display: flex;align-items: stretch;justify-content: center;background-color: white;position: relative;}#sk-container-id-1 div.sk-item::before, #sk-container-id-1 div.sk-parallel-item::before {content: \"\";position: absolute;border-left: 1px solid gray;box-sizing: border-box;top: 0;bottom: 0;left: 50%;z-index: -1;}#sk-container-id-1 div.sk-parallel-item {display: flex;flex-direction: column;z-index: 1;position: relative;background-color: white;}#sk-container-id-1 div.sk-parallel-item:first-child::after {align-self: flex-end;width: 50%;}#sk-container-id-1 div.sk-parallel-item:last-child::after {align-self: flex-start;width: 50%;}#sk-container-id-1 div.sk-parallel-item:only-child::after {width: 0;}#sk-container-id-1 div.sk-dashed-wrapped {border: 1px dashed gray;margin: 0 0.4em 0.5em 0.4em;box-sizing: border-box;padding-bottom: 0.4em;background-color: white;}#sk-container-id-1 div.sk-label label {font-family: monospace;font-weight: bold;display: inline-block;line-height: 1.2em;}#sk-container-id-1 div.sk-label-container {text-align: center;}#sk-container-id-1 div.sk-container {/* jupyter's `normalize.less` sets `[hidden] { display: none; }` but bootstrap.min.css set `[hidden] { display: none !important; }` so we also need the `!important` here to be able to override the default hidden behavior on the sphinx rendered scikit-learn.org. See: https://github.com/scikit-learn/scikit-learn/issues/21755 */display: inline-block !important;position: relative;}#sk-container-id-1 div.sk-text-repr-fallback {display: none;}</style><div id=\"sk-container-id-1\" class=\"sk-top-container\"><div class=\"sk-text-repr-fallback\"><pre>Pipeline(steps=[(&#x27;imputer&#x27;, SimpleImputer()), (&#x27;scaler&#x27;, StandardScaler()),\n",
555
+ " (&#x27;model&#x27;, RandomForestClassifier(random_state=125))])</pre><b>In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook. <br />On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.</b></div><div class=\"sk-container\" hidden><div class=\"sk-item sk-dashed-wrapped\"><div class=\"sk-label-container\"><div class=\"sk-label sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-1\" type=\"checkbox\" ><label for=\"sk-estimator-id-1\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">Pipeline</label><div class=\"sk-toggleable__content\"><pre>Pipeline(steps=[(&#x27;imputer&#x27;, SimpleImputer()), (&#x27;scaler&#x27;, StandardScaler()),\n",
556
+ " (&#x27;model&#x27;, RandomForestClassifier(random_state=125))])</pre></div></div></div><div class=\"sk-serial\"><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-2\" type=\"checkbox\" ><label for=\"sk-estimator-id-2\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">SimpleImputer</label><div class=\"sk-toggleable__content\"><pre>SimpleImputer()</pre></div></div></div><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-3\" type=\"checkbox\" ><label for=\"sk-estimator-id-3\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">StandardScaler</label><div class=\"sk-toggleable__content\"><pre>StandardScaler()</pre></div></div></div><div class=\"sk-item\"><div class=\"sk-estimator sk-toggleable\"><input class=\"sk-toggleable__control sk-hidden--visually\" id=\"sk-estimator-id-4\" type=\"checkbox\" ><label for=\"sk-estimator-id-4\" class=\"sk-toggleable__label sk-toggleable__label-arrow\">RandomForestClassifier</label><div class=\"sk-toggleable__content\"><pre>RandomForestClassifier(random_state=125)</pre></div></div></div></div></div></div></div>"
557
+ ]
558
+ },
559
+ "metadata": {},
560
+ "execution_count": 10
561
+ }
562
+ ]
563
+ },
564
+ {
565
+ "cell_type": "code",
566
+ "source": [
567
+ "!pip install gradio"
568
+ ],
569
+ "metadata": {
570
+ "colab": {
571
+ "base_uri": "https://localhost:8080/"
572
+ },
573
+ "id": "beFfVpBQiWMo",
574
+ "outputId": "13434ca2-9b7e-433a-b805-b565805b936b"
575
+ },
576
+ "execution_count": 11,
577
+ "outputs": [
578
+ {
579
+ "output_type": "stream",
580
+ "name": "stdout",
581
+ "text": [
582
+ "Requirement already satisfied: gradio in /usr/local/lib/python3.10/dist-packages (4.12.0)\n",
583
+ "Requirement already satisfied: aiofiles<24.0,>=22.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (23.2.1)\n",
584
+ "Requirement already satisfied: altair<6.0,>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.2.2)\n",
585
+ "Requirement already satisfied: fastapi in /usr/local/lib/python3.10/dist-packages (from gradio) (0.108.0)\n",
586
+ "Requirement already satisfied: ffmpy in /usr/local/lib/python3.10/dist-packages (from gradio) (0.3.1)\n",
587
+ "Requirement already satisfied: gradio-client==0.8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.8.0)\n",
588
+ "Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from gradio) (0.26.0)\n",
589
+ "Requirement already satisfied: huggingface-hub>=0.19.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.19.4)\n",
590
+ "Requirement already satisfied: importlib-resources<7.0,>=1.3 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.1.1)\n",
591
+ "Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.1.2)\n",
592
+ "Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.1.3)\n",
593
+ "Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.7.1)\n",
594
+ "Requirement already satisfied: numpy~=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.23.5)\n",
595
+ "Requirement already satisfied: orjson~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (3.9.10)\n",
596
+ "Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio) (23.2)\n",
597
+ "Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (1.5.3)\n",
598
+ "Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (9.4.0)\n",
599
+ "Requirement already satisfied: pydantic>=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.5.3)\n",
600
+ "Requirement already satisfied: pydub in /usr/local/lib/python3.10/dist-packages (from gradio) (0.25.1)\n",
601
+ "Requirement already satisfied: python-multipart in /usr/local/lib/python3.10/dist-packages (from gradio) (0.0.6)\n",
602
+ "Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (6.0.1)\n",
603
+ "Requirement already satisfied: semantic-version~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (2.10.0)\n",
604
+ "Requirement already satisfied: tomlkit==0.12.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.12.0)\n",
605
+ "Requirement already satisfied: typer[all]<1.0,>=0.9 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.9.0)\n",
606
+ "Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (4.9.0)\n",
607
+ "Requirement already satisfied: uvicorn>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio) (0.25.0)\n",
608
+ "Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==0.8.0->gradio) (2023.6.0)\n",
609
+ "Requirement already satisfied: websockets<12.0,>=10.0 in /usr/local/lib/python3.10/dist-packages (from gradio-client==0.8.0->gradio) (11.0.3)\n",
610
+ "Requirement already satisfied: entrypoints in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.4)\n",
611
+ "Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (4.19.2)\n",
612
+ "Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio) (0.12.0)\n",
613
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (3.13.1)\n",
614
+ "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (2.31.0)\n",
615
+ "Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.19.3->gradio) (4.66.1)\n",
616
+ "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.2.0)\n",
617
+ "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (0.12.1)\n",
618
+ "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (4.46.0)\n",
619
+ "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (1.4.5)\n",
620
+ "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (3.1.1)\n",
621
+ "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio) (2.8.2)\n",
622
+ "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio) (2023.3.post1)\n",
623
+ "Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (0.6.0)\n",
624
+ "Requirement already satisfied: pydantic-core==2.14.6 in /usr/local/lib/python3.10/dist-packages (from pydantic>=2.0->gradio) (2.14.6)\n",
625
+ "Requirement already satisfied: click<9.0.0,>=7.1.1 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (8.1.7)\n",
626
+ "Requirement already satisfied: colorama<0.5.0,>=0.4.3 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (0.4.6)\n",
627
+ "Requirement already satisfied: shellingham<2.0.0,>=1.3.0 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (1.5.4)\n",
628
+ "Requirement already satisfied: rich<14.0.0,>=10.11.0 in /usr/local/lib/python3.10/dist-packages (from typer[all]<1.0,>=0.9->gradio) (13.7.0)\n",
629
+ "Requirement already satisfied: h11>=0.8 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio) (0.14.0)\n",
630
+ "Requirement already satisfied: starlette<0.33.0,>=0.29.0 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio) (0.32.0.post1)\n",
631
+ "Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (3.7.1)\n",
632
+ "Requirement already satisfied: certifi in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (2023.11.17)\n",
633
+ "Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (1.0.2)\n",
634
+ "Requirement already satisfied: idna in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (3.6)\n",
635
+ "Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->gradio) (1.3.0)\n",
636
+ "Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (23.1.0)\n",
637
+ "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (2023.11.2)\n",
638
+ "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.32.0)\n",
639
+ "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio) (0.15.2)\n",
640
+ "Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.10/dist-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio) (1.16.0)\n",
641
+ "Requirement already satisfied: markdown-it-py>=2.2.0 in /usr/local/lib/python3.10/dist-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (3.0.0)\n",
642
+ "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /usr/local/lib/python3.10/dist-packages (from rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (2.16.1)\n",
643
+ "Requirement already satisfied: exceptiongroup in /usr/local/lib/python3.10/dist-packages (from anyio->httpx->gradio) (1.2.0)\n",
644
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.3->gradio) (3.3.2)\n",
645
+ "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->huggingface-hub>=0.19.3->gradio) (2.0.7)\n",
646
+ "Requirement already satisfied: mdurl~=0.1 in /usr/local/lib/python3.10/dist-packages (from markdown-it-py>=2.2.0->rich<14.0.0,>=10.11.0->typer[all]<1.0,>=0.9->gradio) (0.1.2)\n"
647
+ ]
648
+ }
649
+ ]
650
+ },
651
+ {
652
+ "cell_type": "code",
653
+ "source": [
654
+ "!pip install --upgrade typing\n",
655
+ "\n"
656
+ ],
657
+ "metadata": {
658
+ "colab": {
659
+ "base_uri": "https://localhost:8080/"
660
+ },
661
+ "id": "hkRt-nm-i7n3",
662
+ "outputId": "fb8b64cf-1033-4ac3-a37b-6c2b47651645"
663
+ },
664
+ "execution_count": 12,
665
+ "outputs": [
666
+ {
667
+ "output_type": "stream",
668
+ "name": "stdout",
669
+ "text": [
670
+ "Requirement already satisfied: typing in /usr/local/lib/python3.10/dist-packages (3.7.4.3)\n"
671
+ ]
672
+ }
673
+ ]
674
+ },
675
+ {
676
+ "cell_type": "code",
677
+ "source": [
678
+ "import gradio as gr\n",
679
+ "import skops.io as sio\n",
680
+ "\n",
681
+ "pipe = sio.load(\"glass_pipeline.skops\", trusted=True)\n",
682
+ "\n",
683
+ "classes = [\n",
684
+ " \"None\",\n",
685
+ " \"Building Windows Float Processed\",\n",
686
+ " \"Building Windows Non Float Processed\",\n",
687
+ " \"Vehicle Windows Float Processed\",\n",
688
+ " \"Vehicle Windows Non Float Processed\",\n",
689
+ " \"Containers\",\n",
690
+ " \"Tableware\",\n",
691
+ " \"Headlamps\",\n",
692
+ "]\n",
693
+ "\n",
694
+ "\n",
695
+ "def classifier(RI, Na, Mg, Al, Si, K, Ca, Ba, Fe):\n",
696
+ " pred_glass = pipe.predict([[RI, Na, Mg, Al, Si, K, Ca, Ba, Fe]])[0]\n",
697
+ " label = f\"Predicted Glass label: **{classes[pred_glass]}**\"\n",
698
+ " return label\n",
699
+ "\n",
700
+ "\n",
701
+ "inputs = [\n",
702
+ " gr.Slider(1.51, 1.54, step=0.01, label=\"Refractive Index\"),\n",
703
+ " gr.Slider(10, 17, step=1, label=\"Sodium\"),\n",
704
+ " gr.Slider(0, 4.5, step=0.5, label=\"Magnesium\"),\n",
705
+ " gr.Slider(0.3, 3.5, step=0.1, label=\"Aluminum\"),\n",
706
+ " gr.Slider(69.8, 75.4, step=0.1, label=\"Silicon\"),\n",
707
+ " gr.Slider(0, 6.2, step=0.1, label=\"Potassium\"),\n",
708
+ " gr.Slider(5.4, 16.19, step=0.1, label=\"Calcium\"),\n",
709
+ " gr.Slider(0, 3, step=0.1, label=\"Barium\"),\n",
710
+ " gr.Slider(0, 0.5, step=0.1, label=\"Iron\"),\n",
711
+ "]\n",
712
+ "outputs = [gr.Label(num_top_classes=7)]\n",
713
+ "\n",
714
+ "title = \"Glass Classification\"\n",
715
+ "description = \"Enter the details to correctly identify glass type?\"\n",
716
+ "\n",
717
+ "gr.Interface(\n",
718
+ " fn=classifier,\n",
719
+ " inputs=inputs,\n",
720
+ " outputs=outputs,\n",
721
+ " title=title,\n",
722
+ " description=description,\n",
723
+ ").launch()"
724
+ ],
725
+ "metadata": {
726
+ "colab": {
727
+ "base_uri": "https://localhost:8080/",
728
+ "height": 1000
729
+ },
730
+ "id": "A8KXp_EFiS1U",
731
+ "outputId": "c021cdbf-b938-4951-f5e7-8bc0988e9d8a"
732
+ },
733
+ "execution_count": 1,
734
+ "outputs": [
735
+ {
736
+ "output_type": "stream",
737
+ "name": "stderr",
738
+ "text": [
739
+ "Exception in thread Thread-5 (attachment_entry):\n",
740
+ "Traceback (most recent call last):\n",
741
+ " File \"/usr/local/lib/python3.10/dist-packages/debugpy/server/api.py\", line 237, in listen\n",
742
+ " sock, _ = endpoints_listener.accept()\n",
743
+ " File \"/usr/lib/python3.10/socket.py\", line 293, in accept\n",
744
+ " fd, addr = self._accept()\n",
745
+ "TimeoutError: timed out\n",
746
+ "\n",
747
+ "During handling of the above exception, another exception occurred:\n",
748
+ "\n",
749
+ "Traceback (most recent call last):\n",
750
+ " File \"/usr/lib/python3.10/threading.py\", line 1016, in _bootstrap_inner\n",
751
+ " self.run()\n",
752
+ " File \"/usr/lib/python3.10/threading.py\", line 953, in run\n",
753
+ " self._target(*self._args, **self._kwargs)\n",
754
+ " File \"/usr/local/lib/python3.10/dist-packages/google/colab/_debugpy.py\", line 52, in attachment_entry\n",
755
+ " debugpy.listen(_dap_port)\n",
756
+ " File \"/usr/local/lib/python3.10/dist-packages/debugpy/public_api.py\", line 31, in wrapper\n",
757
+ " return wrapped(*args, **kwargs)\n",
758
+ " File \"/usr/local/lib/python3.10/dist-packages/debugpy/server/api.py\", line 143, in debug\n",
759
+ " log.reraise_exception(\"{0}() failed:\", func.__name__, level=\"info\")\n",
760
+ " File \"/usr/local/lib/python3.10/dist-packages/debugpy/server/api.py\", line 141, in debug\n",
761
+ " return func(address, settrace_kwargs, **kwargs)\n",
762
+ " File \"/usr/local/lib/python3.10/dist-packages/debugpy/server/api.py\", line 251, in listen\n",
763
+ " raise RuntimeError(\"timed out waiting for adapter to connect\")\n",
764
+ "RuntimeError: timed out waiting for adapter to connect\n"
765
+ ]
766
+ },
767
+ {
768
+ "output_type": "stream",
769
+ "name": "stdout",
770
+ "text": [
771
+ "Setting queue=True in a Colab notebook requires sharing enabled. Setting `share=True` (you can turn this off by setting `share=False` in `launch()` explicitly).\n",
772
+ "\n",
773
+ "Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
774
+ "Running on public URL: https://efa6ecf31e4b5a440c.gradio.live\n",
775
+ "\n",
776
+ "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
777
+ ]
778
+ },
779
+ {
780
+ "output_type": "display_data",
781
+ "data": {
782
+ "text/plain": [
783
+ "<IPython.core.display.HTML object>"
784
+ ],
785
+ "text/html": [
786
+ "<div><iframe src=\"https://efa6ecf31e4b5a440c.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
787
+ ]
788
+ },
789
+ "metadata": {}
790
+ },
791
+ {
792
+ "output_type": "execute_result",
793
+ "data": {
794
+ "text/plain": []
795
+ },
796
+ "metadata": {},
797
+ "execution_count": 1
798
+ }
799
+ ]
800
+ }
801
+ ],
802
+ "metadata": {
803
+ "colab": {
804
+ "provenance": []
805
+ },
806
+ "kernelspec": {
807
+ "display_name": "Python 3",
808
+ "name": "python3"
809
+ }
810
+ },
811
+ "nbformat": 4,
812
+ "nbformat_minor": 0
813
+ }