dnth commited on
Commit
935bfed
1 Parent(s): 4aaa11c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from fastai.vision.all import *
3
+ import skimage
4
+
5
+ learn = load_learner('export.pkl')
6
+
7
+ labels = learn.dls.vocab
8
+ def predict(img):
9
+ img = PILImage.create(img)
10
+ pred,pred_idx,probs = learn.predict(img)
11
+ return {labels[i]: float(probs[i]) for i in range(len(labels))}
12
+
13
+ import os
14
+ for root, dirs, files in os.walk(r'sample_images/'):
15
+ for filename in files:
16
+ print(filename)
17
+
18
+ title = "Pet Breed Classifier"
19
+ description = "A pet breed classifier trained on the Oxford Pets dataset"
20
+ interpretation='default'
21
+ examples = ["sample_images/"+file for file in files]
22
+ article="<p style='text-align: center'><a href='https://dicksonneoh.com/pet-classifier/' target='_blank'>Blog post</a></p>"
23
+ enable_queue=True
24
+
25
+ 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()