Spaces:
Sleeping
Sleeping
Jeff Chen
commited on
Commit
·
857df21
1
Parent(s):
7937caf
hello
Browse files- app.py +18 -4
- black.jfif +0 -0
- dunno.jfif +0 -0
- grizzly.jfif +0 -0
- model.pkl +3 -0
- teddy.jfif +0 -0
app.py
CHANGED
@@ -1,7 +1,21 @@
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
def
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
1 |
+
__all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf']
|
2 |
+
|
3 |
+
from fastai.vision.all import *
|
4 |
import gradio as gr
|
5 |
|
6 |
+
def is_cat(x): return x[0].isupper()
|
7 |
+
|
8 |
+
learn = load_learner('model.pkl')
|
9 |
+
|
10 |
+
categories = ('Black Bear', 'Grizzly Bear', 'Teddy Bear')
|
11 |
+
|
12 |
+
def classify_image(img):
|
13 |
+
pred,idx,probs = learn.predict(img)
|
14 |
+
return dict(zip(categories, map(float,probs)))
|
15 |
+
|
16 |
+
image = gr.inputs.Image(shape=(192, 192))
|
17 |
+
label = gr.outputs.Label()
|
18 |
+
examples = ['black.jfif', 'grizzly.jfif', 'teddy.jfif', 'dunno.jfif']
|
19 |
|
20 |
+
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
21 |
+
intf.launch(inline=False)
|
black.jfif
ADDED
Binary file (917 kB). View file
|
|
dunno.jfif
ADDED
Binary file (20.4 kB). View file
|
|
grizzly.jfif
ADDED
Binary file (402 kB). View file
|
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:887831f51b533c68a28aa7e412fa2a4dbb7343ac854d242c91e20fc93b63a9c5
|
3 |
+
size 46960829
|
teddy.jfif
ADDED
Binary file (193 kB). View file
|
|