NovaOrToast / app.py
exiomius
First Attempt using NBdev notebook to file
73fc5dd
raw
history blame
934 Bytes
# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/app.ipynb (unless otherwise specified).
__all__ = ['classify_image', 'learn_inf', 'categories', 'image', 'label', 'examples', 'intf']
# Cell
# Importing neccesary modules
import fastbook
fastbook.setup_book()
from fastbook import *
from fastai.vision.widgets import *
from fastai.vision.all import *
import gradio as gr
# Cell
learn_inf = load_learner('NovaOrToastModel.pkl') # Loading the model
learn_inf.dls.vocab # Returns a list of the categories
categories = learn_inf.dls.vocab
# Gradio code:
# Function for Gradio to use to classify images
def classify_image(img):
pred, idx, probs = learn_inf.predict(img)
return dict(zip(categories, map(float,probs)))
image = gr.inputs.Image(shape=(192,192))
label = gr.outputs.Label()
examples = ["ToastTest.jpeg"]
intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)
intf.launch(inline=False)