Spaces:
Runtime error
Runtime error
| from fastai.vision.all import * | |
| import gradio as gr | |
| import skimage | |
| import pathlib | |
| import os | |
| plt = platform.system() | |
| if plt == 'Linux': pathlib.WindowsPath = pathlib.PosixPath | |
| learn = load_learner('model.pkl') | |
| examples = [str(x) for x in get_image_files('images')] | |
| labels = learn.dls.vocab | |
| def predict(img): | |
| img = PILImage.create(img) | |
| pred,pred_idx,probs = learn.predict(img) | |
| val, idx = probs.topk(3) | |
| pred_labels = labels[idx] | |
| return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
| title = "Northern EU Mushroom Classifier" | |
| description = "<p style='text-align: center; font-size:16px'>A North EU mushroom image classifier trained on a kaggle dataset with fastai. " \ | |
| +"The dataset consist of 9 different folders that contains from 300 to 1500 selected images of mushrooms genuses. " \ | |
| +"</br>Possible genuses are: Agaricus, Amanita, Boletus, Cortinarius, Entoloma, Hygrocybe, Lactarius, Russula and Suillus. </p>" | |
| article="<p style='text-align: center; font-size:16px'><a href='https://www.kaggle.com/datasets/maysee/mushrooms-classification-common-genuss-images' target='_blank'>Data Source</a></h4>" | |
| interpretation='default' | |
| enable_queue=True | |
| inputs = gr.Image(shape=(224, 224)) | |
| gr.Interface(fn=predict, inputs=inputs, outputs=gr.Label(num_top_classes=3), title=title, description=description, article=article, interpretation=interpretation, examples=examples).launch(inline=False, enable_queue=enable_queue) |