|
|
import gradio as gr |
|
|
import tensorflow as tf |
|
|
import numpy as np |
|
|
import cv2 |
|
|
|
|
|
|
|
|
model = tf.keras.models.load_model("tomato_disease_mobilenetv2_25Epc.h5") |
|
|
|
|
|
|
|
|
classes = ["Tomato___Bacterial_spot", "Tomato___Early_blight", "Tomato___Late_blight", |
|
|
"Tomato___Leaf_Mold", "Tomato___Septoria_leaf_spot", "Tomato___Spider_mites Two-spotted_spider_mite", |
|
|
"Tomato___Target_Spot", "Tomato___Tomato_Yellow_Leaf_Curl_Virus", |
|
|
"Tomato___Tomato_mosaic_virus", "Tomato___healthy"] |
|
|
|
|
|
|
|
|
def predict_image(image): |
|
|
|
|
|
img = cv2.resize(image, (224, 224)) |
|
|
img = img / 255.0 |
|
|
img = np.expand_dims(img, axis=0) |
|
|
|
|
|
|
|
|
prediction = model.predict(img) |
|
|
predicted_class = np.argmax(prediction) |
|
|
confidence = np.max(prediction) * 100 |
|
|
|
|
|
return f"🌱 Résultat : {classes[predicted_class]} \n🔍 Confiance : {confidence:.2f}%" |
|
|
|
|
|
|
|
|
interface = gr.Interface( |
|
|
fn=predict_image, |
|
|
inputs=gr.Image(type="numpy"), |
|
|
outputs="text", |
|
|
title="Détection des Maladies des Plantes 🌿", |
|
|
description="📸 Télécharge une image d'une feuille de plante pour obtenir une analyse IA." |
|
|
) |
|
|
|
|
|
|
|
|
interface.launch() |
|
|
|