|
from fastai.vision.all import * |
|
from fastai.vision.widgets import * |
|
import gradio as gr |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
learn = load_learner('kinds_of_butterflies_model.pkl') |
|
|
|
|
|
def classify_image(img): |
|
pred, idx, probs = learn.predict(img) |
|
categories = learn.dls.vocab |
|
label_pred = widgets.Label() |
|
label_pred.value = f'Prediction: {pred}; Probability: {probs[idx]:.04f}' |
|
print(label_pred) |
|
float_values = map(float, probs) |
|
return dict(zip(categories, float_values)) |
|
|
|
|
|
image = gr.Image() |
|
label = gr.Label() |
|
examples = ['forest.jpg', 'monarch.jpg', 'swallow.jpg'] |
|
|
|
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples) |
|
intf.launch(inline=False) |
|
|