Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# Charger le modèle pré-entraîné
|
10 |
+
model = load_model('plant_disease.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 = np.expand_dims(image, axis=0)
|
25 |
+
return image
|
26 |
+
|
27 |
+
st.title("Classification des Maladies des Plantes")
|
28 |
+
st.write("Téléchargez une image de plante pour la classification")
|
29 |
+
|
30 |
+
uploaded_file = st.file_uploader("Choisissez une image...", type=["jpg", "jpeg", "png"])
|
31 |
+
|
32 |
+
if uploaded_file is not None:
|
33 |
+
# Afficher l'image téléchargée
|
34 |
+
image = Image.open(uploaded_file)
|
35 |
+
st.image(image, caption='Image téléchargée', use_column_width=True)
|
36 |
+
|
37 |
+
st.write("Classification en cours...")
|
38 |
+
|
39 |
+
# Prétraiter l'image
|
40 |
+
processed_image = preprocess_image(image)
|
41 |
+
|
42 |
+
# Faire la prédiction
|
43 |
+
predictions = model.predict(processed_image)
|
44 |
+
probabilities = predictions[0]
|
45 |
+
|
46 |
+
# Afficher les probabilités de chaque classe
|
47 |
+
for i, label in enumerate(class_labels):
|
48 |
+
st.write(f"{label}: {probabilities[i]:.2f}")
|
49 |
+
|
50 |
+
# Afficher le résultat de la classe prédite
|
51 |
+
predicted_class = class_labels[np.argmax(probabilities)]
|
52 |
+
st.write(f"Classe prédite: {predicted_class}")
|