Update src/streamlit_app1.py
Browse files12345678910111213141516171819202122232425262728293031323334353637import streamlit as stimport tensorflow as tffrom PIL import Imageimport numpy as np# Chargement des modèlesmodel_infect = tf.keras.models.load_model("exo1.keras")model_animals = tf.keras.models.load_model("exo2.keras")# Fonction de prédictiondef predict(model, img_array, classes):prediction = model.predict(img_array)index = np.argmax(prediction)return classes[index], prediction[0][index]# Interface utilisateurst.title("🧠 Classification d’images")option = st.selectbox("Choisissez le modèle :", ("Infecté / Non Infecté", "Chat / Chien"))uploaded_file = st.file_uploader("Uploader une image", type=["jpg", "png", "jpeg"])if uploaded_file:image = Image.open(uploaded_file)st.image(image, caption="Image chargée", use_column_width=True)# Prétraitementimage = image.resize((224, 224)) # à adapter selon votre modèleimg_array = np.array(image) / 255.0img_array = np.expand_dims(img_array, axis=0)if option == "Infecté / Non Infecté":label, confidence = predict(model_infect, img_array, ["Non Infecté", "Infecté"])else:label, confidence = predict(model_animals, img_array, ["Chat", "Chien"])st.success(f"Classe prédite : **{label}** avec une confiance de **{confidence:.2f}**")123456789101112131415161718192021222324252627282930313233343536import streamlit as stfrom PIL import Imageimport numpy as np# Chargement des modèlesmodel_infect = tf.keras.models.load_model("exo1.keras")model_animals = tf.keras.models.load_model("exo2.keras")# Fonction de prédictiondef predict(model, img_array, classes):prediction = model.predict(img_array)index = np.argmax(prediction)return classes[index], prediction[0][index]# Interface utilisateurst.title("🧠 Classification d’images")option = st.selectbox("Choisissez le modèle :", ("Infecté / Non Infecté", "Chat / Chien"))uploaded_file = st.file_uploader("Uploader une image", type=["jpg", "png", "jpeg"])if uploaded_file:image = Image.open(uploaded_file)st.image(image, caption="Image chargée", use_column_width=True)# Prétraitementimage = image.resize((224, 224)) # à adapter selon votre modèleimg_array = np.array(image) / 255.0img_array = np.expand_dims(img_array, axis=0)if option == "Infecté / Non Infecté":label, confidence = predict(model_infect, img_array, ["Non Infecté", "Infecté"])else:label, confidence = predict(model_animals, img_array, ["Chat", "Chien"])st.success(f"Classe prédite : **{label}** avec une confiance de **{confidence:.2f}**")
src/streamlit_app1.py+36-37