Ajit Singh commited on
Commit
45627bf
1 Parent(s): 883c5f2

Fix syntax error in app.py

Browse files
Files changed (3) hide show
  1. .ipynb_checkpoints/app-checkpoint.ipynb +749 -0
  2. app.ipynb +2 -3
  3. app.py +0 -5
.ipynb_checkpoints/app-checkpoint.ipynb ADDED
@@ -0,0 +1,749 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 4,
6
+ "id": "2ccea5e4",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "#|default_exp app\n"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": null,
16
+ "id": "1d47b7c1",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "# Make sure we've got the latest version of fastai:\n",
21
+ "!pip install -Uqq fastai gradio\n",
22
+ "!pip install -Uqq fastbook"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 12,
28
+ "id": "553b0061",
29
+ "metadata": {},
30
+ "outputs": [],
31
+ "source": [
32
+ "#|export\n",
33
+ "import fastbook\n",
34
+ "fastbook.setup_book()"
35
+ ]
36
+ },
37
+ {
38
+ "cell_type": "code",
39
+ "execution_count": 32,
40
+ "id": "efc0850a",
41
+ "metadata": {},
42
+ "outputs": [],
43
+ "source": [
44
+ "#|export\n",
45
+ "from fastbook import *\n",
46
+ "from fastai.vision.widgets import *\n",
47
+ "from fastai.vision.all import *\n",
48
+ "from urllib.request import urlopen"
49
+ ]
50
+ },
51
+ {
52
+ "cell_type": "markdown",
53
+ "id": "c73e94bb",
54
+ "metadata": {},
55
+ "source": [
56
+ "# Dogs vs Cats"
57
+ ]
58
+ },
59
+ {
60
+ "cell_type": "code",
61
+ "execution_count": 5,
62
+ "id": "15421cd2",
63
+ "metadata": {
64
+ "scrolled": true
65
+ },
66
+ "outputs": [],
67
+ "source": [
68
+ "#|export\n",
69
+ "import gradio as gr\n",
70
+ "\n",
71
+ "def is_cat(x): return x[0].issuper()"
72
+ ]
73
+ },
74
+ {
75
+ "cell_type": "code",
76
+ "execution_count": 64,
77
+ "id": "f8743ab2",
78
+ "metadata": {},
79
+ "outputs": [],
80
+ "source": [
81
+ "ims = search_images_ddg('dog', max_images=3)\n",
82
+ "dest = 'images/'\n",
83
+ "download_images(dest, urls=ims)"
84
+ ]
85
+ },
86
+ {
87
+ "cell_type": "code",
88
+ "execution_count": 38,
89
+ "id": "91067f42",
90
+ "metadata": {},
91
+ "outputs": [
92
+ {
93
+ "data": {
94
+ "text/plain": [
95
+ "(#9) [Path('images/3cf5e7be-7aa0-4f7d-b585-ab7bd97d6d95.jpg'),Path('images/4d3b88ed-d0dc-43ec-bbaf-6babf6f310a7.jpg'),Path('images/5c283719-addd-4dbf-9847-eda74d0af8e7.jpg'),Path('images/6c9ec27e-0dbf-4e92-8059-12ec91bfa37b.jpg'),Path('images/a8ceb639-1fbf-447f-856e-7cf9bc796475.jpg'),Path('images/cc15e76a-5cd9-471e-9620-ae608e1d6be6.jpg'),Path('images/d53d92d8-7958-4fb6-ba9d-5f1e27fe9ceb.jpg'),Path('images/dog.jpg'),Path('images/edca2fd3-9ef6-40a5-a091-446b1abdfb55.jpg')]"
96
+ ]
97
+ },
98
+ "execution_count": 38,
99
+ "metadata": {},
100
+ "output_type": "execute_result"
101
+ }
102
+ ],
103
+ "source": [
104
+ "fns = get_image_files(dest)\n",
105
+ "fns"
106
+ ]
107
+ },
108
+ {
109
+ "cell_type": "code",
110
+ "execution_count": 39,
111
+ "id": "ba9916e9",
112
+ "metadata": {},
113
+ "outputs": [
114
+ {
115
+ "data": {
116
+ "text/plain": [
117
+ "(#0) []"
118
+ ]
119
+ },
120
+ "execution_count": 39,
121
+ "metadata": {},
122
+ "output_type": "execute_result"
123
+ }
124
+ ],
125
+ "source": [
126
+ "failed = verify_images(fns)\n",
127
+ "failed"
128
+ ]
129
+ },
130
+ {
131
+ "cell_type": "code",
132
+ "execution_count": 40,
133
+ "id": "cf2964df",
134
+ "metadata": {},
135
+ "outputs": [],
136
+ "source": [
137
+ "failed.map(Path.unlink);"
138
+ ]
139
+ },
140
+ {
141
+ "cell_type": "markdown",
142
+ "id": "a5deae21",
143
+ "metadata": {},
144
+ "source": [
145
+ "# Load Learner"
146
+ ]
147
+ },
148
+ {
149
+ "cell_type": "code",
150
+ "execution_count": 44,
151
+ "id": "13b84738",
152
+ "metadata": {},
153
+ "outputs": [],
154
+ "source": [
155
+ "#|export\n",
156
+ "learn = load_learner('model.pkl')"
157
+ ]
158
+ },
159
+ {
160
+ "cell_type": "code",
161
+ "execution_count": 48,
162
+ "id": "ad82eadc",
163
+ "metadata": {},
164
+ "outputs": [
165
+ {
166
+ "data": {
167
+ "text/html": [
168
+ "\n",
169
+ "<style>\n",
170
+ " /* Turns off some styling */\n",
171
+ " progress {\n",
172
+ " /* gets rid of default border in Firefox and Opera. */\n",
173
+ " border: none;\n",
174
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
175
+ " background-size: auto;\n",
176
+ " }\n",
177
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
178
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
179
+ " }\n",
180
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
181
+ " background: #F44336;\n",
182
+ " }\n",
183
+ "</style>\n"
184
+ ],
185
+ "text/plain": [
186
+ "<IPython.core.display.HTML object>"
187
+ ]
188
+ },
189
+ "metadata": {},
190
+ "output_type": "display_data"
191
+ },
192
+ {
193
+ "data": {
194
+ "text/html": [],
195
+ "text/plain": [
196
+ "<IPython.core.display.HTML object>"
197
+ ]
198
+ },
199
+ "metadata": {},
200
+ "output_type": "display_data"
201
+ },
202
+ {
203
+ "name": "stdout",
204
+ "output_type": "stream",
205
+ "text": [
206
+ "('False', tensor(0), tensor([9.9998e-01, 1.5045e-05]))\n"
207
+ ]
208
+ },
209
+ {
210
+ "data": {
211
+ "text/html": [
212
+ "\n",
213
+ "<style>\n",
214
+ " /* Turns off some styling */\n",
215
+ " progress {\n",
216
+ " /* gets rid of default border in Firefox and Opera. */\n",
217
+ " border: none;\n",
218
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
219
+ " background-size: auto;\n",
220
+ " }\n",
221
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
222
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
223
+ " }\n",
224
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
225
+ " background: #F44336;\n",
226
+ " }\n",
227
+ "</style>\n"
228
+ ],
229
+ "text/plain": [
230
+ "<IPython.core.display.HTML object>"
231
+ ]
232
+ },
233
+ "metadata": {},
234
+ "output_type": "display_data"
235
+ },
236
+ {
237
+ "data": {
238
+ "text/html": [],
239
+ "text/plain": [
240
+ "<IPython.core.display.HTML object>"
241
+ ]
242
+ },
243
+ "metadata": {},
244
+ "output_type": "display_data"
245
+ },
246
+ {
247
+ "name": "stdout",
248
+ "output_type": "stream",
249
+ "text": [
250
+ "('False', tensor(0), tensor([1.0000e+00, 2.4750e-06]))\n"
251
+ ]
252
+ },
253
+ {
254
+ "data": {
255
+ "text/html": [
256
+ "\n",
257
+ "<style>\n",
258
+ " /* Turns off some styling */\n",
259
+ " progress {\n",
260
+ " /* gets rid of default border in Firefox and Opera. */\n",
261
+ " border: none;\n",
262
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
263
+ " background-size: auto;\n",
264
+ " }\n",
265
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
266
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
267
+ " }\n",
268
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
269
+ " background: #F44336;\n",
270
+ " }\n",
271
+ "</style>\n"
272
+ ],
273
+ "text/plain": [
274
+ "<IPython.core.display.HTML object>"
275
+ ]
276
+ },
277
+ "metadata": {},
278
+ "output_type": "display_data"
279
+ },
280
+ {
281
+ "data": {
282
+ "text/html": [],
283
+ "text/plain": [
284
+ "<IPython.core.display.HTML object>"
285
+ ]
286
+ },
287
+ "metadata": {},
288
+ "output_type": "display_data"
289
+ },
290
+ {
291
+ "name": "stdout",
292
+ "output_type": "stream",
293
+ "text": [
294
+ "('False', tensor(0), tensor([1.0000e+00, 2.2275e-06]))\n"
295
+ ]
296
+ },
297
+ {
298
+ "data": {
299
+ "text/html": [
300
+ "\n",
301
+ "<style>\n",
302
+ " /* Turns off some styling */\n",
303
+ " progress {\n",
304
+ " /* gets rid of default border in Firefox and Opera. */\n",
305
+ " border: none;\n",
306
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
307
+ " background-size: auto;\n",
308
+ " }\n",
309
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
310
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
311
+ " }\n",
312
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
313
+ " background: #F44336;\n",
314
+ " }\n",
315
+ "</style>\n"
316
+ ],
317
+ "text/plain": [
318
+ "<IPython.core.display.HTML object>"
319
+ ]
320
+ },
321
+ "metadata": {},
322
+ "output_type": "display_data"
323
+ },
324
+ {
325
+ "data": {
326
+ "text/html": [],
327
+ "text/plain": [
328
+ "<IPython.core.display.HTML object>"
329
+ ]
330
+ },
331
+ "metadata": {},
332
+ "output_type": "display_data"
333
+ },
334
+ {
335
+ "name": "stdout",
336
+ "output_type": "stream",
337
+ "text": [
338
+ "('False', tensor(0), tensor([1.0000e+00, 1.0369e-07]))\n"
339
+ ]
340
+ },
341
+ {
342
+ "data": {
343
+ "text/html": [
344
+ "\n",
345
+ "<style>\n",
346
+ " /* Turns off some styling */\n",
347
+ " progress {\n",
348
+ " /* gets rid of default border in Firefox and Opera. */\n",
349
+ " border: none;\n",
350
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
351
+ " background-size: auto;\n",
352
+ " }\n",
353
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
354
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
355
+ " }\n",
356
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
357
+ " background: #F44336;\n",
358
+ " }\n",
359
+ "</style>\n"
360
+ ],
361
+ "text/plain": [
362
+ "<IPython.core.display.HTML object>"
363
+ ]
364
+ },
365
+ "metadata": {},
366
+ "output_type": "display_data"
367
+ },
368
+ {
369
+ "data": {
370
+ "text/html": [],
371
+ "text/plain": [
372
+ "<IPython.core.display.HTML object>"
373
+ ]
374
+ },
375
+ "metadata": {},
376
+ "output_type": "display_data"
377
+ },
378
+ {
379
+ "name": "stdout",
380
+ "output_type": "stream",
381
+ "text": [
382
+ "('False', tensor(0), tensor([9.9997e-01, 2.7372e-05]))\n"
383
+ ]
384
+ },
385
+ {
386
+ "data": {
387
+ "text/html": [
388
+ "\n",
389
+ "<style>\n",
390
+ " /* Turns off some styling */\n",
391
+ " progress {\n",
392
+ " /* gets rid of default border in Firefox and Opera. */\n",
393
+ " border: none;\n",
394
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
395
+ " background-size: auto;\n",
396
+ " }\n",
397
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
398
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
399
+ " }\n",
400
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
401
+ " background: #F44336;\n",
402
+ " }\n",
403
+ "</style>\n"
404
+ ],
405
+ "text/plain": [
406
+ "<IPython.core.display.HTML object>"
407
+ ]
408
+ },
409
+ "metadata": {},
410
+ "output_type": "display_data"
411
+ },
412
+ {
413
+ "data": {
414
+ "text/html": [],
415
+ "text/plain": [
416
+ "<IPython.core.display.HTML object>"
417
+ ]
418
+ },
419
+ "metadata": {},
420
+ "output_type": "display_data"
421
+ },
422
+ {
423
+ "name": "stdout",
424
+ "output_type": "stream",
425
+ "text": [
426
+ "('False', tensor(0), tensor([0.9984, 0.0016]))\n"
427
+ ]
428
+ },
429
+ {
430
+ "data": {
431
+ "text/html": [
432
+ "\n",
433
+ "<style>\n",
434
+ " /* Turns off some styling */\n",
435
+ " progress {\n",
436
+ " /* gets rid of default border in Firefox and Opera. */\n",
437
+ " border: none;\n",
438
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
439
+ " background-size: auto;\n",
440
+ " }\n",
441
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
442
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
443
+ " }\n",
444
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
445
+ " background: #F44336;\n",
446
+ " }\n",
447
+ "</style>\n"
448
+ ],
449
+ "text/plain": [
450
+ "<IPython.core.display.HTML object>"
451
+ ]
452
+ },
453
+ "metadata": {},
454
+ "output_type": "display_data"
455
+ },
456
+ {
457
+ "data": {
458
+ "text/html": [],
459
+ "text/plain": [
460
+ "<IPython.core.display.HTML object>"
461
+ ]
462
+ },
463
+ "metadata": {},
464
+ "output_type": "display_data"
465
+ },
466
+ {
467
+ "name": "stdout",
468
+ "output_type": "stream",
469
+ "text": [
470
+ "('False', tensor(0), tensor([9.9941e-01, 5.8600e-04]))\n"
471
+ ]
472
+ },
473
+ {
474
+ "data": {
475
+ "text/html": [
476
+ "\n",
477
+ "<style>\n",
478
+ " /* Turns off some styling */\n",
479
+ " progress {\n",
480
+ " /* gets rid of default border in Firefox and Opera. */\n",
481
+ " border: none;\n",
482
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
483
+ " background-size: auto;\n",
484
+ " }\n",
485
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
486
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
487
+ " }\n",
488
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
489
+ " background: #F44336;\n",
490
+ " }\n",
491
+ "</style>\n"
492
+ ],
493
+ "text/plain": [
494
+ "<IPython.core.display.HTML object>"
495
+ ]
496
+ },
497
+ "metadata": {},
498
+ "output_type": "display_data"
499
+ },
500
+ {
501
+ "data": {
502
+ "text/html": [],
503
+ "text/plain": [
504
+ "<IPython.core.display.HTML object>"
505
+ ]
506
+ },
507
+ "metadata": {},
508
+ "output_type": "display_data"
509
+ },
510
+ {
511
+ "name": "stdout",
512
+ "output_type": "stream",
513
+ "text": [
514
+ "('False', tensor(0), tensor([9.9920e-01, 7.9651e-04]))\n"
515
+ ]
516
+ },
517
+ {
518
+ "data": {
519
+ "text/html": [
520
+ "\n",
521
+ "<style>\n",
522
+ " /* Turns off some styling */\n",
523
+ " progress {\n",
524
+ " /* gets rid of default border in Firefox and Opera. */\n",
525
+ " border: none;\n",
526
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
527
+ " background-size: auto;\n",
528
+ " }\n",
529
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
530
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
531
+ " }\n",
532
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
533
+ " background: #F44336;\n",
534
+ " }\n",
535
+ "</style>\n"
536
+ ],
537
+ "text/plain": [
538
+ "<IPython.core.display.HTML object>"
539
+ ]
540
+ },
541
+ "metadata": {},
542
+ "output_type": "display_data"
543
+ },
544
+ {
545
+ "data": {
546
+ "text/html": [],
547
+ "text/plain": [
548
+ "<IPython.core.display.HTML object>"
549
+ ]
550
+ },
551
+ "metadata": {},
552
+ "output_type": "display_data"
553
+ },
554
+ {
555
+ "name": "stdout",
556
+ "output_type": "stream",
557
+ "text": [
558
+ "('False', tensor(0), tensor([9.9999e-01, 9.5192e-06]))\n"
559
+ ]
560
+ }
561
+ ],
562
+ "source": [
563
+ "for path in fns:\n",
564
+ " im = PILImage.create(path)\n",
565
+ " im.thumbnail((192,192))\n",
566
+ " print(learn.predict(im)) "
567
+ ]
568
+ },
569
+ {
570
+ "cell_type": "code",
571
+ "execution_count": 49,
572
+ "id": "011cccba",
573
+ "metadata": {},
574
+ "outputs": [],
575
+ "source": [
576
+ "categories = ('Dog', 'Cat')\n",
577
+ "def classify_image(img):\n",
578
+ " pref,idx,probs = learn.predict(img)\n",
579
+ " return dict(zip(categories, map(float, probs)))"
580
+ ]
581
+ },
582
+ {
583
+ "cell_type": "code",
584
+ "execution_count": 50,
585
+ "id": "16881a1b",
586
+ "metadata": {},
587
+ "outputs": [
588
+ {
589
+ "data": {
590
+ "text/html": [
591
+ "\n",
592
+ "<style>\n",
593
+ " /* Turns off some styling */\n",
594
+ " progress {\n",
595
+ " /* gets rid of default border in Firefox and Opera. */\n",
596
+ " border: none;\n",
597
+ " /* Needs to be in here for Safari polyfill so background images work as expected. */\n",
598
+ " background-size: auto;\n",
599
+ " }\n",
600
+ " progress:not([value]), progress:not([value])::-webkit-progress-bar {\n",
601
+ " background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px);\n",
602
+ " }\n",
603
+ " .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar {\n",
604
+ " background: #F44336;\n",
605
+ " }\n",
606
+ "</style>\n"
607
+ ],
608
+ "text/plain": [
609
+ "<IPython.core.display.HTML object>"
610
+ ]
611
+ },
612
+ "metadata": {},
613
+ "output_type": "display_data"
614
+ },
615
+ {
616
+ "data": {
617
+ "text/html": [],
618
+ "text/plain": [
619
+ "<IPython.core.display.HTML object>"
620
+ ]
621
+ },
622
+ "metadata": {},
623
+ "output_type": "display_data"
624
+ },
625
+ {
626
+ "data": {
627
+ "text/plain": [
628
+ "{'Dog': 0.999957799911499, 'Cat': 4.219008405925706e-05}"
629
+ ]
630
+ },
631
+ "execution_count": 50,
632
+ "metadata": {},
633
+ "output_type": "execute_result"
634
+ }
635
+ ],
636
+ "source": [
637
+ "base_image = PILImage.create(fns[0])\n",
638
+ "classify_image(base_image)"
639
+ ]
640
+ },
641
+ {
642
+ "cell_type": "markdown",
643
+ "id": "4c11585c",
644
+ "metadata": {},
645
+ "source": [
646
+ "# Gradio"
647
+ ]
648
+ },
649
+ {
650
+ "cell_type": "code",
651
+ "execution_count": 74,
652
+ "id": "69406102",
653
+ "metadata": {},
654
+ "outputs": [
655
+ {
656
+ "name": "stderr",
657
+ "output_type": "stream",
658
+ "text": [
659
+ "/media/data/programming/ml/anaconda3/lib/python3.9/site-packages/gradio/inputs.py:257: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",
660
+ " warnings.warn(\n",
661
+ "/media/data/programming/ml/anaconda3/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",
662
+ " warnings.warn(value)\n",
663
+ "/media/data/programming/ml/anaconda3/lib/python3.9/site-packages/gradio/outputs.py:197: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",
664
+ " warnings.warn(\n",
665
+ "/media/data/programming/ml/anaconda3/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",
666
+ " warnings.warn(value)\n"
667
+ ]
668
+ },
669
+ {
670
+ "name": "stdout",
671
+ "output_type": "stream",
672
+ "text": [
673
+ "Running on local URL: http://127.0.0.1:7861\n",
674
+ "\n",
675
+ "To create a public link, set `share=True` in `launch()`.\n"
676
+ ]
677
+ },
678
+ {
679
+ "data": {
680
+ "text/plain": []
681
+ },
682
+ "execution_count": 74,
683
+ "metadata": {},
684
+ "output_type": "execute_result"
685
+ }
686
+ ],
687
+ "source": [
688
+ "#|export\n",
689
+ "image = gr.inputs.Image(shape=(192,192))\n",
690
+ "label = gr.outputs.Label()\n",
691
+ "examples = ['images/4d3b88ed-d0dc-43ec-bbaf-6babf6f310a7.jpg',\n",
692
+ " 'images/5c283719-addd-4dbf-9847-eda74d0af8e7.jpg']\n",
693
+ "\n",
694
+ "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n",
695
+ "intf.launch(inline=False)"
696
+ ]
697
+ },
698
+ {
699
+ "cell_type": "markdown",
700
+ "id": "38ae565f",
701
+ "metadata": {},
702
+ "source": [
703
+ "# Exporting"
704
+ ]
705
+ },
706
+ {
707
+ "cell_type": "code",
708
+ "execution_count": 75,
709
+ "id": "ef61159a",
710
+ "metadata": {},
711
+ "outputs": [],
712
+ "source": [
713
+ "!pip install -Uqq nbdev\n",
714
+ "import nbdev"
715
+ ]
716
+ },
717
+ {
718
+ "cell_type": "code",
719
+ "execution_count": 76,
720
+ "id": "5e35eaab",
721
+ "metadata": {},
722
+ "outputs": [],
723
+ "source": [
724
+ "nbdev.export.nb_export('app.ipynb', '.')"
725
+ ]
726
+ }
727
+ ],
728
+ "metadata": {
729
+ "kernelspec": {
730
+ "display_name": "Python 3 (ipykernel)",
731
+ "language": "python",
732
+ "name": "python3"
733
+ },
734
+ "language_info": {
735
+ "codemirror_mode": {
736
+ "name": "ipython",
737
+ "version": 3
738
+ },
739
+ "file_extension": ".py",
740
+ "mimetype": "text/x-python",
741
+ "name": "python",
742
+ "nbconvert_exporter": "python",
743
+ "pygments_lexer": "ipython3",
744
+ "version": "3.9.13"
745
+ }
746
+ },
747
+ "nbformat": 4,
748
+ "nbformat_minor": 5
749
+ }
app.ipynb CHANGED
@@ -17,9 +17,9 @@
17
  "metadata": {},
18
  "outputs": [],
19
  "source": [
20
- "#|export\n",
21
  "# Make sure we've got the latest version of fastai:\n",
22
- "!pip install -Uqq fastai gradio"
 
23
  ]
24
  },
25
  {
@@ -30,7 +30,6 @@
30
  "outputs": [],
31
  "source": [
32
  "#|export\n",
33
- "!pip install -Uqq fastbook\n",
34
  "import fastbook\n",
35
  "fastbook.setup_book()"
36
  ]
 
17
  "metadata": {},
18
  "outputs": [],
19
  "source": [
 
20
  "# Make sure we've got the latest version of fastai:\n",
21
+ "!pip install -Uqq fastai gradio\n",
22
+ "!pip install -Uqq fastbook"
23
  ]
24
  },
25
  {
 
30
  "outputs": [],
31
  "source": [
32
  "#|export\n",
 
33
  "import fastbook\n",
34
  "fastbook.setup_book()"
35
  ]
app.py CHANGED
@@ -3,12 +3,7 @@
3
  # %% auto 0
4
  __all__ = ['learn', 'image', 'label', 'examples', 'intf', 'is_cat']
5
 
6
- # %% app.ipynb 1
7
- # Make sure we've got the latest version of fastai:
8
- !pip install -Uqq fastai gradio
9
-
10
  # %% app.ipynb 2
11
- !pip install -Uqq fastbook
12
  import fastbook
13
  fastbook.setup_book()
14
 
 
3
  # %% auto 0
4
  __all__ = ['learn', 'image', 'label', 'examples', 'intf', 'is_cat']
5
 
 
 
 
 
6
  # %% app.ipynb 2
 
7
  import fastbook
8
  fastbook.setup_book()
9