from fastai.vision.all import load_learner import gradio as gr import pathlib temp=pathlib.PosixPath pathlib.PosixPath=pathlib.WindowsPath snake_labels = ( "Monocled cobra", "Egyptian cobra", "Black-necked spitting cobra", "Samar cobra", "Red spitting cobra", "Javan spitting cobra", "Spectacled cobra", "Russell's viper", "Horned vipers", "Bush vipers", "Eyelash viper", "Saw-scaled vipers", "Banded krait", "Black mamba", "Inland taipan", "Eastern brown snake", "Rattle snake", "King cobra" ) model = load_learner('models/snake-recognizer-v0.pkl') def recognize_snake(photo): pred, idx, probs = model.predict(photo) return dict(zip(snake_labels, map(float, probs))) image = gr.inputs.Image(shape=(192,192)) label = gr.outputs.Label() examples = [ 'test data/viper-2.jpg', 'test data/shutterstock_2062214282-edited-1-scaled.jpg', 'test data/download (3).jpg', 'test data/download (4).jpg', 'test data/Naja_sputatrix.jpg', 'test data/download (6).jpg', 'test data/download.jpg' ] iface = gr.Interface(fn=recognize_snake, inputs=image, outputs=label, examples=examples) iface.launch(inline=False,share=True)