File size: 2,080 Bytes
a011f05
 
 
 
 
 
 
 
eed1162
ef2fac7
a011f05
eed1162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a011f05
 
eed1162
a011f05
eed1162
a011f05
eed1162
a011f05
09a3a38
a011f05
 
 
eed1162
a011f05
 
 
 
 
 
eed1162
a011f05
 
eed1162
a011f05
eed1162
 
a011f05
eed1162
 
a011f05
 
eed1162
 
a011f05
214e701
 
a011f05
eed1162
a011f05
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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}")