Spaces:
Sleeping
Sleeping
File size: 797 Bytes
5bc1a59 5e9f943 5bc2870 |
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 26 27 28 29 |
#__all__ = ["examples", "iface", "learn", "labels", "classify_bear", "bear_image", "outputs"]
import gradio as gr
from fastai.vision.all import *
from fastcore.all import *
learn = load_learner("model/export.pkl")
labels = learn.dls.vocab
examples = [
"examples/black.jpg",
"examples/grizzly.jpg",
"examples/panda.jpg",
"examples/polar.jpg",
"examples/teddy.png"
]
def classify_bear(img):
img = PILImage.create(img)
pred,idx,probs = learn.predict(img)
return f"Prediction: {pred}; Probability: {probs[idx]:.04f}"
bear_image = gr.inputs.Image(shape=(192,192))
outputs = gr.outputs.Label(num_top_classes=5)
# App launch
iface = gr.Interface(
fn=classify_bear, inputs=bear_image, outputs=outputs, examples=examples)
iface.launch() |