File size: 1,645 Bytes
0af5b29 76ca3a0 b836ce7 76ca3a0 b836ce7 2abbe16 9433a78 b836ce7 76ca3a0 0af5b29 b836ce7 76ca3a0 0af5b29 b836ce7 76ca3a0 0af5b29 bb1cd8b b836ce7 bb1cd8b b836ce7 0af5b29 b836ce7 0af5b29 b836ce7 76ca3a0 8e7d5e1 76ca3a0 4526676 76ca3a0 b836ce7 c8a2164 |
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import os
import gradio as gr
import tensorflow as tf
import numpy as np
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
# Loading saved model
model = tf.keras.models.load_model('plant_disease_classifier.h5')
def predict(input_image):
try:
# Preprocessing
input_image = tf.convert_to_tensor(input_image)
input_image = tf.image.resize(input_image, [256, 256])
input_image = tf.expand_dims(input_image, 0) / 255.0
predictions = model.predict(input_image)
labels = ['Healthy', 'Powdery', 'Rust']
class_idx = np.argmax(predictions)
class_label = labels[class_idx]
confidence = np.round(predictions[0][class_idx] * 100, 3)
return f"Predicted Class: {class_label}. Confidence Score: {confidence}%"
except Exception as e:
return f"An error occurred: {e}"
examples = ["Healthy.png", "Powdery.png", "Rust.png"]
iface = gr.Interface(
fn=predict,
inputs=gr.Image(),
outputs="text",
title="🌿 Plant Disease Detection",
description='<br> This is a specialized Image Classification model engineered to identify the health status of plants, specifically detecting conditions of Powdery Mildew or Rust. <br> \
This model is based on a Convolutional Neural Network that I have trained, evaluated, and validated on my Kaggle Notebook: <a href="https://www.kaggle.com/code/lusfernandotorres/convolutional-neural-network-from-scratch">🧠 Convolutional Neural Network From Scratch</a>. <br> \
<br> Upload a photo of a plant to see how the model classifies its status!',
examples=examples
)
iface.launch(share=True)
|