File size: 693 Bytes
1e42e9a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastai.vision.all import *
import gradio as gr


learn = load_learner("bear-classifier.pkl")
labels = learn.dls.vocab

def predict(img):
    """
    Prediction APIs.
    """
    _, _, probs = learn.predict(PILImage.create(img))

    return {labels[i]: float(probs[i]) for i in range(len(labels))}


demo = gr.Interface(
    fn=predict, 
    inputs=gr.Image(), 
    outputs=gr.Label(num_top_classes=3), 
    title="Bear Classifier", 
    description="A bear classifier fine tuned on ResNet18 with a few bear samples from the internet. Its task is to recognize whether an image is a grizzy bear, a black bear or just a cute litte teddy bear!", 
    examples=["grizzly.jpg"]
)
demo.launch()