Jeff Parks commited on
Commit
39fd66c
·
1 Parent(s): b277525

added app.py and model

Browse files
Files changed (2) hide show
  1. app.py +24 -0
  2. image_classifier_caltech101.pkl +3 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastai.vision.all import *
2
+ import gradio as gr
3
+
4
+ # gradio
5
+ learn_caltech101 = load_learner('image_classifier_caltech101.pkl')
6
+
7
+ # build prediction function
8
+ labels = learn_caltech101.dls.vocab
9
+
10
+ def predict(img):
11
+ img = PILImage.create(img)
12
+ pred, pred_idx, probs = learn_caltech101.predict(img)
13
+ return {str(labels[i]):float(probs[i]) for i in range(len(labels))}
14
+
15
+ # build gradio interface
16
+ gradio_interface = gr.Interface(
17
+ title = "Caltech_101 Image Classifier",
18
+ description = "A simple image classifier based on the Caltech_101 dataset.",
19
+ fn=predict,
20
+ inputs = gr.inputs.Image(shape=(224,224)),
21
+ outputs = gr.outputs.Label(num_top_classes=5)
22
+ )
23
+
24
+ gradio_interface.launch(enable_queue=True)
image_classifier_caltech101.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c2aeeaa7751f9c9c1f309bab71fbb0a22f747fd01cde17212903860e68e219dd
3
+ size 87836655