AlphaGric / app.py
Abder004's picture
Update app.py
cd230a0 verified
import gradio as gr
import tensorflow as tf
import numpy as np
import cv2
# Charger le modèle (Remplace par ton modèle)
model = tf.keras.models.load_model("tomato_disease_mobilenetv2_25Epc.h5")
# Classes des maladies (modifie selon ton dataset)
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"]
# Fonction de prédiction avec score de confiance
def predict_image(image):
# Convertir en format compatible avec le modèle
img = cv2.resize(image, (224, 224)) # Adapter à la taille du modèle
img = img / 255.0 # Normalisation
img = np.expand_dims(img, axis=0)
# Faire la prédiction
prediction = model.predict(img)
predicted_class = np.argmax(prediction)
confidence = np.max(prediction) * 100 # Score de confiance en %
return f"🌱 Résultat : {classes[predicted_class]} \n🔍 Confiance : {confidence:.2f}%"
# Interface Gradio
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."
)
# Lancer l’application
interface.launch()