File size: 934 Bytes
73fc5dd
351ff91
73fc5dd
351ff91
73fc5dd
 
351ff91
 
 
 
 
 
 
73fc5dd
 
 
351ff91
 
73fc5dd
 
 
351ff91
 
 
 
73fc5dd
351ff91
 
 
 
73fc5dd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# 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)