Spaces:
Sleeping
Sleeping
adding app.py and export.pkl files
Browse files- app.py +33 -0
- export.pkl +3 -0
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastai.vision.all import *
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import glob
|
| 4 |
+
|
| 5 |
+
learn = load_learner('export.pkl')
|
| 6 |
+
|
| 7 |
+
labels = learn.dls.vocab
|
| 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 |
+
title='Pet Breed Classifier'
|
| 15 |
+
description = ('Pet breed classifier trained on the Oxford Pets dataset' +
|
| 16 |
+
'with the fastai library and the ResNet50 neural network architecture. ' +
|
| 17 |
+
'Based on the tutorial by Dr Tanishq Abraham.')
|
| 18 |
+
article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
|
| 19 |
+
|
| 20 |
+
subfolder = Path('pets')
|
| 21 |
+
search_pattern = str(subfolder/'*.jpg')
|
| 22 |
+
jpg_files = glob.glob(search_pattern)
|
| 23 |
+
|
| 24 |
+
gr.Interface(fn=predict,
|
| 25 |
+
inputs=gr.Image(),
|
| 26 |
+
outputs=gr.Label(num_top_classes=3),
|
| 27 |
+
title=title,
|
| 28 |
+
description=description,
|
| 29 |
+
article=article,
|
| 30 |
+
examples=jpg_files,
|
| 31 |
+
examples_per_page=37,
|
| 32 |
+
enable_queue=True
|
| 33 |
+
).launch()
|
export.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:57b28eefe233e7a4e09ea01309d52d99fbb97d1173ac83976638f0833740f59e
|
| 3 |
+
size 103061589
|