File size: 1,063 Bytes
9abef9f
 
 
8521848
9abef9f
 
 
 
 
 
e39d03a
 
5d0802c
 
 
 
 
a9eaf12
8521848
 
 
 
 
 
 
78f684b
e39d03a
9abef9f
 
 
 
 
e39d03a
bd25240
e39d03a
9abef9f
 
 
 
 
bd25240
19f236b
9abef9f
 
19f236b
9abef9f
8521848
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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: 
        os.path.join(
            os.path.dirname(__file__), 
            "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.inputs.Image(shape=(224, 224)),
    outputs=gr.outputs.Label(),
    title=title,
    description=description,
    examples=['examples/red.jpg']).launch()