David Kooistra commited on
Commit
b19e2d4
1 Parent(s): e11c2b9

Put model in app file

Browse files
Files changed (2) hide show
  1. app.py +22 -4
  2. testing.ipynb +27 -2
app.py CHANGED
@@ -1,7 +1,25 @@
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
 
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
1
+ # AUTOGENERATED! DO NOT EDIT! File to edit: ../testing.ipynb.
2
+
3
+ # %% auto 0
4
+ __all__ = ['learn', 'categories', 'examples', 'intf', 'classify_img']
5
+
6
+ # %% ../testing.ipynb 1
7
+ from fastai.vision.all import *
8
  import gradio as gr
9
 
10
+ # %% ../testing.ipynb 3
11
+ learn = load_learner("model.pkl")
12
+
13
+ # %% ../testing.ipynb 5
14
+ categories = ('American Robin', 'Downy Woodpecker', 'Great Blue Heron', 'Hairy Woodpecker', 'House Sparrow')
15
+ def classify_img(img):
16
+ pred,idx,probs = learn.predict(img)
17
+ return dict(zip(categories, map(float,probs)))
18
+
19
+ # %% ../testing.ipynb 7
20
+ # image = gr.Image(shape=(256,256))
21
+ # label = gr.Label()
22
+ examples = ['american_robin.jpeg', 'downy_woodpecker.jpeg', 'great_blue_heron.jpeg', 'hairy_woodpecker.jpeg', 'house_sparrow.jpeg']
23
 
24
+ intf = gr.Interface(fn=classify_img, inputs='image', outputs='label', examples=examples)
25
+ intf.launch(inline=False)
testing.ipynb CHANGED
@@ -571,12 +571,37 @@
571
  },
572
  {
573
  "cell_type": "code",
574
- "execution_count": null,
575
  "metadata": {},
576
  "outputs": [],
577
  "source": [
578
- "from nbdev.export import notebook2script\n"
579
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
580
  }
581
  ],
582
  "metadata": {
 
571
  },
572
  {
573
  "cell_type": "code",
574
+ "execution_count": 11,
575
  "metadata": {},
576
  "outputs": [],
577
  "source": [
578
+ "import nbdev"
579
  ]
580
+ },
581
+ {
582
+ "cell_type": "code",
583
+ "execution_count": 12,
584
+ "metadata": {},
585
+ "outputs": [
586
+ {
587
+ "name": "stdout",
588
+ "output_type": "stream",
589
+ "text": [
590
+ "Export successful\n"
591
+ ]
592
+ }
593
+ ],
594
+ "source": [
595
+ "nbdev.export.nb_export('testing.ipynb', 'app')\n",
596
+ "print('Export successful')"
597
+ ]
598
+ },
599
+ {
600
+ "cell_type": "code",
601
+ "execution_count": null,
602
+ "metadata": {},
603
+ "outputs": [],
604
+ "source": []
605
  }
606
  ],
607
  "metadata": {