File size: 824 Bytes
e28465a
 
c0e0c45
 
e28465a
c0e0c45
 
 
e28465a
c0e0c45
 
 
 
 
 
 
 
 
 
e28465a
 
c0e0c45
 
e28465a
 
 
 
c0e0c45
e28465a
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
import os

import gradio as gr
from fastai.vision.all import PILImage, load_learner
from gradio.components import Image, Label

learn = load_learner("model.pkl")
labels = learn.dls.vocab
examples = ["examples/" + file for file in os.listdir("examples")]


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))}


gradio_interface = gr.Interface(
    fn=predict,
    inputs=Image(shape=(512, 512)),
    outputs=Label(num_top_classes=2),
    allow_flagging="never",
    live=True,
    examples=examples,
    title="Angry Carroll",
    description="Can AI tell the difference between Carroll and Nunez? \
        Upload a photo or choose an example below to test it out!",
)
gradio_interface.launch(enable_queue=True)