Update src/streamlit_app1.py
Browse files- src/streamlit_app1.py +36 -37
src/streamlit_app1.py
CHANGED
|
@@ -1,37 +1,36 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
index
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
image =
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
img_array = np.
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
st.success(f"Classe prédite : **{label}** avec une confiance de **{confidence:.2f}**")
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from PIL import Image
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Chargement des modèles
|
| 6 |
+
model_infect = tf.keras.models.load_model("exo1.keras")
|
| 7 |
+
model_animals = tf.keras.models.load_model("exo2.keras")
|
| 8 |
+
|
| 9 |
+
# Fonction de prédiction
|
| 10 |
+
def predict(model, img_array, classes):
|
| 11 |
+
prediction = model.predict(img_array)
|
| 12 |
+
index = np.argmax(prediction)
|
| 13 |
+
return classes[index], prediction[0][index]
|
| 14 |
+
|
| 15 |
+
# Interface utilisateur
|
| 16 |
+
st.title("🧠 Classification d’images")
|
| 17 |
+
|
| 18 |
+
option = st.selectbox("Choisissez le modèle :", ("Infecté / Non Infecté", "Chat / Chien"))
|
| 19 |
+
|
| 20 |
+
uploaded_file = st.file_uploader("Uploader une image", type=["jpg", "png", "jpeg"])
|
| 21 |
+
|
| 22 |
+
if uploaded_file:
|
| 23 |
+
image = Image.open(uploaded_file)
|
| 24 |
+
st.image(image, caption="Image chargée", use_column_width=True)
|
| 25 |
+
|
| 26 |
+
# Prétraitement
|
| 27 |
+
image = image.resize((224, 224)) # à adapter selon votre modèle
|
| 28 |
+
img_array = np.array(image) / 255.0
|
| 29 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 30 |
+
|
| 31 |
+
if option == "Infecté / Non Infecté":
|
| 32 |
+
label, confidence = predict(model_infect, img_array, ["Non Infecté", "Infecté"])
|
| 33 |
+
else:
|
| 34 |
+
label, confidence = predict(model_animals, img_array, ["Chat", "Chien"])
|
| 35 |
+
|
| 36 |
+
st.success(f"Classe prédite : **{label}** avec une confiance de **{confidence:.2f}**")
|
|
|