File size: 862 Bytes
0a6c2ae
 
 
 
8842891
 
 
 
 
 
 
 
 
 
 
 
0a6c2ae
8842891
0a6c2ae
 
 
8842891
 
 
 
0a6c2ae
 
 
8842891
 
0a6c2ae
 
 
8842891
 
a2326f6
8842891
 
 
 
 
0a6c2ae
8842891
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
import gradio as gr
from fastai.vision.core import PILImage
import fastai.vision.all as fav
import os
import sys


def is_cat(x):
    return x[0].isupper()  # Used by model


sys.modules["__main__"].is_cat = is_cat


if os.name != "posix":
    print("Converting PosixPath to WindowsPath")
    import pathlib

    pathlib.PosixPath = pathlib.WindowsPath


learn = fav.load_learner("model.pkl")

labels = ["That's a dog", "That's a cat"]


def predict(img):
    img = PILImage.create(img)
    pred, pred_idx, probs = learn.predict(img)
    pred = "That's a cat" if pred else "That's a dog"
    return {labels[i]: float(probs[i]) for i in range(len(labels))}


iface = gr.Interface(
    fn=predict,
    inputs="image",
    outputs="label",
    live=True,
    title="My first Gradio",
    description="Well it's really all been said in the title",
)

iface.launch()