Update src/streamlit_app1.py
Browse files- src/streamlit_app1.py +8 -8
src/streamlit_app1.py
CHANGED
|
@@ -3,18 +3,14 @@ import tensorflow as tf
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
-
# Chargement des modèles
|
| 7 |
-
|
| 8 |
model_infect = tf.keras.models.load_model("src/exo1.keras")
|
| 9 |
model_animals = tf.keras.models.load_model("src/exo2.keras")
|
| 10 |
|
| 11 |
-
# Fonction de prédiction
|
| 12 |
def predict(model, img_array, classes):
|
| 13 |
prediction = model.predict(img_array)
|
| 14 |
index = np.argmax(prediction)
|
| 15 |
return classes[index], prediction[0][index]
|
| 16 |
|
| 17 |
-
# Interface utilisateur
|
| 18 |
st.title("🧠 Classification d’images")
|
| 19 |
|
| 20 |
option = st.selectbox("Choisissez le modèle :", ("Infecté / Non Infecté", "Chat / Chien"))
|
|
@@ -22,13 +18,17 @@ option = st.selectbox("Choisissez le modèle :", ("Infecté / Non Infecté", "Ch
|
|
| 22 |
uploaded_file = st.file_uploader("Uploader une image", type=["jpg", "png", "jpeg"])
|
| 23 |
|
| 24 |
if uploaded_file:
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
st.image(image, caption="Image chargée", use_column_width=True)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
image = image.resize((128, 128)) # à adapter selon votre modèle
|
| 30 |
img_array = np.array(image) / 255.0
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
if option == "Infecté / Non Infecté":
|
| 34 |
label, confidence = predict(model_infect, img_array, ["Non Infecté", "Infecté"])
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
import numpy as np
|
| 5 |
|
|
|
|
|
|
|
| 6 |
model_infect = tf.keras.models.load_model("src/exo1.keras")
|
| 7 |
model_animals = tf.keras.models.load_model("src/exo2.keras")
|
| 8 |
|
|
|
|
| 9 |
def predict(model, img_array, classes):
|
| 10 |
prediction = model.predict(img_array)
|
| 11 |
index = np.argmax(prediction)
|
| 12 |
return classes[index], prediction[0][index]
|
| 13 |
|
|
|
|
| 14 |
st.title("🧠 Classification d’images")
|
| 15 |
|
| 16 |
option = st.selectbox("Choisissez le modèle :", ("Infecté / Non Infecté", "Chat / Chien"))
|
|
|
|
| 18 |
uploaded_file = st.file_uploader("Uploader une image", type=["jpg", "png", "jpeg"])
|
| 19 |
|
| 20 |
if uploaded_file:
|
| 21 |
+
st.write("Image uploadée, traitement en cours...") # debug
|
| 22 |
+
|
| 23 |
+
image = Image.open(uploaded_file).convert("RGB")
|
| 24 |
st.image(image, caption="Image chargée", use_column_width=True)
|
| 25 |
|
| 26 |
+
image = image.resize((128, 128))
|
|
|
|
| 27 |
img_array = np.array(image) / 255.0
|
| 28 |
+
if len(img_array.shape) == 3:
|
| 29 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 30 |
+
|
| 31 |
+
st.write("Données prétraitées, lancement prédiction...") # debug
|
| 32 |
|
| 33 |
if option == "Infecté / Non Infecté":
|
| 34 |
label, confidence = predict(model_infect, img_array, ["Non Infecté", "Infecté"])
|