File size: 938 Bytes
a10151c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51cf471
a10151c
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
#!/usr/bin/env python
# coding: utf-8

# # Bear Classifier
# 
# This is a prototype tool to deploy a model which classifies 3 bear categories namely Black, Grizzly and Teddy (Toys)
# 
# Upload a picture of a bear and click classify to the results



from fastai.vision.all import *
import gradio as gr
import skimage


learn_inf = load_learner('bear_model.pkl')
labels = learn_inf.dls.vocab


def predict(img):
    img = PILImage.create(img)
    pred,pred_idx,probs = learn_inf.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}

gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3), title = "Bear Classifier",
description = "A Bear Classifier trained with fastai. Created as a demo for Gradio and HuggingFace Spaces. Classifies from Grizzly, Black and Teddy(Toys). ",interpretation='default', examples=['ted.jpg','grizzly.jpg']).launch(share=True)