Spaces:
Sleeping
Sleeping
Commit
·
dc1de53
1
Parent(s):
2c0c92c
deploy to huggingface spaces
Browse files- app.py +24 -0
- cat.jpg +0 -0
- dog.jpg +0 -0
- hybrid.jpg +0 -0
- model.pkl +3 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = ['is_cat', 'learn', 'classify_image', 'categories', 'image', 'labels', 'examples', 'intf']
|
| 2 |
+
|
| 3 |
+
from fastai.vision.all import *
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
# labelling function
|
| 7 |
+
def is_cat(x): return x[0].isupper()
|
| 8 |
+
|
| 9 |
+
learn = load_learner('model.pkl')
|
| 10 |
+
|
| 11 |
+
# create categories and classifying function for HuggingFace Space
|
| 12 |
+
categories = ('Dog', 'Cat')
|
| 13 |
+
|
| 14 |
+
def classify_image(img):
|
| 15 |
+
pred,idx,probs = learn.predict(img)
|
| 16 |
+
# gradio wants a dictionary
|
| 17 |
+
return dict(zip(categories, map(float, probs)))
|
| 18 |
+
|
| 19 |
+
image = gr.inputs.Image(shape=(192,192))
|
| 20 |
+
label = gr.outputs.Label()
|
| 21 |
+
examples = ['dog.jpg', 'cat.jpg', 'hybrid.jpg']
|
| 22 |
+
|
| 23 |
+
intf = gr.Interface(fn=classify_image, inputs = image, outputs = label, examples = examples)
|
| 24 |
+
intf.launch(inline = False)
|
cat.jpg
ADDED
|
dog.jpg
ADDED
|
hybrid.jpg
ADDED
|
model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9a0b8910baa00a4b0d577c478292cf815877403fd8d7572e37ae55c138815911
|
| 3 |
+
size 47065323
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
fastai
|