Spaces:
Sleeping
Sleeping
import streamlit as st | |
import cv2 | |
import numpy as np | |
import tensorflow as tf | |
from tensorflow.keras.models import load_model | |
from tensorflow.keras.preprocessing.image import img_to_array | |
from PIL import Image | |
# Charger le modèle pré-entraîné | |
model = load_model('plant_diseases.h5') | |
# Classes de labels (remplacez par vos propres classes) | |
class_labels = ['Piment: Bacterial_spot', | |
'Piment: healthy', | |
'Pomme de terre: Early_blight', | |
'Pomme de terre: Late_blight', | |
'Pomme de terre: Healthy', 'Tomate: Bacterial Spot', 'Tomate: Early Blight', 'Tomate: Late Blight', 'Tomate: Leaf mold', 'Tomate: Septoria leaf spot', 'Tomate: Siper mites', 'Tomate: Spot', "Tomate: Yellow Leaf Curl", 'Tomate: Virus Mosaïque', 'Tomate: Healthy'] | |
def preprocess_image(image, image_size=(224, 224)): | |
# Convertir l'image en niveaux de gris | |
image = np.array(image.convert('L')) | |
# Redimensionner l'image | |
image = cv2.resize(image, image_size) | |
# Redimensionner pour le modèle | |
image = img_to_array(image) | |
image /= 255.0 | |
image = np.expand_dims(image, axis=0) | |
return image | |
st.title("Classification des Maladies des Plantes") | |
st.write("Téléchargez une image de plante pour la classification") | |
uploaded_file = st.file_uploader("Choisissez une image...", type=["jpg", "jpeg", "png"]) | |
if uploaded_file is not None: | |
# Afficher l'image téléchargée | |
image = Image.open(uploaded_file) | |
st.image(image, caption='Image téléchargée', use_column_width=True) | |
st.write("Classification en cours...") | |
# Prétraiter l'image | |
processed_image = preprocess_image(image) | |
# Faire la prédiction | |
predictions = model.predict(processed_image) | |
probabilities = predictions[0] | |
# Afficher les probabilités de chaque classe | |
for i, label in enumerate(class_labels): | |
if probabilities[i] > 0: | |
st.write(f"{label}: {probabilities[i]:.2f}") | |
# Afficher le résultat de la classe prédite | |
predicted_class = class_labels[np.argmax(probabilities)] | |
st.write(f"Classe prédite: {predicted_class}") | |