Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,7 @@ import streamlit.components.v1 as components
|
|
| 8 |
from PIL import Image
|
| 9 |
import seaborn as sns
|
| 10 |
import matplotlib.pyplot as plt
|
|
|
|
| 11 |
|
| 12 |
# 1=sidebar menu, 2=horizontal menu, 3=horizontal menu w/ custom menu
|
| 13 |
EXAMPLE_NO = 3
|
|
@@ -15,10 +16,10 @@ st.set_page_config(layout='wide')
|
|
| 15 |
st.markdown("""
|
| 16 |
<style>
|
| 17 |
.block-container {
|
| 18 |
-
padding-top:
|
| 19 |
padding-bottom: 0rem;
|
| 20 |
-
padding-left:
|
| 21 |
-
padding-right:
|
| 22 |
}
|
| 23 |
</style>
|
| 24 |
""", unsafe_allow_html=True)
|
|
@@ -29,8 +30,8 @@ def streamlit_menu(example=1):
|
|
| 29 |
with st.sidebar:
|
| 30 |
selected = option_menu(
|
| 31 |
menu_title="Main Menu", # required
|
| 32 |
-
options=["Acceuil", "Statistique", "Prédiction"], # required
|
| 33 |
-
icons=["house", "book", "
|
| 34 |
menu_icon="cast", # optional
|
| 35 |
default_index=0, # optional
|
| 36 |
)
|
|
@@ -40,8 +41,8 @@ def streamlit_menu(example=1):
|
|
| 40 |
# 2. horizontal menu w/o custom style
|
| 41 |
selected = option_menu(
|
| 42 |
menu_title=None, # required
|
| 43 |
-
options=["Acceuil", "Statistique", "Prédiction"], # required
|
| 44 |
-
icons=["house", "
|
| 45 |
menu_icon="cast", # optional
|
| 46 |
default_index=0, # optional
|
| 47 |
orientation="horizontal",
|
|
@@ -52,8 +53,8 @@ def streamlit_menu(example=1):
|
|
| 52 |
# 2. horizontal menu with custom style
|
| 53 |
selected = option_menu(
|
| 54 |
menu_title=None, # required
|
| 55 |
-
options=["Acceuil", "Statistique", "Prédiction"], # required
|
| 56 |
-
icons=["house", "
|
| 57 |
menu_icon="cast", # optional
|
| 58 |
default_index=0, # optional
|
| 59 |
orientation="horizontal",
|
|
@@ -206,8 +207,8 @@ if selected == "Acceuil":
|
|
| 206 |
qui souhaitent comprendre et gérer leur risque personnel. En quelques clics, les utilisateurs peuvent explorer les facteurs influents et recevoir des prévisions basées sur des algorithmes avancés d'apprentissage automatique.
|
| 207 |
</p>
|
| 208 |
<p style="color: blue; text-align: center; font-size: 16px;">
|
| 209 |
-
Cette application
|
| 210 |
-
|
| 211 |
</p>
|
| 212 |
</div>
|
| 213 |
"""
|
|
@@ -285,4 +286,76 @@ if selected == "Statistique":
|
|
| 285 |
if st.button("Afficher le boxplot"):
|
| 286 |
fig, ax = plt.subplots(figsize=(8, 4))
|
| 287 |
sns.boxplot(x=df[selected_categorical], y=df[selected_numerical], ax=ax)
|
| 288 |
-
st.pyplot(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
from PIL import Image
|
| 9 |
import seaborn as sns
|
| 10 |
import matplotlib.pyplot as plt
|
| 11 |
+
from datetime import datetime
|
| 12 |
|
| 13 |
# 1=sidebar menu, 2=horizontal menu, 3=horizontal menu w/ custom menu
|
| 14 |
EXAMPLE_NO = 3
|
|
|
|
| 16 |
st.markdown("""
|
| 17 |
<style>
|
| 18 |
.block-container {
|
| 19 |
+
padding-top: 4rem;
|
| 20 |
padding-bottom: 0rem;
|
| 21 |
+
padding-left: 4rem;
|
| 22 |
+
padding-right: 4rem;
|
| 23 |
}
|
| 24 |
</style>
|
| 25 |
""", unsafe_allow_html=True)
|
|
|
|
| 30 |
with st.sidebar:
|
| 31 |
selected = option_menu(
|
| 32 |
menu_title="Main Menu", # required
|
| 33 |
+
options=["Acceuil", "Statistique", "Prédiction", "Suivi"], # required
|
| 34 |
+
icons=["house", "book", "envelope", "clipboard-data"], # optional
|
| 35 |
menu_icon="cast", # optional
|
| 36 |
default_index=0, # optional
|
| 37 |
)
|
|
|
|
| 41 |
# 2. horizontal menu w/o custom style
|
| 42 |
selected = option_menu(
|
| 43 |
menu_title=None, # required
|
| 44 |
+
options=["Acceuil", "Statistique", "Prédiction", "Suivi"], # required
|
| 45 |
+
icons=["house", "bar-chart", "activity", "clipboard"], # optional
|
| 46 |
menu_icon="cast", # optional
|
| 47 |
default_index=0, # optional
|
| 48 |
orientation="horizontal",
|
|
|
|
| 53 |
# 2. horizontal menu with custom style
|
| 54 |
selected = option_menu(
|
| 55 |
menu_title=None, # required
|
| 56 |
+
options=["Acceuil", "Statistique", "Prédiction", "Suivi"], # required
|
| 57 |
+
icons=["house", "bar-chart", "activity", "clipboard"], # optional
|
| 58 |
menu_icon="cast", # optional
|
| 59 |
default_index=0, # optional
|
| 60 |
orientation="horizontal",
|
|
|
|
| 207 |
qui souhaitent comprendre et gérer leur risque personnel. En quelques clics, les utilisateurs peuvent explorer les facteurs influents et recevoir des prévisions basées sur des algorithmes avancés d'apprentissage automatique.
|
| 208 |
</p>
|
| 209 |
<p style="color: blue; text-align: center; font-size: 16px;">
|
| 210 |
+
Cette application permet aussi de faire un suivi personnalisé sur l'indice de masse corporelle, precisement de
|
| 211 |
+
son statut nutritionnel.
|
| 212 |
</p>
|
| 213 |
</div>
|
| 214 |
"""
|
|
|
|
| 286 |
if st.button("Afficher le boxplot"):
|
| 287 |
fig, ax = plt.subplots(figsize=(8, 4))
|
| 288 |
sns.boxplot(x=df[selected_categorical], y=df[selected_numerical], ax=ax)
|
| 289 |
+
st.pyplot(fig)
|
| 290 |
+
|
| 291 |
+
if selected == "Suivi":
|
| 292 |
+
# Charger ou initialiser les données de suivi
|
| 293 |
+
def load_data():
|
| 294 |
+
try:
|
| 295 |
+
data = pd.read_csv('imc_data.csv')
|
| 296 |
+
except FileNotFoundError:
|
| 297 |
+
data = pd.DataFrame(columns=['Date', 'Weight', 'Height', 'BMI', 'Status'])
|
| 298 |
+
return data
|
| 299 |
+
|
| 300 |
+
def save_data(data):
|
| 301 |
+
data.to_csv('imc_data.csv', index=False)
|
| 302 |
+
|
| 303 |
+
# Calculer l'IMC et le statut nutritionnel
|
| 304 |
+
def calculate_bmi(weight, height):
|
| 305 |
+
return weight / (height ** 2)
|
| 306 |
+
|
| 307 |
+
def get_nutritional_status(bmi):
|
| 308 |
+
if bmi < 18.5:
|
| 309 |
+
return "Insuffisance pondérale"
|
| 310 |
+
elif 18.5 <= bmi < 25:
|
| 311 |
+
return "Poids normal"
|
| 312 |
+
elif 25 <= bmi < 30:
|
| 313 |
+
return "Surpoids"
|
| 314 |
+
else:
|
| 315 |
+
return "Obésité"
|
| 316 |
+
|
| 317 |
+
# Interface utilisateur Streamlit
|
| 318 |
+
st.title("Suivi de l'IMC et du Statut Nutritionnel")
|
| 319 |
+
|
| 320 |
+
# Collecte des données utilisateur
|
| 321 |
+
weight = st.number_input("Poids (en kg)", min_value=30.0, max_value=200.0, value=70.0)
|
| 322 |
+
height = st.number_input("Taille (en mètres)", min_value=1.0, max_value=2.5, value=1.75)
|
| 323 |
+
|
| 324 |
+
# Calculer l'IMC et le statut nutritionnel
|
| 325 |
+
if height > 0:
|
| 326 |
+
bmi = calculate_bmi(weight, height)
|
| 327 |
+
status = get_nutritional_status(bmi)
|
| 328 |
+
st.write(f"Votre IMC est : {bmi:.2f}")
|
| 329 |
+
st.write(f"Statut nutritionnel : {status}")
|
| 330 |
+
|
| 331 |
+
# Charger et mettre à jour les données de suivi
|
| 332 |
+
data = load_data()
|
| 333 |
+
if st.button("Enregistrer vos données"):
|
| 334 |
+
new_entry = pd.DataFrame({
|
| 335 |
+
'Date': [datetime.now().strftime("%Y-%m-%d %H:%M:%S")],
|
| 336 |
+
'Weight': [weight],
|
| 337 |
+
'Height': [height],
|
| 338 |
+
'BMI': [bmi],
|
| 339 |
+
'Status': [status]
|
| 340 |
+
})
|
| 341 |
+
data = pd.concat([data, new_entry], ignore_index=True)
|
| 342 |
+
save_data(data)
|
| 343 |
+
st.success("Vos données ont été enregistrées avec succès !")
|
| 344 |
+
|
| 345 |
+
# Afficher l'évolution de l'IMC
|
| 346 |
+
if not data.empty:
|
| 347 |
+
st.subheader("Évolution de votre IMC")
|
| 348 |
+
data['Date'] = pd.to_datetime(data['Date'])
|
| 349 |
+
plt.figure(figsize=(10, 6))
|
| 350 |
+
plt.plot(data['Date'], data['BMI'], marker='o')
|
| 351 |
+
plt.title("Évolution de l'IMC")
|
| 352 |
+
plt.xlabel("Date")
|
| 353 |
+
plt.ylabel("IMC")
|
| 354 |
+
plt.grid(True)
|
| 355 |
+
st.pyplot(plt)
|
| 356 |
+
|
| 357 |
+
# Afficher l'historique des données soumises
|
| 358 |
+
st.subheader("Historique des données soumises")
|
| 359 |
+
st.dataframe(data[['Date', 'Weight', 'Height', 'BMI', 'Status']])
|
| 360 |
+
else:
|
| 361 |
+
st.warning("Veuillez entrer une taille valide pour calculer l'IMC.")
|