Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- app.py +34 -0
- export.pkl +3 -0
- requirements.txt +2 -0
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import skimage
|
4 |
+
|
5 |
+
learn = load_learner('export.pkl')
|
6 |
+
labels = learn.dls.vocab
|
7 |
+
|
8 |
+
|
9 |
+
def predict(img):
|
10 |
+
img = PILImage.create(img)
|
11 |
+
pred, pred_idx, probs = learn.predict(img)
|
12 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
13 |
+
|
14 |
+
|
15 |
+
title = "Pet Breed Classifier"
|
16 |
+
description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio " \
|
17 |
+
"and HuggingFace Spaces. "
|
18 |
+
article = "<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' " \
|
19 |
+
"target='_blank'>Blog post</a></p> "
|
20 |
+
examples = ['siamese.jpg']
|
21 |
+
interpretation = 'default'
|
22 |
+
enable_queue = True
|
23 |
+
|
24 |
+
gr.Interface(
|
25 |
+
fn=predict,
|
26 |
+
inputs=gr.inputs.Image(shape=(512, 512)),
|
27 |
+
outputs=gr.outputs.Label(num_top_classes=3),
|
28 |
+
title=title,
|
29 |
+
description=description,
|
30 |
+
article=article,
|
31 |
+
examples=examples,
|
32 |
+
interpretation=interpretation,
|
33 |
+
enable_queue=enable_queue
|
34 |
+
).launch()
|
export.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3930ab835c8564db7f5a8b1db76a8f5a082a0f8c0cb2d439d4f629a1563ee502
|
3 |
+
size 103045373
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastai
|
2 |
+
scikit-image
|