Spaces:
Runtime error
Runtime error
Commit ·
1d4a191
1
Parent(s): 90a6677
added app.py and example images
Browse files- app.py +31 -0
- images/black.jpg +0 -0
- images/grizzly.jpg +0 -0
- images/teddy.jpg +0 -0
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../app.ipynb.
|
| 2 |
+
|
| 3 |
+
# %% auto 0
|
| 4 |
+
__all__ = ['learn', 'categories', 'image', 'label', 'examples', 'intf', 'is_teddy', 'classify_image']
|
| 5 |
+
|
| 6 |
+
# %% ../app.ipynb 1
|
| 7 |
+
from fastai.vision.all import *
|
| 8 |
+
import gradio as gr
|
| 9 |
+
|
| 10 |
+
# %% ../app.ipynb 2
|
| 11 |
+
def is_teddy(x):
|
| 12 |
+
return x[0].isupper()
|
| 13 |
+
|
| 14 |
+
# %% ../app.ipynb 5
|
| 15 |
+
learn = load_learner('bearClassifier.pkl')
|
| 16 |
+
|
| 17 |
+
# %% ../app.ipynb 8
|
| 18 |
+
categories = ('grizzly', 'black', 'teddy')
|
| 19 |
+
|
| 20 |
+
def classify_image(img):
|
| 21 |
+
pred, idx, probs = learn.predict(img)
|
| 22 |
+
return dict(zip(categories, map(float, probs)))
|
| 23 |
+
|
| 24 |
+
# %% ../app.ipynb 10
|
| 25 |
+
image = gr.components.Image()
|
| 26 |
+
label = gr.components.Label()
|
| 27 |
+
examples = ['images/teddy.jpg', 'images/black.jpg', 'images/grizzly.jpg']
|
| 28 |
+
|
| 29 |
+
# %% ../app.ipynb 11
|
| 30 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 31 |
+
intf.launch(inline=False)
|
images/black.jpg
ADDED
|
images/grizzly.jpg
ADDED
|
images/teddy.jpg
ADDED
|