Spaces:
Sleeping
Sleeping
#__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() |