road_or_gravel / app.py
lucasvw's picture
update
cc5feed
# AUTOGENERATED! DO NOT EDIT! File to edit: ../01.ipynb.
# %% auto 0
__all__ = ['learner', 'labels', 'image', 'outputs', 'title', 'description', 'examples', 'interpretation', 'predict']
# %% ../01.ipynb 3
from fastai.vision.all import *
# %% ../01.ipynb 4
learner = load_learner('model.pkl')
# %% ../01.ipynb 5
labels = learner.dls.vocab
def predict(img):
img = PILImage.create(img)
pred,pred_idx,probs = learner.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
# %% ../01.ipynb 7
import gradio as gr
# %% ../01.ipynb 8
image = gr.inputs.Image(shape=(512, 512))
outputs = gr.outputs.Label(num_top_classes=3)
title = "Road vs Gravel Bike Classifier"
description = "Since for a human it's sometimes almost impossible to distuingish the two, let's see if an AI is better at telling them apart!"
examples = ['gravelbike.jpeg', 'roadbike.jpeg']
interpretation='default'
gr.Interface(fn=predict, inputs=image, outputs=outputs, title=title, description=description, examples=examples).launch(inline=False)