Spaces:
Runtime error
Runtime error
import gradio as gr | |
from fastai.vision.all import * | |
import skimage | |
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.jpeg', | |
'./crack_2.jpg', './red_arch.jpg', | |
'./green.jpg', './red.jpg', './opening_door.jpg', | |
'./inside.jpg', './cracked_3.jpg', './old.jpg', | |
'./blue.jpg', './closed-door.jpeg', './crack_1.jpg'] | |
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=(512, 512)), | |
outputs=gr.Label(num_top_classes=3), | |
title=title, | |
description=description, | |
examples=examples, | |
interpretation="default").queue().launch() | |