Spaces:
Sleeping
Sleeping
Jeff Parks
commited on
Commit
·
9fdc9ee
1
Parent(s):
623c56b
added model
Browse files- app.py +27 -0
- image_classifier_flowers.pkl +3 -0
- requirements.txt +1 -0
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import gr.themes.*
|
| 3 |
+
|
| 4 |
+
# import model for gradio
|
| 5 |
+
learn_gradio = load_learner('image_classifier_flowers.pkl')
|
| 6 |
+
|
| 7 |
+
# build prediction function
|
| 8 |
+
labels = learn_gradio.dls.vocab
|
| 9 |
+
|
| 10 |
+
def predict(img):
|
| 11 |
+
img = PILImage.create(img)
|
| 12 |
+
pred,pred_idx,probs = learn_gradio.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 |
+
theme=gr.themes.Soft(),
|
| 18 |
+
title = "Flower Image Classifier",
|
| 19 |
+
description = "A simple classifier for the 102-category <a href='https://www.robots.ox.ac.uk/~vgg/data/flowers/' target='new'>Flower Dataset</a>",
|
| 20 |
+
fn=predict,
|
| 21 |
+
inputs = gr.inputs.Image(shape=(224,224)),
|
| 22 |
+
outputs = gr.outputs.Label(num_top_classes=5),
|
| 23 |
+
enable_queue=True,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
# launch interface
|
| 27 |
+
gradio_interface.launch(share=True)
|
image_classifier_flowers.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:5d08b9b787bb49daf960feeefe9ca861698b32087218b8717580265e95ba7abf
|
| 3 |
+
size 87704526
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
fastai
|