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 | |
# Load the pre-trained model | |
model = load_model('plant_diseases.h5') | |
# Class labels (replace with your own 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: Spider mites', | |
'Tomate: Spot', | |
'Tomate: Yellow Leaf Curl', | |
'Tomate: Virus Mosaïque', | |
'Tomate: Healthy' | |
] | |
def preprocess_image(image, image_size=(224, 224)): | |
# Convert image to grayscale | |
image = np.array(image.convert('L')) | |
# Resize image | |
image = cv2.resize(image, image_size) | |
# Prepare image for the model | |
image = img_to_array(image) | |
image /= 255.0 | |
image = np.expand_dims(image, axis=0) | |
return image | |
# Streamlit app setup | |
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: | |
# Display the uploaded image | |
image = Image.open(uploaded_file) | |
st.image(image, caption='Image téléchargée', use_column_width=True) | |
st.write("Classification en cours...") | |
# Preprocess the image | |
processed_image = preprocess_image(image) | |
# Make predictions | |
predictions = model.predict(processed_image) | |
probabilities = predictions[0] | |
# Display probabilities for each class | |
for i, label in enumerate(class_labels): | |
if probabilities[i] > 0: | |
st.write(f"{label}: {probabilities[i]:.2f}") | |
# Show predicted class | |
predicted_class = class_labels[np.argmax(probabilities)] | |
st.write(f"Classe prédite: {predicted_class}") | |