c5huracan commited on
Commit
9325160
·
1 Parent(s): ad4e30e

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # import gradio.components as gr
2
+ import gradio as gr
3
+ # from PIL import Image
4
+ from fastai.vision.all import *
5
+ import skimage
6
+
7
+ learn = load_learner('pets-model-resnet18.pkl')
8
+
9
+ labels = learn.dls.vocab
10
+ def predict(img):
11
+ img = PILImage.create(img)
12
+ pred,pred_idx,probs = learn.predict(img)
13
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
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 and HuggingFace Spaces."
17
+ article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
18
+ examples = ['siamese.jpg']
19
+ interpretation='default'
20
+ enable_queue=True
21
+
22
+ gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation,enable_queue=enable_queue).launch()