Spaces:
Sleeping
Sleeping
File size: 928 Bytes
5079bcf 48998aa 5079bcf defc3c5 48998aa 4e654b8 48998aa 58dd01a c546c28 48998aa a999041 48998aa f221625 48998aa 5079bcf 2ac4ff5 efc174b | 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 | import gradio as gr
from fastai.vision.all import *
## Use this commented part to execute this file in windows ##
# import pathlib
# temp = pathlib.PosixPath
# pathlib.PosixPath = pathlib.WindowsPath
model = load_learner('models/ball-classifier-v5.pkl')
ball_labels = [
'Baseball',
'Basketball',
'Billiards',
'Bowling',
'Cricket',
'Football',
'Golf',
'Rugby',
'Tennis',
'Volleyball'
]
image = gr.inputs.Image()
label = gr.outputs.Label(num_top_classes=5)
example = [
'test_images/img0001.jpeg',
'test_images/img0002.jpeg',
'test_images/img0003.jpeg',
'test_images/img0004.jpeg',
'test_images/img0005.jpeg'
]
def recognize_image(image):
_, _, probs = model.predict(image)
return dict(zip(ball_labels, map(float, probs)))
iface = gr.Interface(fn=recognize_image, inputs=image, outputs=label, examples= example)
iface.launch(inline=False, share= True) |