File size: 1,060 Bytes
d6e8f65
103309c
dcd9be2
d6e8f65
3b511cb
 
d6e8f65
 
 
 
8b03c49
 
 
 
 
 
 
 
 
 
103309c
8b03c49
 
 
 
 
 
 
a86d131
 
3641b49
 
 
 
8b03c49
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
30
31
32
33
34
35
36
from fastai.vision.all import *
import gradio as gr

categories = ("grizzly bear", "black bear", "teddy bear")
learn = load_learner("export.pkl")

def classify_image(img):
    pred, idx, probs = learn.predict(img)
    return dict(zip(categories, map(float, probs)))

with gr.Blocks() as demo:
    gr.Markdown("# 🐻 Bear Classifier")
    gr.Markdown("Classify different types of bears: grizzly, black, or teddy bears.")

    with gr.Row():
        image_input = gr.Image(height=192, width=192)
        label_output = gr.Label()

    btn = gr.Button("Classify")
    btn.click(fn=classify_image, inputs=image_input, outputs=label_output)

    gr.Examples(
        examples=[
            ["examples/bears.jpg"],
            ["examples/grizzly.jpg"]
        ],
        inputs=image_input
    )

if __name__ == "__main__":
    print(f"===》Torch version: {torch.__version__}")
    print(f"===》Fastai version: {fastai.__version__}")
    print(f"===》Fastcore version: {fastcore.__version__}")
    print(f"===》Python version: {sys.version}")
    demo.launch()