Aspiring Astro commited on
Commit
56da072
1 Parent(s): 6426419

add a clear btn

Browse files
Files changed (2) hide show
  1. app.ipynb +20 -39
  2. app.py +11 -7
app.ipynb CHANGED
@@ -20,8 +20,9 @@
20
  "#| export\n",
21
  "from fastai.vision.all import *\n",
22
  "import gradio as gr\n",
23
- "import warnings\n",
24
- "warnings.filterwarnings('ignore')\n",
 
25
  "\n",
26
  "title = \"FastAI - Big Cats Classifier\"\n",
27
  "description = \"Classify big cats using all Resnet models available pre-trained in FastAI\""
@@ -124,7 +125,7 @@
124
  "name": "stdout",
125
  "output_type": "stream",
126
  "text": [
127
- "{'african leopard': 0.0005852991016581655, 'cheetah': 0.9993988275527954, 'clouded leopard': 1.7600793000838166e-07, 'cougar': 6.112059963925276e-06, 'jaguar': 7.491902579204179e-06, 'lion': 1.3097942428430542e-06, 'snow leopard': 6.794325599912554e-07, 'tiger': 1.22832446436405e-07}\n"
128
  ]
129
  },
130
  {
@@ -168,7 +169,7 @@
168
  "name": "stdout",
169
  "output_type": "stream",
170
  "text": [
171
- "{'african leopard': 0.2962114214897156, 'cheetah': 2.706606210267637e-05, 'clouded leopard': 0.0008470952161587775, 'cougar': 1.0193979505856987e-05, 'jaguar': 0.701975405216217, 'lion': 1.3766093616141006e-05, 'snow leopard': 0.0008549779886379838, 'tiger': 6.007726915413514e-05}\n"
172
  ]
173
  },
174
  {
@@ -212,7 +213,7 @@
212
  "name": "stdout",
213
  "output_type": "stream",
214
  "text": [
215
- "{'african leopard': 2.0210626061611947e-08, 'cheetah': 1.6748231246310752e-08, 'clouded leopard': 1.1174745395692298e-06, 'cougar': 2.63490710494807e-06, 'jaguar': 2.399448703727103e-06, 'lion': 6.196571433747522e-08, 'snow leopard': 2.4245096028607804e-06, 'tiger': 0.9999912977218628}\n"
216
  ]
217
  },
218
  {
@@ -256,7 +257,7 @@
256
  "name": "stdout",
257
  "output_type": "stream",
258
  "text": [
259
- "{'african leopard': 9.39465026021935e-05, 'cheetah': 0.00021114452101755887, 'clouded leopard': 8.688175876159221e-05, 'cougar': 0.9761292934417725, 'jaguar': 7.082346655806759e-06, 'lion': 0.02333180606365204, 'snow leopard': 0.00011577722762012854, 'tiger': 2.4006889361771755e-05}\n"
260
  ]
261
  },
262
  {
@@ -300,7 +301,7 @@
300
  "name": "stdout",
301
  "output_type": "stream",
302
  "text": [
303
- "{'african leopard': 1.3545766286426897e-08, 'cheetah': 2.635677674334147e-06, 'clouded leopard': 7.659965994832874e-09, 'cougar': 9.957815017003213e-09, 'jaguar': 1.497639772196635e-07, 'lion': 0.9999957084655762, 'snow leopard': 1.294516778216348e-07, 'tiger': 1.2779944427165901e-06}\n"
304
  ]
305
  },
306
  {
@@ -344,7 +345,7 @@
344
  "name": "stdout",
345
  "output_type": "stream",
346
  "text": [
347
- "{'african leopard': 0.024091463536024094, 'cheetah': 0.0014163728337734938, 'clouded leopard': 0.008692733943462372, 'cougar': 0.0010448594111949205, 'jaguar': 0.7156786322593689, 'lion': 0.017859801650047302, 'snow leopard': 0.22819218039512634, 'tiger': 0.0030239589978009462}\n"
348
  ]
349
  },
350
  {
@@ -388,7 +389,7 @@
388
  "name": "stdout",
389
  "output_type": "stream",
390
  "text": [
391
- "{'african leopard': 7.144178198359441e-06, 'cheetah': 3.725538704202336e-07, 'clouded leopard': 0.9994736313819885, 'cougar': 6.0378228226909414e-05, 'jaguar': 3.279747033957392e-05, 'lion': 1.1806019273308266e-07, 'snow leopard': 0.0003000575816258788, 'tiger': 0.0001255277602467686}\n"
392
  ]
393
  },
394
  {
@@ -432,7 +433,7 @@
432
  "name": "stdout",
433
  "output_type": "stream",
434
  "text": [
435
- "{'african leopard': 2.8642458346439525e-05, 'cheetah': 0.00017579919949639589, 'clouded leopard': 0.08972200006246567, 'cougar': 7.897598698036745e-05, 'jaguar': 2.5307128453277983e-05, 'lion': 1.8576161892269738e-05, 'snow leopard': 0.9099361896514893, 'tiger': 1.4485961401078384e-05}\n"
436
  ]
437
  }
438
  ],
@@ -447,7 +448,7 @@
447
  },
448
  {
449
  "cell_type": "code",
450
- "execution_count": 6,
451
  "id": "a48e7483-c04b-4048-a1ae-34a8c7986a57",
452
  "metadata": {},
453
  "outputs": [
@@ -496,21 +497,6 @@
496
  },
497
  "metadata": {},
498
  "output_type": "display_data"
499
- },
500
- {
501
- "name": "stdout",
502
- "output_type": "stream",
503
- "text": [
504
- "Keyboard interruption in main thread... closing server.\n"
505
- ]
506
- },
507
- {
508
- "data": {
509
- "text/plain": []
510
- },
511
- "execution_count": 6,
512
- "metadata": {},
513
- "output_type": "execute_result"
514
  }
515
  ],
516
  "source": [
@@ -522,7 +508,9 @@
522
  " with gr.Column(variant=\"panel\"):\n",
523
  " image = gr.inputs.Image(label=\"Pick an image\")\n",
524
  " model = gr.inputs.Dropdown(label=\"Select a model\", choices=models)\n",
525
- " btnClassify = gr.Button(\"Classify\")\n",
 
 
526
  " with gr.Column(variant=\"panel\"):\n",
527
  " selected = gr.outputs.Textbox(label=\"Active Model\")\n",
528
  " with gr.Row(equal_height=True):\n",
@@ -530,13 +518,14 @@
530
  " losses=gr.outputs.Image(type='filepath', label=\"Top Losses\")\n",
531
  " result = gr.outputs.Label(label=\"Result\")\n",
532
  " \n",
533
- " btnClassify.click(fn=classify_image, inputs=image, outputs=result)\n",
534
  " img_gallery = gr.Examples(examples=example_images, inputs=image)\n",
535
  "\n",
536
- " # Register all ev\n",
537
  " model.change(fn=select_model, inputs=model, outputs=selected)\n",
538
  " model.change(fn=update_matrix, outputs=matrix)\n",
539
  " model.change(fn=update_losses, outputs=losses)\n",
 
 
540
  "\n",
541
  "demo.launch(debug=True, inline=False)\n",
542
  " # intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )\n",
@@ -546,18 +535,10 @@
546
  },
547
  {
548
  "cell_type": "code",
549
- "execution_count": 8,
550
  "id": "cab071f9-7c3b-4b35-a0d1-3687731ffce5",
551
  "metadata": {},
552
- "outputs": [
553
- {
554
- "name": "stdout",
555
- "output_type": "stream",
556
- "text": [
557
- "Export successful\n"
558
- ]
559
- }
560
- ],
561
  "source": [
562
  "import nbdev\n",
563
  "nbdev.export.nb_export('app.ipynb', './')\n",
 
20
  "#| export\n",
21
  "from fastai.vision.all import *\n",
22
  "import gradio as gr\n",
23
+ "\n",
24
+ "interpretation='default'\n",
25
+ "enable_queue=True\n",
26
  "\n",
27
  "title = \"FastAI - Big Cats Classifier\"\n",
28
  "description = \"Classify big cats using all Resnet models available pre-trained in FastAI\""
 
125
  "name": "stdout",
126
  "output_type": "stream",
127
  "text": [
128
+ "{'african leopard': 0.00045245178625918925, 'cheetah': 0.9994743466377258, 'clouded leopard': 3.061432778395101e-07, 'cougar': 8.726581654627807e-06, 'jaguar': 4.878858817392029e-05, 'lion': 1.4129628652881365e-05, 'snow leopard': 1.2738197483486147e-06, 'tiger': 1.1983513736879559e-08}\n"
129
  ]
130
  },
131
  {
 
169
  "name": "stdout",
170
  "output_type": "stream",
171
  "text": [
172
+ "{'african leopard': 8.918660228118824e-07, 'cheetah': 3.004239079729132e-09, 'clouded leopard': 1.0275688282490592e-06, 'cougar': 1.8215871477877954e-08, 'jaguar': 0.9999979734420776, 'lion': 7.327587425720594e-10, 'snow leopard': 1.3988608316140017e-07, 'tiger': 4.418302523845341e-08}\n"
173
  ]
174
  },
175
  {
 
213
  "name": "stdout",
214
  "output_type": "stream",
215
  "text": [
216
+ "{'african leopard': 1.279351291572084e-08, 'cheetah': 3.040315732505405e-08, 'clouded leopard': 4.387358387702989e-08, 'cougar': 1.2642824458453106e-06, 'jaguar': 3.0061545430726255e-07, 'lion': 2.5054502472698914e-08, 'snow leopard': 4.821659516096588e-08, 'tiger': 0.9999983310699463}\n"
217
  ]
218
  },
219
  {
 
257
  "name": "stdout",
258
  "output_type": "stream",
259
  "text": [
260
+ "{'african leopard': 2.2317146886052797e-06, 'cheetah': 6.153353297122521e-06, 'clouded leopard': 3.5761433991865488e-06, 'cougar': 0.9940788745880127, 'jaguar': 7.271950153153739e-08, 'lion': 0.005906379781663418, 'snow leopard': 1.0360908220263809e-07, 'tiger': 2.569006483099656e-06}\n"
261
  ]
262
  },
263
  {
 
301
  "name": "stdout",
302
  "output_type": "stream",
303
  "text": [
304
+ "{'african leopard': 7.383512135028525e-10, 'cheetah': 1.6924343526625307e-06, 'clouded leopard': 3.8847122740826023e-10, 'cougar': 1.4941306858418102e-08, 'jaguar': 3.277633942033731e-09, 'lion': 0.9999983310699463, 'snow leopard': 4.2623696572263725e-08, 'tiger': 5.7686470711360016e-08}\n"
305
  ]
306
  },
307
  {
 
345
  "name": "stdout",
346
  "output_type": "stream",
347
  "text": [
348
+ "{'african leopard': 0.11080536246299744, 'cheetah': 0.00025237080990336835, 'clouded leopard': 0.0003655211767181754, 'cougar': 1.1126862773380708e-05, 'jaguar': 0.8603838086128235, 'lion': 8.311066630994901e-05, 'snow leopard': 0.028046416118741035, 'tiger': 5.234780110185966e-05}\n"
349
  ]
350
  },
351
  {
 
389
  "name": "stdout",
390
  "output_type": "stream",
391
  "text": [
392
+ "{'african leopard': 5.991949336703328e-08, 'cheetah': 1.2888077272066312e-08, 'clouded leopard': 0.9999984502792358, 'cougar': 7.355600928349304e-07, 'jaguar': 5.131531679580803e-07, 'lion': 5.543293823961903e-09, 'snow leopard': 3.404375448212704e-08, 'tiger': 2.0324510785485472e-07}\n"
393
  ]
394
  },
395
  {
 
433
  "name": "stdout",
434
  "output_type": "stream",
435
  "text": [
436
+ "{'african leopard': 2.2017589799361303e-05, 'cheetah': 9.802879503695294e-05, 'clouded leopard': 0.0109814228489995, 'cougar': 1.8166520021623e-06, 'jaguar': 5.0095695769414306e-06, 'lion': 5.28784084963263e-06, 'snow leopard': 0.988881528377533, 'tiger': 4.889693173026899e-06}\n"
437
  ]
438
  }
439
  ],
 
448
  },
449
  {
450
  "cell_type": "code",
451
+ "execution_count": null,
452
  "id": "a48e7483-c04b-4048-a1ae-34a8c7986a57",
453
  "metadata": {},
454
  "outputs": [
 
497
  },
498
  "metadata": {},
499
  "output_type": "display_data"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
  }
501
  ],
502
  "source": [
 
508
  " with gr.Column(variant=\"panel\"):\n",
509
  " image = gr.inputs.Image(label=\"Pick an image\")\n",
510
  " model = gr.inputs.Dropdown(label=\"Select a model\", choices=models)\n",
511
+ " with gr.Row(equal_height=True):\n",
512
+ " btnClassify = gr.Button(\"Classify\")\n",
513
+ " btnClear = gr.Button(\"Clear\")\n",
514
  " with gr.Column(variant=\"panel\"):\n",
515
  " selected = gr.outputs.Textbox(label=\"Active Model\")\n",
516
  " with gr.Row(equal_height=True):\n",
 
518
  " losses=gr.outputs.Image(type='filepath', label=\"Top Losses\")\n",
519
  " result = gr.outputs.Label(label=\"Result\")\n",
520
  " \n",
 
521
  " img_gallery = gr.Examples(examples=example_images, inputs=image)\n",
522
  "\n",
523
+ " # Register all event listeners\n",
524
  " model.change(fn=select_model, inputs=model, outputs=selected)\n",
525
  " model.change(fn=update_matrix, outputs=matrix)\n",
526
  " model.change(fn=update_losses, outputs=losses)\n",
527
+ " btnClassify.click(fn=classify_image, inputs=image, outputs=result)\n",
528
+ " btnClear.click(fn=lambda: gr.Image.update(value=None), inputs=None, outputs=None)\n",
529
  "\n",
530
  "demo.launch(debug=True, inline=False)\n",
531
  " # intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )\n",
 
535
  },
536
  {
537
  "cell_type": "code",
538
+ "execution_count": null,
539
  "id": "cab071f9-7c3b-4b35-a0d1-3687731ffce5",
540
  "metadata": {},
541
+ "outputs": [],
 
 
 
 
 
 
 
 
542
  "source": [
543
  "import nbdev\n",
544
  "nbdev.export.nb_export('app.ipynb', './')\n",
app.py CHANGED
@@ -1,14 +1,15 @@
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
 
3
  # %% auto 0
4
- __all__ = ['title', 'description', 'learners', 'models', 'active_name', 'active_model', 'example_images', 'demo',
5
- 'classify_image', 'select_model', 'update_matrix', 'update_losses']
6
 
7
  # %% app.ipynb 1
8
  from fastai.vision.all import *
9
  import gradio as gr
10
- import warnings
11
- warnings.filterwarnings('ignore')
 
12
 
13
  title = "FastAI - Big Cats Classifier"
14
  description = "Classify big cats using all Resnet models available pre-trained in FastAI"
@@ -55,7 +56,9 @@ with demo:
55
  with gr.Column(variant="panel"):
56
  image = gr.inputs.Image(label="Pick an image")
57
  model = gr.inputs.Dropdown(label="Select a model", choices=models)
58
- btnClassify = gr.Button("Classify")
 
 
59
  with gr.Column(variant="panel"):
60
  selected = gr.outputs.Textbox(label="Active Model")
61
  with gr.Row(equal_height=True):
@@ -63,13 +66,14 @@ with demo:
63
  losses=gr.outputs.Image(type='filepath', label="Top Losses")
64
  result = gr.outputs.Label(label="Result")
65
 
66
- btnClassify.click(fn=classify_image, inputs=image, outputs=result)
67
  img_gallery = gr.Examples(examples=example_images, inputs=image)
68
 
69
- # Register all ev
70
  model.change(fn=select_model, inputs=model, outputs=selected)
71
  model.change(fn=update_matrix, outputs=matrix)
72
  model.change(fn=update_losses, outputs=losses)
 
 
73
 
74
  demo.launch(debug=True, inline=False)
75
  # intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )
 
1
  # AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb.
2
 
3
  # %% auto 0
4
+ __all__ = ['interpretation', 'enable_queue', 'title', 'description', 'learners', 'models', 'active_name', 'active_model',
5
+ 'example_images', 'demo', 'classify_image', 'select_model', 'update_matrix', 'update_losses']
6
 
7
  # %% app.ipynb 1
8
  from fastai.vision.all import *
9
  import gradio as gr
10
+
11
+ interpretation='default'
12
+ enable_queue=True
13
 
14
  title = "FastAI - Big Cats Classifier"
15
  description = "Classify big cats using all Resnet models available pre-trained in FastAI"
 
56
  with gr.Column(variant="panel"):
57
  image = gr.inputs.Image(label="Pick an image")
58
  model = gr.inputs.Dropdown(label="Select a model", choices=models)
59
+ with gr.Row(equal_height=True):
60
+ btnClassify = gr.Button("Classify")
61
+ btnClear = gr.Button("Clear")
62
  with gr.Column(variant="panel"):
63
  selected = gr.outputs.Textbox(label="Active Model")
64
  with gr.Row(equal_height=True):
 
66
  losses=gr.outputs.Image(type='filepath', label="Top Losses")
67
  result = gr.outputs.Label(label="Result")
68
 
 
69
  img_gallery = gr.Examples(examples=example_images, inputs=image)
70
 
71
+ # Register all event listeners
72
  model.change(fn=select_model, inputs=model, outputs=selected)
73
  model.change(fn=update_matrix, outputs=matrix)
74
  model.change(fn=update_losses, outputs=losses)
75
+ btnClassify.click(fn=classify_image, inputs=image, outputs=result)
76
+ btnClear.click(fn=lambda: gr.Image.update(value=None), inputs=None, outputs=None)
77
 
78
  demo.launch(debug=True, inline=False)
79
  # intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=example_images, title=title, description=description )