jurgenbollo commited on
Commit
205874f
·
verified ·
1 Parent(s): e70fe77

Update src/streamlit_app1.py

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