File size: 2,076 Bytes
205874f
4fed44e
205874f
 
 
501b63d
 
 
 
 
25b8bab
501b63d
 
 
 
 
205874f
 
 
501b63d
205874f
501b63d
25b8bab
205874f
25b8bab
205874f
 
25b8bab
501b63d
205874f
 
501b63d
 
39ad34a
501b63d
25b8bab
501b63d
 
b6e56ec
25b8bab
 
 
b6e56ec
25b8bab
 
 
 
 
 
501b63d
 
25b8bab
501b63d
 
25b8bab
501b63d
 
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
import streamlit as st
import tensorflow as tf
from PIL import Image
import numpy as np

# Chargement des modèles avec message
with st.spinner("Chargement des modèles..."):
    try:
        model_infect = tf.keras.models.load_model("src/exo1.keras")
        model_animals = tf.keras.models.load_model("src/exo2.keras")
        st.success("Modèles chargés avec succès ")
    except Exception as e:
        st.error(f"Erreur lors du chargement des modèles : {e}")
        st.stop()

# Fonction de prédiction
def predict(model, img_array, classes):
    prediction = model.predict(img_array)
    index = np.argmax(prediction)
    return classes[index], float(prediction[0][index])

# Interface utilisateur
st.title("Classification d’images")

# Choix du modèle
option = st.selectbox("Choisissez le modèle :", ("Infecté / Non Infecté", "Chat / Chien"))

# Upload d'image
uploaded_file = st.file_uploader("Uploader une image", type=["jpg", "jpeg", "png"])

if uploaded_file:
    try:
        image = Image.open(uploaded_file).convert("RGB")
        st.image(image, caption="Image chargée", use_container_width=True)

        # Bouton pour déclencher la prédiction
        if st.button("Prédire"):
            with st.spinner("Prétraitement de l’image..."):
                if option == "Infecté / Non Infecté":
                    image = image.resize((50, 50))
                    model = model_infect
                    classes = ["Non Infecté", "Infecté"]
                else:
                    image = image.resize((128, 128))
                    model = model_animals
                    classes = ["Chat", "Chien"]

                img_array = np.array(image) / 255.0
                img_array = np.expand_dims(img_array, axis=0)

            with st.spinner("Prédiction en cours..."):
                label, confidence = predict(model, img_array, classes)

            st.success(f"✅ Classe prédite : **{label}** avec une confiance de **{confidence:.2f}**")

    except Exception as e:
        st.error(f"❌ Erreur lors du traitement : {e}")