File size: 1,480 Bytes
7d1eab1
7ba6ad7
7d1eab1
e7e82d6
f157f75
e7e82d6
 
 
7d1eab1
07f6228
f9573e3
7d1eab1
 
 
 
 
 
 
 
 
 
44a9b3a
 
 
 
7d1eab1
 
f157f75
7d1eab1
610d5e0
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
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)