amirkhanbloch commited on
Commit
5f9c702
·
verified ·
1 Parent(s): 28b72fb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import cv2
3
+ import numpy as np
4
+ import tensorflow as tf
5
+ from tensorflow.keras.models import load_model
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}")