butterflies / app.py
mahuna's picture
Adding all the files
aa0604c
raw
history blame contribute delete
986 Bytes
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)