Spaces:
Sleeping
Sleeping
nkhimin
commited on
Commit
β’
2bed28e
1
Parent(s):
a33b47a
message
Browse files- .DS_Store +0 -0
- .gitattributes +2 -0
- README.md +3 -4
- app.py +44 -0
- examples/.DS_Store +0 -0
- examples/10.png +3 -0
- examples/11.png +3 -0
- examples/2.png +3 -0
- examples/British_Shorthair.png +3 -0
- examples/dachshund.jpg +3 -0
- examples/pomeranian.png +3 -0
- examples/siamese.png +3 -0
- examples/toy_poodle.png +3 -0
- model-export.pkl +3 -0
- requirements.txt +3 -0
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
.gitattributes
CHANGED
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
37 |
+
*.jpg filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
@@ -1,13 +1,12 @@
|
|
1 |
---
|
2 |
title: Pet Classifier
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.27.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
10 |
-
license: apache-2.0
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: Pet Classifier
|
3 |
+
emoji: π
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: gray
|
6 |
sdk: gradio
|
7 |
sdk_version: 4.27.0
|
8 |
app_file: app.py
|
9 |
pinned: false
|
|
|
10 |
---
|
11 |
|
12 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from pathlib import Path
|
3 |
+
# from fastai.vision.all import * # noqa: F403
|
4 |
+
from fastai.learner import load_learner
|
5 |
+
from fastai.vision.core import PILImage
|
6 |
+
import os
|
7 |
+
|
8 |
+
|
9 |
+
# import skimage
|
10 |
+
|
11 |
+
|
12 |
+
# Define any custom functions or classes that the model depends on
|
13 |
+
def is_cat(x): # Make sure to define this correctly as it was used during training
|
14 |
+
return x[0].isupper()
|
15 |
+
|
16 |
+
print(os.path.abspath("model-export.pkl"))
|
17 |
+
learn = load_learner("model-export.pkl")
|
18 |
+
|
19 |
+
labels = learn.dls.vocab
|
20 |
+
|
21 |
+
|
22 |
+
def predict(img):
|
23 |
+
img = PILImage.create(img)
|
24 |
+
pred, pred_idx, probs = learn.predict(img)
|
25 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
26 |
+
|
27 |
+
|
28 |
+
title = "Pet Breed Classifier"
|
29 |
+
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
|
30 |
+
article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
31 |
+
path = Path('examples')
|
32 |
+
examples = list(path.iterdir())
|
33 |
+
|
34 |
+
gr.Interface(
|
35 |
+
fn=predict,
|
36 |
+
inputs="image",
|
37 |
+
outputs="label",
|
38 |
+
title=title,
|
39 |
+
description=description,
|
40 |
+
article=article,
|
41 |
+
examples=examples
|
42 |
+
).launch()
|
43 |
+
|
44 |
+
|
examples/.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
examples/10.png
ADDED
Git LFS Details
|
examples/11.png
ADDED
Git LFS Details
|
examples/2.png
ADDED
Git LFS Details
|
examples/British_Shorthair.png
ADDED
Git LFS Details
|
examples/dachshund.jpg
ADDED
Git LFS Details
|
examples/pomeranian.png
ADDED
Git LFS Details
|
examples/siamese.png
ADDED
Git LFS Details
|
examples/toy_poodle.png
ADDED
Git LFS Details
|
model-export.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:31ce20b2b77e13cc4cbf4014dab953ea42f8c3a626a6983f62a76f3b3a55ff2c
|
3 |
+
size 47072792
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
gradio==4.27
|
2 |
+
fastai==2.7.14
|
3 |
+
scikit-image==0.22
|