import gradio as gr import matplotlib.pyplot as plt import numpy as np import PIL import tensorflow as tf model = tf.keras.models.load_model('model.h5') class_name_list = ['Edible', 'Inedible', 'Poisonous'] def predict_image(img): # Reescalamos la imagen en 4 dimensiones img_4d = img.reshape(-1,224,224,3) # Predicción del modelo prediction = model.predict(img_4d)[0] # Diccionario con todas las clases y las probabilidades correspondientes return {class_name_list[i]: float(prediction[i]) for i in range(3)} image = gr.inputs.Image(shape=(224,224)) label = gr.outputs.Label(num_top_classes=3) title = 'Mushroom Edibility Classifier' description = 'Get the edibility classification for the input mushroom image' examples=[['app_interface/Boletus edulis 15 wf.jpg'], ['app_interface/Cantharelluscibarius5 mw.jpg'], ['app_interface/Agaricus augustus 2 wf.jpg'], ['app_interface/Coprinellus micaceus 8 wf.jpg'], ['app_interface/Clavulinopsis fusiformis 2 fp.jpg'], ['app_interface/Amanita torrendii 8 fp.jpg'], ['app_interface/Russula sanguinea 5 fp.jpg'], ['app_interface/Caloceraviscosa1 mw.jpg'], ['app_interface/Amanita muscaria 1 wf.jpg'], ['app_interface/Amanita pantherina 11 wf.jpg'], ['app_interface/Lactarius torminosus 6 fp.jpg'], ['app_interface/Amanitaphalloides1 mw.jpg']] thumbnail = 'app_interface/thumbnail.png' article = '''

The Mushroom Edibility Classifier is an MVP for CNN multiclass classification model.
It has been trained after gathering 5500 mushroom images through Web Scraping techniques from the following web sites:


- Mushroom World
- Wild Food UK
- Fungipedia


Note: model created solely and exclusively for academic purposes. The results provided by the model should never be considered definitive as the accuracy of the model is not guaranteed.


MODEL METRICS:

precision recall f1-score support
Edible 0.61 0.70 0.65 481
Inedible 0.67 0.69 0.68 439
Poisonous 0.52 0.28 0.36 192
Global Accuracy 0.63 1112
Macro Average 0.60 0.56 0.57 1112
Weighted Average 0.62 0.63 0.61 1112

Author: Íñigo Sarralde Alzórriz

''' iface = gr.Interface(fn=predict_image, inputs=image, outputs=label, interpretation='default', title = title, description = description, theme = 'darkpeach', examples = examples, thumbnail = thumbnail, article = article, allow_flagging = False, allow_screenshot = False, ) iface.launch()