Files changed (1) hide show
  1. app.py +32 -17
app.py CHANGED
@@ -6,49 +6,64 @@ from tensorflow.keras.models import load_model
6
  from tensorflow.keras.preprocessing.image import img_to_array
7
  from PIL import Image
8
 
9
- # Charger le modèle pré-entraîné
10
  model = load_model('plant_diseases.h5')
11
 
12
- # Classes de labels (remplacez par vos propres classes)
13
- 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']
14
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  def preprocess_image(image, image_size=(224, 224)):
17
- # Convertir l'image en niveaux de gris
18
  image = np.array(image.convert('L'))
19
- # Redimensionner l'image
20
  image = cv2.resize(image, image_size)
21
-
22
- # Redimensionner pour le modèle
23
  image = img_to_array(image)
24
  image /= 255.0
25
  image = np.expand_dims(image, axis=0)
26
  return image
27
 
 
28
  st.title("Classification des Maladies des Plantes")
29
  st.write("Téléchargez une image de plante pour la classification")
30
 
31
  uploaded_file = st.file_uploader("Choisissez une image...", type=["jpg", "jpeg", "png"])
32
 
33
  if uploaded_file is not None:
34
- # Afficher l'image téléchargée
35
  image = Image.open(uploaded_file)
36
  st.image(image, caption='Image téléchargée', use_column_width=True)
37
-
38
  st.write("Classification en cours...")
39
-
40
- # Prétraiter l'image
41
  processed_image = preprocess_image(image)
42
-
43
- # Faire la prédiction
44
  predictions = model.predict(processed_image)
45
  probabilities = predictions[0]
46
-
47
- # Afficher les probabilités de chaque classe
48
  for i, label in enumerate(class_labels):
49
  if probabilities[i] > 0:
50
  st.write(f"{label}: {probabilities[i]:.2f}")
51
 
52
- # Afficher le résultat de la classe prédite
53
  predicted_class = class_labels[np.argmax(probabilities)]
54
  st.write(f"Classe prédite: {predicted_class}")
 
6
  from tensorflow.keras.preprocessing.image import img_to_array
7
  from PIL import Image
8
 
9
+ # Load the pre-trained model
10
  model = load_model('plant_diseases.h5')
11
 
12
+ # Class labels (replace with your own classes)
13
+ class_labels = [
14
+ 'Piment: Bacterial_spot',
15
+ 'Piment: healthy',
16
+ 'Pomme de terre: Early_blight',
17
+ 'Pomme de terre: Late_blight',
18
+ 'Pomme de terre: Healthy',
19
+ 'Tomate: Bacterial Spot',
20
+ 'Tomate: Early Blight',
21
+ 'Tomate: Late Blight',
22
+ 'Tomate: Leaf mold',
23
+ 'Tomate: Septoria leaf spot',
24
+ 'Tomate: Spider mites',
25
+ 'Tomate: Spot',
26
+ 'Tomate: Yellow Leaf Curl',
27
+ 'Tomate: Virus Mosaïque',
28
+ 'Tomate: Healthy'
29
+ ]
30
 
31
  def preprocess_image(image, image_size=(224, 224)):
32
+ # Convert image to grayscale
33
  image = np.array(image.convert('L'))
34
+ # Resize image
35
  image = cv2.resize(image, image_size)
36
+ # Prepare image for the model
 
37
  image = img_to_array(image)
38
  image /= 255.0
39
  image = np.expand_dims(image, axis=0)
40
  return image
41
 
42
+ # Streamlit app setup
43
  st.title("Classification des Maladies des Plantes")
44
  st.write("Téléchargez une image de plante pour la classification")
45
 
46
  uploaded_file = st.file_uploader("Choisissez une image...", type=["jpg", "jpeg", "png"])
47
 
48
  if uploaded_file is not None:
49
+ # Display the uploaded image
50
  image = Image.open(uploaded_file)
51
  st.image(image, caption='Image téléchargée', use_column_width=True)
52
+
53
  st.write("Classification en cours...")
54
+
55
+ # Preprocess the image
56
  processed_image = preprocess_image(image)
57
+
58
+ # Make predictions
59
  predictions = model.predict(processed_image)
60
  probabilities = predictions[0]
61
+
62
+ # Display probabilities for each class
63
  for i, label in enumerate(class_labels):
64
  if probabilities[i] > 0:
65
  st.write(f"{label}: {probabilities[i]:.2f}")
66
 
67
+ # Show predicted class
68
  predicted_class = class_labels[np.argmax(probabilities)]
69
  st.write(f"Classe prédite: {predicted_class}")