fastaicourse / app.py
kaesb
Added title and description to the app
76f3e8b
raw
history blame contribute delete
679 Bytes
from fastai.vision.all import *
import gradio as gr
import pathlib
plt = platform.system()
if plt != 'Windows': pathlib.WindowsPath = pathlib.PosixPath
learner_dir = pathlib.Path('cat_dog_model.pkl')
learn = load_learner(learner_dir)
labels = learn.dls.vocab
def predict(img):
img = PILImage.create(img)
pred,pred_idx,probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
title = "Cat or dog?"
description = "Guesses whether the picture is of a cat or a dog"
gr.Interface(fn=predict, inputs=gr.components.Image(shape=(512, 512)), outputs=gr.components.Label(num_top_classes=3), title=title,description=description).launch()