File size: 1,244 Bytes
9747bf9
aa7176c
 
 
9747bf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastai.vision.all import *
import gradio as gr


def hello(name):
    return 'Hello ' + name

def bye(name):
    return 'Bye ' + name

def cat_vs_dog(image):
    learn = load_learner('cat-vs-dog.pkl')
    image = PILImage.create(image)

    label, index, probabilities = learn.predict(image)

    # Create a dictionary with class label as the key and probability as value.
    return dict(zip(learn.dls.vocab, probabilities.tolist()))

def fish_vs_face(image):
    learn = load_learner('fish-vs-face.pkl')
    image = PILImage.create(image)

    label, index, probabilities = learn.predict(image)

    # Create a dictionary with class label as the key and probability as value.
    return dict(zip(learn.dls.vocab, probabilities.tolist()))

hello_world = gr.Interface(fn=hello, inputs='text', outputs='text')
bye_world = gr.Interface(fn=bye, inputs='text', outputs='text')
cat_vs_dog_interface = gr.Interface(fn=cat_vs_dog, inputs='image', outputs='label')
fish_vs_face_interface = gr.Interface(fn=fish_vs_face, inputs='webcam', outputs='label')
demo = gr.TabbedInterface([hello_world, bye_world, cat_vs_dog_interface, fish_vs_face_interface], ['Hello', 'Bye', 'Cat vs Dog', 'Fish vs Face'])


if __name__ == '__main__':
    demo.launch()