jurgenbollo commited on
Commit
2999e98
·
verified ·
1 Parent(s): b142f5e

Upload streamlit_app1.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app1.py +37 -0
src/streamlit_app1.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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}**")