import gradio as gr from fastai.vision.all import * import pathlib import sys # Change pathlib's default path to PosixPath for compatibility if sys.platform != 'win32': pathlib.WindowsPath = pathlib.PosixPath # Load the model learn = load_learner('mushy_ubuntu.pkl') labels=learn.dls.vocab def predict(img): img = PILImage.create(img) pred,pred_idx,probs = learn.predict(img) return {labels[i]: float(probs[i]) for i in range(len(labels))} title = "Magic Mushroom Identifier" description = "Do not put anything in your mouth based on the results of this app. Upload your image to have it classify one of five psilocybe mushroom species. The magic mushroom species it can detect are psilocybe cubensis, psilocybe cyanescens, psilocybe tampanensis, psilocybe ovoideocystidiata, psilocybe semilanceata. This app is for research purposes. Not to be used for illegal activites. -mom" examples=['examples/example1.jpg', 'examples/example2.jpg'] gr.Interface(fn=predict,inputs=gr.Image(type="filepath"),outputs=gr.Label(num_top_classes=3),title=title,description=description,examples=examples).launch(share=True)