File size: 625 Bytes
590447b
 
b55a370
97fe8f1
 
 
 
590447b
 
 
 
 
 
 
 
b55a370
97fe8f1
590447b
 
a52b680
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from fastai.vision.all import *
import gradio as gr
import os


def get_label_from_file_path(path):
    return os.path.basename(os.path.dirname(path))


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))}


script_dir = os.path.dirname(os.path.realpath(__file__))
learn_inf = load_learner(script_dir + '/model/cat_dog_classifier.pkl')
labels = learn_inf.dls.vocab
gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(224, 224)),
             outputs=gr.outputs.Label(num_top_classes=3)).launch(share=False)