Spaces:
Sleeping
Sleeping
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() | |