hightowerr commited on
Commit
a004bbc
·
1 Parent(s): c23acfb

updated changes

Browse files
Files changed (1) hide show
  1. app.ipynb +87 -59
app.ipynb CHANGED
@@ -20,7 +20,7 @@
20
  },
21
  {
22
  "cell_type": "code",
23
- "execution_count": 32,
24
  "id": "844c3071-836e-46c5-b30e-2b8d96a8e369",
25
  "metadata": {},
26
  "outputs": [],
@@ -33,7 +33,7 @@
33
  },
34
  {
35
  "cell_type": "code",
36
- "execution_count": 33,
37
  "id": "ded0d929-67f6-4a69-b223-dee3ad189139",
38
  "metadata": {},
39
  "outputs": [],
@@ -43,7 +43,7 @@
43
  },
44
  {
45
  "cell_type": "code",
46
- "execution_count": 34,
47
  "id": "6b7aeaaa-8260-45fa-9178-e064b0132c36",
48
  "metadata": {},
49
  "outputs": [],
@@ -55,7 +55,7 @@
55
  },
56
  {
57
  "cell_type": "code",
58
- "execution_count": 35,
59
  "id": "a0dfbe70-b826-4903-95cf-ae59c498a3b6",
60
  "metadata": {},
61
  "outputs": [],
@@ -68,7 +68,7 @@
68
  },
69
  {
70
  "cell_type": "code",
71
- "execution_count": 36,
72
  "id": "a5aaeeb6-6a93-4de8-be39-36c4b5d90ee4",
73
  "metadata": {},
74
  "outputs": [],
@@ -78,7 +78,7 @@
78
  },
79
  {
80
  "cell_type": "code",
81
- "execution_count": 37,
82
  "id": "7fcc53f8-0326-49d0-a110-1140148d6301",
83
  "metadata": {},
84
  "outputs": [],
@@ -88,7 +88,7 @@
88
  },
89
  {
90
  "cell_type": "code",
91
- "execution_count": 38,
92
  "id": "6173ae0f-fa63-4a94-b9f6-e0f9534ff8d9",
93
  "metadata": {},
94
  "outputs": [],
@@ -98,7 +98,7 @@
98
  },
99
  {
100
  "cell_type": "code",
101
- "execution_count": 39,
102
  "id": "490af644-cb3c-4f8c-9e12-1a7cf9c18fc0",
103
  "metadata": {},
104
  "outputs": [],
@@ -111,7 +111,7 @@
111
  },
112
  {
113
  "cell_type": "code",
114
- "execution_count": 40,
115
  "id": "e3618d64-5db3-4659-b30f-f917939f509a",
116
  "metadata": {},
117
  "outputs": [],
@@ -122,7 +122,7 @@
122
  },
123
  {
124
  "cell_type": "code",
125
- "execution_count": 41,
126
  "id": "b2475bb3-b820-4a9d-b3b7-488e9e2971bc",
127
  "metadata": {},
128
  "outputs": [],
@@ -133,7 +133,7 @@
133
  },
134
  {
135
  "cell_type": "code",
136
- "execution_count": 42,
137
  "id": "1cdad192-403a-44d4-b006-661afebe18da",
138
  "metadata": {},
139
  "outputs": [],
@@ -145,14 +145,14 @@
145
  },
146
  {
147
  "cell_type": "code",
148
- "execution_count": 43,
149
  "id": "c72e52ad-30b5-4c06-83d4-35095e43d419",
150
  "metadata": {},
151
  "outputs": [
152
  {
153
  "data": {
154
  "application/vnd.jupyter.widget-view+json": {
155
- "model_id": "fe84c3bbef9d49beb17489c0cb53294a",
156
  "version_major": 2,
157
  "version_minor": 0
158
  },
@@ -160,7 +160,7 @@
160
  "Button(description='Classify', style=ButtonStyle())"
161
  ]
162
  },
163
- "execution_count": 43,
164
  "metadata": {},
165
  "output_type": "execute_result"
166
  }
@@ -173,45 +173,7 @@
173
  },
174
  {
175
  "cell_type": "code",
176
- "execution_count": 47,
177
- "id": "ae0492e9-9981-4fa9-b97c-76d65d4a0206",
178
- "metadata": {},
179
- "outputs": [],
180
- "source": [
181
- "#|export\n",
182
- "from PIL import Image\n",
183
- "import ipywidgets as widgets\n",
184
- "\n",
185
- "# Optional: Import display only if in an IPython environment\n",
186
- "try:\n",
187
- " from IPython.display import display\n",
188
- " can_display = True\n",
189
- "except ImportError:\n",
190
- " can_display = False\n",
191
- "\n",
192
- "def on_click_classify(img_array):\n",
193
- " # Convert numpy array to PIL Image\n",
194
- " img = Image.fromarray(img_array.astype('uint8'), 'RGB')\n",
195
- " \n",
196
- " out_pl = widgets.Output()\n",
197
- " out_pl.clear_output()\n",
198
- " if can_display:\n",
199
- " # Use display if available\n",
200
- " with out_pl:\n",
201
- " display(img.to_thumb(128, 128))\n",
202
- " else:\n",
203
- " # Save to a file if display is not available\n",
204
- " img.to_thumb(128, 128).save('output_thumbnail.png')\n",
205
- " print(\"Thumbnail saved to 'output_thumbnail.png'.\")\n",
206
- " \n",
207
- " # Assuming learn_inf is already defined and loaded elsewhere in your code\n",
208
- " pred, pred_idx, probs = learn_inf.predict(img)\n",
209
- " return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'"
210
- ]
211
- },
212
- {
213
- "cell_type": "code",
214
- "execution_count": 27,
215
  "id": "936e0aa5-4344-4b86-9e7d-b21adbd6b5ab",
216
  "metadata": {},
217
  "outputs": [],
@@ -229,7 +191,7 @@
229
  },
230
  {
231
  "cell_type": "code",
232
- "execution_count": 28,
233
  "id": "3bb8c7a0-3fb4-4fbb-9361-c62095a541a8",
234
  "metadata": {},
235
  "outputs": [],
@@ -239,15 +201,15 @@
239
  },
240
  {
241
  "cell_type": "code",
242
- "execution_count": 48,
243
- "id": "a6e2a398-f6c8-4444-b0f2-e538a1b36da2",
244
  "metadata": {},
245
  "outputs": [
246
  {
247
  "name": "stdout",
248
  "output_type": "stream",
249
  "text": [
250
- "Running on local URL: http://127.0.0.1:7866\n",
251
  "\n",
252
  "To create a public link, set `share=True` in `launch()`.\n"
253
  ]
@@ -256,13 +218,79 @@
256
  "data": {
257
  "text/plain": []
258
  },
259
- "execution_count": 48,
260
  "metadata": {},
261
  "output_type": "execute_result"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
262
  }
263
  ],
264
  "source": [
265
  "#|export\n",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
266
  "image = gr.Image()\n",
267
  "label = gr.Label()\n",
268
  "examples = ['Adi_trainers.jpg', 'Nike_trainers.jpg', 'Puma_trainers.jpg', 'Adidas_trainers.jpg']\n",
@@ -281,7 +309,7 @@
281
  },
282
  {
283
  "cell_type": "code",
284
- "execution_count": 49,
285
  "id": "f5c57105-41fe-4d79-a2b0-d52ed75ea6cb",
286
  "metadata": {},
287
  "outputs": [
 
20
  },
21
  {
22
  "cell_type": "code",
23
+ "execution_count": 50,
24
  "id": "844c3071-836e-46c5-b30e-2b8d96a8e369",
25
  "metadata": {},
26
  "outputs": [],
 
33
  },
34
  {
35
  "cell_type": "code",
36
+ "execution_count": 51,
37
  "id": "ded0d929-67f6-4a69-b223-dee3ad189139",
38
  "metadata": {},
39
  "outputs": [],
 
43
  },
44
  {
45
  "cell_type": "code",
46
+ "execution_count": 52,
47
  "id": "6b7aeaaa-8260-45fa-9178-e064b0132c36",
48
  "metadata": {},
49
  "outputs": [],
 
55
  },
56
  {
57
  "cell_type": "code",
58
+ "execution_count": 53,
59
  "id": "a0dfbe70-b826-4903-95cf-ae59c498a3b6",
60
  "metadata": {},
61
  "outputs": [],
 
68
  },
69
  {
70
  "cell_type": "code",
71
+ "execution_count": 54,
72
  "id": "a5aaeeb6-6a93-4de8-be39-36c4b5d90ee4",
73
  "metadata": {},
74
  "outputs": [],
 
78
  },
79
  {
80
  "cell_type": "code",
81
+ "execution_count": 55,
82
  "id": "7fcc53f8-0326-49d0-a110-1140148d6301",
83
  "metadata": {},
84
  "outputs": [],
 
88
  },
89
  {
90
  "cell_type": "code",
91
+ "execution_count": 56,
92
  "id": "6173ae0f-fa63-4a94-b9f6-e0f9534ff8d9",
93
  "metadata": {},
94
  "outputs": [],
 
98
  },
99
  {
100
  "cell_type": "code",
101
+ "execution_count": 57,
102
  "id": "490af644-cb3c-4f8c-9e12-1a7cf9c18fc0",
103
  "metadata": {},
104
  "outputs": [],
 
111
  },
112
  {
113
  "cell_type": "code",
114
+ "execution_count": 58,
115
  "id": "e3618d64-5db3-4659-b30f-f917939f509a",
116
  "metadata": {},
117
  "outputs": [],
 
122
  },
123
  {
124
  "cell_type": "code",
125
+ "execution_count": 59,
126
  "id": "b2475bb3-b820-4a9d-b3b7-488e9e2971bc",
127
  "metadata": {},
128
  "outputs": [],
 
133
  },
134
  {
135
  "cell_type": "code",
136
+ "execution_count": 60,
137
  "id": "1cdad192-403a-44d4-b006-661afebe18da",
138
  "metadata": {},
139
  "outputs": [],
 
145
  },
146
  {
147
  "cell_type": "code",
148
+ "execution_count": 61,
149
  "id": "c72e52ad-30b5-4c06-83d4-35095e43d419",
150
  "metadata": {},
151
  "outputs": [
152
  {
153
  "data": {
154
  "application/vnd.jupyter.widget-view+json": {
155
+ "model_id": "dc5c7e68735b44fb942ce0f4c923259b",
156
  "version_major": 2,
157
  "version_minor": 0
158
  },
 
160
  "Button(description='Classify', style=ButtonStyle())"
161
  ]
162
  },
163
+ "execution_count": 61,
164
  "metadata": {},
165
  "output_type": "execute_result"
166
  }
 
173
  },
174
  {
175
  "cell_type": "code",
176
+ "execution_count": 62,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  "id": "936e0aa5-4344-4b86-9e7d-b21adbd6b5ab",
178
  "metadata": {},
179
  "outputs": [],
 
191
  },
192
  {
193
  "cell_type": "code",
194
+ "execution_count": 63,
195
  "id": "3bb8c7a0-3fb4-4fbb-9361-c62095a541a8",
196
  "metadata": {},
197
  "outputs": [],
 
201
  },
202
  {
203
  "cell_type": "code",
204
+ "execution_count": 64,
205
+ "id": "ae0492e9-9981-4fa9-b97c-76d65d4a0206",
206
  "metadata": {},
207
  "outputs": [
208
  {
209
  "name": "stdout",
210
  "output_type": "stream",
211
  "text": [
212
+ "Running on local URL: http://127.0.0.1:7867\n",
213
  "\n",
214
  "To create a public link, set `share=True` in `launch()`.\n"
215
  ]
 
218
  "data": {
219
  "text/plain": []
220
  },
221
+ "execution_count": 64,
222
  "metadata": {},
223
  "output_type": "execute_result"
224
+ },
225
+ {
226
+ "data": {
227
+ "text/html": [
228
+ "\n",
229
+ "<style>\n",
230
+ " /* Turns off some styling */\n",
231
+ " progress {\n",
232
+ " /* gets rid of default border in Firefox and Opera. */\n",
233
+ " border: none;\n",
234
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
235
+ " background-size: auto;\n",
236
+ " }\n",
237
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
238
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
239
+ " }\n",
240
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
241
+ " background: #F44336;\n",
242
+ " }\n",
243
+ "</style>\n"
244
+ ],
245
+ "text/plain": [
246
+ "<IPython.core.display.HTML object>"
247
+ ]
248
+ },
249
+ "metadata": {},
250
+ "output_type": "display_data"
251
+ },
252
+ {
253
+ "data": {
254
+ "text/html": [],
255
+ "text/plain": [
256
+ "<IPython.core.display.HTML object>"
257
+ ]
258
+ },
259
+ "metadata": {},
260
+ "output_type": "display_data"
261
  }
262
  ],
263
  "source": [
264
  "#|export\n",
265
+ "from PIL import Image\n",
266
+ "import ipywidgets as widgets\n",
267
+ "\n",
268
+ "# Optional: Import display only if in an IPython environment\n",
269
+ "try:\n",
270
+ " from IPython.display import display\n",
271
+ " can_display = True\n",
272
+ "except ImportError:\n",
273
+ " can_display = False\n",
274
+ "\n",
275
+ "def on_click_classify(img_array):\n",
276
+ " # Convert numpy array to PIL Image\n",
277
+ " img = Image.fromarray(img_array.astype('uint8'), 'RGB')\n",
278
+ " \n",
279
+ " out_pl = widgets.Output()\n",
280
+ " out_pl.clear_output()\n",
281
+ " if can_display:\n",
282
+ " # Use display if available\n",
283
+ " with out_pl:\n",
284
+ " display(img.to_thumb(128, 128))\n",
285
+ " else:\n",
286
+ " # Save to a file if display is not available\n",
287
+ " img.to_thumb(128, 128).save('output_thumbnail.png')\n",
288
+ " print(\"Thumbnail saved to 'output_thumbnail.png'.\")\n",
289
+ " \n",
290
+ " # Assuming learn_inf is already defined and loaded elsewhere in your code\n",
291
+ " pred, pred_idx, probs = learn_inf.predict(img)\n",
292
+ " return f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'\n",
293
+ "\n",
294
  "image = gr.Image()\n",
295
  "label = gr.Label()\n",
296
  "examples = ['Adi_trainers.jpg', 'Nike_trainers.jpg', 'Puma_trainers.jpg', 'Adidas_trainers.jpg']\n",
 
309
  },
310
  {
311
  "cell_type": "code",
312
+ "execution_count": 65,
313
  "id": "f5c57105-41fe-4d79-a2b0-d52ed75ea6cb",
314
  "metadata": {},
315
  "outputs": [