Rubanza Silver
commited on
Commit
·
390106f
1
Parent(s):
0c5a93b
Add application file
Browse files- app.py +44 -0
- bearClassifier.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../fastai_lesson_2_bearsInference_colab.ipynb.
|
2 |
+
|
3 |
+
# %% auto 0
|
4 |
+
__all__ = ['learn', 'image', 'label', 'examples', 'intf', 'classify_image']
|
5 |
+
|
6 |
+
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 1
|
7 |
+
#Imports
|
8 |
+
|
9 |
+
import numpy as np # linear algebra
|
10 |
+
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
|
11 |
+
|
12 |
+
#hide
|
13 |
+
[ -e /content ]
|
14 |
+
pip install -Uqq fastbook
|
15 |
+
|
16 |
+
import fastbook
|
17 |
+
fastbook.setup_book()
|
18 |
+
|
19 |
+
#hide
|
20 |
+
from fastbook import *
|
21 |
+
from fastai.vision.widgets import *
|
22 |
+
|
23 |
+
#pip install fastai
|
24 |
+
|
25 |
+
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 3
|
26 |
+
from fastai.vision.all import *
|
27 |
+
import gradio as gr
|
28 |
+
|
29 |
+
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 12
|
30 |
+
learn = load_learner('/bearClassifier.pkl')
|
31 |
+
|
32 |
+
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 15
|
33 |
+
def classify_image(img):
|
34 |
+
pred,idx,probs = learn.predict(img)
|
35 |
+
return dict(zip(categories, map(float,probs)))
|
36 |
+
|
37 |
+
# %% ../fastai_lesson_2_bearsInference_colab.ipynb 18
|
38 |
+
#create gradio interface
|
39 |
+
image = gr.inputs.Image(shape=(128,128))
|
40 |
+
label = gr.outputs.Label()
|
41 |
+
examples = ['grizzlyBearA.jpg', 'blackBearA.jpg', 'teddyBearA.jpg']
|
42 |
+
|
43 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples )
|
44 |
+
intf.launch(inline=False)
|
bearClassifier.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1be36bf5fd08a4ed7e9d5d3fcddb0093865015c2e11fdd67df91d8f708dd2c08
|
3 |
+
size 46981023
|