Spaces:
Sleeping
Sleeping
Commit ·
d7d8358
1
Parent(s): 2c402e9
Updated to dog/cat classifier.
Browse files
app.py
CHANGED
|
@@ -1,7 +1,30 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
def greet(name):
|
| 4 |
return "Hello " + name + "!!"
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def is_cat(x):
|
| 6 |
+
return x[0].isupper()
|
| 7 |
+
|
| 8 |
|
| 9 |
def greet(name):
|
| 10 |
return "Hello " + name + "!!"
|
| 11 |
|
| 12 |
+
|
| 13 |
+
learn = load_learner("model.pkl")
|
| 14 |
+
|
| 15 |
+
categories = ("Dog", "Cat")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def classify_image(img):
|
| 19 |
+
pred, idx, probs = learn.predict(img)
|
| 20 |
+
return dict(zip(categories, map(float, probs)))
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
image = gr.inputs.Image(shape=(192, 192))
|
| 24 |
+
label = gr.outputs.Label()
|
| 25 |
+
examples = ["dog.jpg", "cat.jpg", "dunno.png"]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
iface = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
|
| 29 |
+
iface.launch(inline=False)
|
| 30 |
+
|
cat.jpg
ADDED
|
dog.jpg
ADDED
|
dunno.png
ADDED
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dcdb8c18ace8f284e8fa8d73f75e3c24e374a653e25bb529bdfa8a2d4a7e643a
|
| 3 |
+
size 47060011
|