Josh commited on
Commit
6362a59
·
1 Parent(s): 012a29b

Add prediction function

Browse files
Files changed (1) hide show
  1. app.py +8 -0
app.py CHANGED
@@ -3,6 +3,14 @@ import gradio as gr
3
  from fastai.vision.all import *
4
  import skimage
5
 
 
 
 
 
 
 
 
 
6
  title = "Pet Breed Classifier"
7
  description = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces. Thank you to Tanishq Abraham for making this demo."
8
  article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
 
3
  from fastai.vision.all import *
4
  import skimage
5
 
6
+ learn = load_learner('export.pkl')
7
+
8
+ labels = learn.dls.vocab
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 = "A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces. Thank you to Tanishq Abraham for making this demo."
16
  article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"