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