File size: 1,453 Bytes
e5a756f
b32ee1e
e5a756f
a22f15d
956d1f2
a22f15d
 
6dcd719
956d1f2
42e90e2
 
b32ee1e
e5a756f
d68a05b
 
b32ee1e
d68a05b
 
b32ee1e
 
d68a05b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b32ee1e
 
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
49
50
51
52
import gradio as gr
from fastai.vision.all import *

title = "Interstellar"
description = (
    "Experimental Astronomical Classifier built for the fast.ai 'Deep Learning' "
    "course by fine tuning ResNet50 (1 + 3 epochs) with a custom dataset "
    "of images (150 per label with augmentation)."
)
inputs = gr.components.Image()
outputs = gr.components.Label()
examples = "examples"

model_class = load_learner("models/model.class.pkl")
labels_class = model_class.dls.vocab

model_object = load_learner("models/model.object.pkl")
labels_object = model_object.dls.vocab


def predict_class(img):
    pred, pred_idx, probs = model_class.predict(img)
    return dict(zip(labels_class, map(float, probs)))


def predict_object(img):
    pred, pred_idx, probs = model_object.predict(img)
    return dict(zip(labels_object, map(float, probs)))


with gr.Blocks() as demo:
    with gr.Tab("Class Prediction"):
        gr.Interface(
            fn=predict_class,
            inputs=inputs,
            outputs=outputs,
            examples=examples,
            title=title,
            description=description,
        ).queue(default_concurrency_limit=5)
    with gr.Tab("Object Prediction"):
        gr.Interface(
            fn=predict_object,
            inputs=inputs,
            outputs=outputs,
            examples=examples,
            title=title,
            description=description,
        ).queue(default_concurrency_limit=5)

demo.launch()