catdog / app.py
romlinux's picture
Do not support share as it is not supported in spaces
a52b680
raw
history blame contribute delete
625 Bytes
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)