File size: 727 Bytes
83f183a
4acf485
83f183a
4acf485
04e1269
4acf485
aa061fc
4acf485
 
 
 
 
 
83f183a
4acf485
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
from fastai.vision.all import *

learn_inf = load_learner('model.pkl')

features = learn_inf.dls.vocab

def predict_image(image):
    pred_class, pred_idx, probs = learn_inf.predict(image)
    return {str(features[i]): float(probs[i]) for i in range(len(learn_inf.dls.vocab))}

input_image = gr.inputs.Image(shape=(None, None))
output_label = gr.outputs.Label(num_top_classes=3)

gr.Interface(fn=predict_image,
             inputs=input_image,
             outputs=output_label,
             title="Image Classifier",
             description=f"Upload an image to classify it into one of the following categories: {' | '.join([f'{item}' for item in features])}",
             capture_session=True).launch()