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|
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
from urllib.request import urlopen
|
4 |
+
from sklearn.preprocessing import StandardScaler
|
5 |
+
from sklearn.metrics.pairwise import cosine_similarity
|
6 |
+
from sklearn.metrics.pairwise import euclidean_distances
|
7 |
+
import plotly.express as px
|
8 |
+
import plotly.graph_objects as go
|
9 |
+
from streamlit_option_menu import option_menu
|
10 |
+
import json
|
11 |
+
import requests
|
12 |
+
from streamlit_lottie import st_lottie
|
13 |
+
import pydeck as pdk
|
14 |
+
import snowflake.connector
|
15 |
+
import numpy as np
|
16 |
+
from keras.preprocessing import image
|
17 |
+
from keras.models import load_model
|
18 |
+
import streamlit as st
|
19 |
+
import tensorflow as tf
|
20 |
+
import numpy as np
|
21 |
+
|
22 |
+
# Layout
|
23 |
+
st.set_page_config(
|
24 |
+
page_title="PulmoCare",
|
25 |
+
layout="wide",
|
26 |
+
initial_sidebar_state="expanded")
|
27 |
+
|
28 |
+
# Data Pull and Functions
|
29 |
+
st.markdown("""
|
30 |
+
<style>
|
31 |
+
.big-font {
|
32 |
+
font-size:80px !important;
|
33 |
+
}
|
34 |
+
</style>
|
35 |
+
""", unsafe_allow_html=True)
|
36 |
+
|
37 |
+
|
38 |
+
@st.cache_data
|
39 |
+
def load_lottiefile(filepath: str):
|
40 |
+
with open(filepath, "r") as f:
|
41 |
+
return json.load(f)
|
42 |
+
|
43 |
+
|
44 |
+
@st.cache_data
|
45 |
+
def pull_clean():
|
46 |
+
master_zip = pd.read_csv('MASTER_ZIP.csv', dtype={'ZCTA5': str})
|
47 |
+
master_city = pd.read_csv('MASTER_CITY.csv', dtype={'ZCTA5': str})
|
48 |
+
return master_zip, master_city
|
49 |
+
|
50 |
+
|
51 |
+
def clear_image():
|
52 |
+
st.session_state.image = None
|
53 |
+
|
54 |
+
|
55 |
+
def resize_image(img, img_size):
|
56 |
+
return img.resize(img_size)
|
57 |
+
|
58 |
+
|
59 |
+
@st.cache_data
|
60 |
+
def classifier_image(image_path):
|
61 |
+
# Redimensionner l'image
|
62 |
+
img = resize_image(image_path, (224, 224))
|
63 |
+
|
64 |
+
# Convertir l'image en tableau numpy
|
65 |
+
img_array = image.img_to_array(img)
|
66 |
+
# Ajouter une dimension pour représenter le batch (1 image)
|
67 |
+
img_array = np.expand_dims(img_array, axis=0)
|
68 |
+
# Normaliser l'image
|
69 |
+
img_array = img_array / 255.0
|
70 |
+
|
71 |
+
# Charger le modèle depuis le fichier .h5
|
72 |
+
model = load_model("keras_model.h5")
|
73 |
+
|
74 |
+
# Effectuer la prédiction
|
75 |
+
predictions = model.predict(img_array)
|
76 |
+
|
77 |
+
# Interpréter la prédiction
|
78 |
+
class_labels = [ 'Taro', 'koki', 'Couscous_gombo' ,'Ero', 'Ndole', 'Nkui', 'Okok', 'riz','riz_sauté']
|
79 |
+
results = {class_labels[i]: float(predictions[0][i]*100) for i in range(4)}
|
80 |
+
# for i, class_label in enumerate(class_labels):
|
81 |
+
# results.append((class_label, predictions[0][i] * 100))
|
82 |
+
|
83 |
+
return results
|
84 |
+
|
85 |
+
|
86 |
+
# Options Menu
|
87 |
+
with st.sidebar:
|
88 |
+
selected = option_menu('Camfood', ["Acceuil", 'Documention', 'A propos'],
|
89 |
+
icons=['play-btn', "bi-file-earmark-bar-graph-fill", 'info-circle'], menu_icon='intersect', default_index=0)
|
90 |
+
|
91 |
+
|
92 |
+
# Intro Page
|
93 |
+
if selected == "Acceuil":
|
94 |
+
# Header
|
95 |
+
|
96 |
+
st.markdown(
|
97 |
+
"<h1 style='color:#077485'>Bienvenue sur Camfood</h1>", unsafe_allow_html=True)
|
98 |
+
st.markdown(
|
99 |
+
"<i><h5 style='color:#077485; font-weight:lighter'>Pour l'instant l'application est juste encore en test. Elle a été utilisé juste pour reconnaitre 8 plats du Cameroun </h5></i>",
|
100 |
+
unsafe_allow_html=True
|
101 |
+
)
|
102 |
+
|
103 |
+
st.divider()
|
104 |
+
# Use Cases
|
105 |
+
with st.container():
|
106 |
+
col1, col2 = st.columns(2)
|
107 |
+
with col1:
|
108 |
+
st.markdown(
|
109 |
+
"<h3 style='color:#077485'>Charger l'image à analyser ici !</h3>", unsafe_allow_html=True)
|
110 |
+
uploaded_file = st.file_uploader(
|
111 |
+
"", type=["jpg", "jpeg", "png"])
|
112 |
+
with st.container():
|
113 |
+
subcol1, subcol2, subcol3, subcol4 = st.columns(4)
|
114 |
+
with subcol1:
|
115 |
+
sub = st.button("Soumettre")
|
116 |
+
with subcol2:
|
117 |
+
if st.button("Néttoyer"):
|
118 |
+
clear_image()
|
119 |
+
if uploaded_file is not None:
|
120 |
+
# Display the uploaded image
|
121 |
+
custom_width = 500 # Modifier cette valeur selon vos besoins
|
122 |
+
st.image(uploaded_file, caption='Uploaded Image', width=500)
|
123 |
+
st.session_state.image = uploaded_file
|
124 |
+
with col2:
|
125 |
+
if sub:
|
126 |
+
|
127 |
+
if 'image' in st.session_state:
|
128 |
+
img = st.session_state.image
|
129 |
+
img = image.load_img(uploaded_file)
|
130 |
+
img = img.copy()
|
131 |
+
prediction_result = classifier_image(img)
|
132 |
+
st.markdown(
|
133 |
+
"<h4 style='color:#077485;margin-left:100px;margin-top:20px'>Resultats de l'analyse</h4>", unsafe_allow_html=True)
|
134 |
+
for label, percentage in prediction_result.items():
|
135 |
+
st.write(
|
136 |
+
f"<span style='font-weight:bold; margin-left:100px'>{label}:</span> <span style='color:#1f77b4'>{percentage:.2f}%</span>", unsafe_allow_html=True)
|
137 |
+
# st.write(
|
138 |
+
# f"> {label} -------------------------------------------------------- {percentage:.2f}%")
|
139 |
+
else:
|
140 |
+
st.write("S'il vous plait charger une image .")
|
141 |
+
|
142 |
+
with st.container():
|
143 |
+
col1, col2 = st.columns(2)
|
144 |
+
with col1:
|
145 |
+
st.markdown(
|
146 |
+
"<h1 style='color:#077485'>Cas d'utilisation</h1>", unsafe_allow_html=True)
|
147 |
+
|
148 |
+
st.markdown(
|
149 |
+
"""
|
150 |
+
|
151 |
+
- _**Detection** : reconnaitre quelques plats Camerounais ._
|
152 |
+
"""
|
153 |
+
)
|
154 |
+
|
155 |
+
st.divider()
|
156 |
+
|
157 |
+
# Tutorial Video
|
158 |
+
# st.header('Tutorial Video')
|
159 |
+
# video_file = open('Similo_Tutorial3_compressed.mp4', 'rb')
|
160 |
+
# video_bytes = video_file.read()
|
161 |
+
# st.video(video_bytes)
|
162 |
+
|
163 |
+
# Search Page
|
164 |
+
if selected == "Documention":
|
165 |
+
st.write("## Fait par Powo kamdem Arnold")
|
166 |
+
st.write("## Utilisation de l'Application CAMFOOD")
|
167 |
+
|
168 |
+
st.write("### 1. Exécution de l'Application")
|
169 |
+
st.write(" Pour utiliser Camfood, assurez-vous d'avoir le script Python contenant l'application Streamlit. Ensuite, exécutez la commande suivante dans votre terminal :")
|
170 |
+
st.code("streamlit run app.py")
|
171 |
+
|
172 |
+
st.write("### 2. Téléchargement de l'Image")
|
173 |
+
st.write(" Lorsque l'application est lancée, vous serez redirigé vers la page d'accueil de PulmoDetect.")
|
174 |
+
st.write(
|
175 |
+
" - Sur la page d'accueil, vous verrez une section permettant de télécharger une image.")
|
176 |
+
st.write(" - Cliquez sur le bouton 'Parcourir les fichiers' pour sélectionner l'image que vous souhaitez analyser.")
|
177 |
+
|
178 |
+
st.write("### 3. Analyse de l'Image")
|
179 |
+
st.write(" Après avoir téléchargé l'image, vous pouvez cliquer sur le bouton 'Submit' pour lancer l'analyse.")
|
180 |
+
st.write(" - Les résultats de l'analyse seront affichés sur la page, indiquant les pourcentages associés à chaque classe de maladie pulmonaire détectée.")
|
181 |
+
|
182 |
+
st.write("### 4. Nettoyage de l'Image")
|
183 |
+
st.write(" Si vous souhaitez supprimer l'image téléchargée et recommencer, vous pouvez cliquer sur le bouton 'Clear'. Cela effacera l'image chargée et vous pourrez télécharger une nouvelle image.")
|
184 |
+
|
185 |
+
st.write("## Remarque")
|
186 |
+
st.write("Assurez-vous d'avoir le modèle de détection des plats (.h5) dans le même répertoire que le script Python de l'application.")
|
187 |
+
|
188 |
+
# About Page
|
189 |
+
if selected == 'A propos':
|
190 |
+
st.write("## À PROPOS DU MODÈLE")
|
191 |
+
|
192 |
+
st.write("Ce modèle a été conçu pour la classification d'images de tumeurs cérébrales en utilisant le dataset masoudnickparvar/brain-tumor-mri-dataset de Kaggle.")
|
193 |
+
|
194 |
+
st.write("### PERFORMANCE DU MODÈLE")
|
195 |
+
st.write(
|
196 |
+
"Notre modèle EfficientNetB0 a atteint les performances suivantes lors des tests :")
|
197 |
+
st.write("- Précision: 98%")
|
198 |
+
st.write("- Rappel moyen: 98%")
|
199 |
+
st.write("- Score F1 moyen: 98%")
|
200 |
+
st.write("- Nombre total d'échantillons: 1311")
|
201 |
+
st.write("- Nombre d'erreurs trouvées: 23")
|
202 |
+
|
203 |
+
st.write("### ARCHITECTURE DU MODÈLE")
|
204 |
+
st.write(
|
205 |
+
"L'architecture de notre modèle EfficientNetB0 est configurée comme suit :")
|
206 |
+
st.write("- Paramètres totaux: 4,418,375 (16.85 MB)")
|
207 |
+
st.write("- Paramètres entraînables: 3,688,004 (1.41 MB)")
|
208 |
+
st.write("- Paramètres non-entraînables: 4,045,971 (15.45 MB)")
|
209 |
+
st.write("Le modèle comprend des couches convolutives personnalisées en plus des couches de pooling et une couche dense finale pour la classification en 4 classes.")
|
210 |
+
|
211 |
+
st.write("### DATASET UTILISÉ")
|
212 |
+
st.write("Les ensembles de données utilisés pour l'entraînement et la validation sont les suivants :")
|
213 |
+
st.write("- Fichiers d'entraînement: 5712 fichiers, répartis en 4 classes.")
|
214 |
+
st.write("- Fichiers de validation: 1311 fichiers, répartis en 4 classes.")
|
215 |
+
st.write("Note: Les données ont été préparées et réparties pour assurer une répartition équilibrée, ce qui est crucial pour l'entraînement d'un modèle de classification robuste.")
|
216 |
+
st.divider()
|
217 |
+
with st.container():
|
218 |
+
col1, col2 = st.columns(2)
|
219 |
+
with col1:
|
220 |
+
st.image("loss.png", caption="Courbe de Loss",
|
221 |
+
use_column_width=True)
|
222 |
+
|
223 |
+
with col2:
|
224 |
+
st.image("accuracy.png", caption="Courbe d'Accuracy",
|
225 |
+
use_column_width=True)
|
keras_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bc0ac8dcaacfde766ec0e907f4c95b66812387706eb4804d139deabafdb452db
|
3 |
+
size 2458208
|
loss.png
ADDED
![]() |
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
keras==2.15.0
|
2 |
+
numpy==1.26.4
|
3 |
+
pandas==2.2.1
|
4 |
+
plotly==5.19.0
|
5 |
+
pydeck==0.8.1b0
|
6 |
+
Requests==2.31.0
|
7 |
+
scikit_learn==1.3.2
|
8 |
+
snowflake_connector_python==3.7.1
|
9 |
+
snowflake_snowpark_python==1.12.1
|
10 |
+
streamlit==1.30.0
|
11 |
+
streamlit_lottie==0.0.5
|
12 |
+
streamlit_option_menu==0.3.12
|
13 |
+
tensorflow==2.15.0
|