Spaces:
Sleeping
Sleeping
Commit
·
f1b3d63
1
Parent(s):
39d7624
Create dog-or-cat classifier
Browse files- app.py +18 -3
- cat.jpg +0 -0
- dog.jpg +0 -0
- model.pkl +3 -0
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -1,7 +1,22 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
|
| 3 |
-
def
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from fastai.vision.all import *
|
| 3 |
|
| 4 |
+
def is_cat(x): return x[0].isupper()
|
| 5 |
+
learner = load_learner('model.pkl')
|
| 6 |
|
| 7 |
+
labels = ['Dog', 'Cat']
|
| 8 |
+
|
| 9 |
+
def predict(img):
|
| 10 |
+
img = PILImage.create(img)
|
| 11 |
+
pred, pred_idx, probs = learner.predict(img)
|
| 12 |
+
return {label: float(probs[idx]) for idx, label in enumerate(labels)}
|
| 13 |
+
|
| 14 |
+
iface = gr.Interface(
|
| 15 |
+
fn=predict,
|
| 16 |
+
inputs='image',
|
| 17 |
+
outputs='label',
|
| 18 |
+
title="Cat or Dog Classifier",
|
| 19 |
+
description="A cat or dog classifier trained with fastai",
|
| 20 |
+
examples=['cat.jpg', 'dog.jpg'],
|
| 21 |
+
)
|
| 22 |
iface.launch()
|
cat.jpg
ADDED
|
dog.jpg
ADDED
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1c09d8f778f89c9eb588eefd9a5ba094eb163cd3ea708a4ea567a83e924f149f
|
| 3 |
+
size 47059947
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
fastai
|