File size: 834 Bytes
b898dbc
873bd31
b898dbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from fastai.vision.all import *
import timm

import gradio as gr

def get_label(img_path):
    one_hot = df.query('image_name == @img_path.name').iloc[:, 1:].values[0]
    return one_hot

learn = load_learner('model.pkl')

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 = "Pizza Toppings Classifier"
description = "A pizza toppings classifier trained on the MIT pizza dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces."
examples = ['onions_and_peppers.jpg', 'pepperoni_and_mushrooms.jpg']
interpretation='default'
enable_queue=True

gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=10)).launch(share=True)