Spaces:
Runtime error
Runtime error
File size: 986 Bytes
aa0604c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
from fastai.vision.all import *
import gradio as gr
# Load the model that has been trained previously
learn = load_learner('model.pkl')
# Define a function that maps the model's predicted probabilities to the possible categories
categories = ('cabbage white butterfly', 'common blue butterfly', 'monarch butterfly', 'red admiral butterfly') # ALPHABETICAL
def classify_image(img):
_,_,probs = learn.predict(img)
return dict(zip(categories, map(float,probs)))
# Making the UI
# Makes a box where images can be dropped as inputs to the model
image = gr.inputs.Image(shape=(192,192))
# Makes an output box to display the output label predictions
label = gr.outputs.Label()
# Provide some example images
examples = ['butterfly1.jpeg', 'butterfly2.jpeg', 'butterfly3.jpeg', 'butterfly4.jpeg', 'butterfly5.jpeg', 'butterfly6.jpeg',]
# Export the result to the UI
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False) |