whichlight's picture
removing deprecated stuff, adding back examples
447cdd5
raw
history blame contribute delete
961 Bytes
import gradio as gr
from fastai.vision.all import *
import skimage
import os
title = "Open/Closed Door Classifier"
description = "A classifier trained using fastai on search images of open and closed doors." \
"Created for Lesson 2 in the fastai course."
examples = ["open-door.jpg",
"crack_2.jpg", "red_arch.jpg",
"green.jpg", "red.jpg", "opening_door.jpg",
"inside.jpg", "cracked_3.jpg", "old.jpg",
"blue.jpg"]
examples = list(
map(
lambda x: "examples/" + x,
examples))
#print(examples)
learn = load_learner('door_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))}
iface = gr.Interface(
fn=predict,
inputs=gr.Image(shape=(224, 224)),
outputs=gr.Label(),
title=title,
description=description,
examples=examples)
iface.launch()