Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,147 +1,191 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
import
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
layout="wide",
|
| 9 |
-
initial_sidebar_state="expanded",
|
| 10 |
-
)
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
st.
|
|
|
|
|
|
|
| 14 |
st.markdown(
|
| 15 |
-
""
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
#
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
else:
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
-
|
| 70 |
|
| 71 |
-
#
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
else:
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
# Suggestions personnalisées
|
| 92 |
-
with col3:
|
| 93 |
-
st.header("Recommandations")
|
| 94 |
-
if categorie == "Insuffisance pondérale":
|
| 95 |
-
with st.container():
|
| 96 |
-
st.markdown("<h3 style='text-align:center;'>🥗 Recommandations</h3>", unsafe_allow_html=True)
|
| 97 |
-
st.markdown("<div style='border:1px solid #ccc; padding:20px; border-radius:10px; background-color:lightblue;'>"
|
| 98 |
-
"Augmentez votre apport calorique avec des aliments riches en nutriments comme les fruits secs et les protéines animales.</div>", unsafe_allow_html=True)
|
| 99 |
-
elif categorie == "Poids normal":
|
| 100 |
-
with st.container():
|
| 101 |
-
st.markdown("<h3 style='text-align:center;'>🥗 Recommandations</h3>", unsafe_allow_html=True)
|
| 102 |
-
st.markdown("<div style='border:1px solid #ccc; padding:20px; border-radius:10px; background-color:lightgreen;'>"
|
| 103 |
-
"Continuez à maintenir votre mode de vie sain en équilibrant votre alimentation et votre activité physique.</div>", unsafe_allow_html=True)
|
| 104 |
-
elif categorie == "Surpoids":
|
| 105 |
-
with st.container():
|
| 106 |
-
st.markdown("<h3 style='text-align:center;'>🥗 Recommandations</h3>", unsafe_allow_html=True)
|
| 107 |
-
st.markdown("<div style='border:1px solid #ccc; padding:20px; border-radius:10px; background-color:lightcoral;'>"
|
| 108 |
-
"Essayez de réduire légèrement votre apport calorique et augmentez votre activité physique pour perdre du poids de manière saine.</div>", unsafe_allow_html=True)
|
| 109 |
else:
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
st.
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
ax.set_xlabel("Valeur du BMI")
|
| 127 |
-
ax.set_title("Interprétation des catégories du BMI")
|
| 128 |
-
ax.legend()
|
| 129 |
-
|
| 130 |
-
st.pyplot(fig)
|
| 131 |
-
|
| 132 |
-
# Sidebar
|
| 133 |
-
st.sidebar.header("Informations supplémentaires")
|
| 134 |
-
st.sidebar.markdown(
|
| 135 |
-
"""
|
| 136 |
-
### Qu'est-ce que le BMI ?
|
| 137 |
-
Le BMI est une mesure standard utilisée pour évaluer si une personne est en sous-poids, en poids normal, en surpoids ou obèse.
|
| 138 |
-
|
| 139 |
-
### Limites du BMI
|
| 140 |
-
- Ne prend pas en compte la masse musculaire.
|
| 141 |
-
- Peut ne pas être représentatif pour certains groupes ethniques.
|
| 142 |
-
|
| 143 |
-
### Liens utiles :
|
| 144 |
-
- [Organisation mondiale de la santé (OMS)](https://www.who.int)
|
| 145 |
-
- [Calculateur d'apports caloriques](https://www.calculator.net/calorie-calculator.html)
|
| 146 |
-
"""
|
| 147 |
-
)
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
# from streamlit_extras.colored_header import colored_header
|
| 5 |
+
# from streamlit_option_menu import option_menu
|
| 6 |
|
| 7 |
+
# Charger les données
|
| 8 |
+
data_path = "bank.csv" # Chemin vers le fichier
|
| 9 |
+
bank_data = pd.read_csv(data_path)
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
# Configuration de l'application
|
| 12 |
+
st.set_page_config(page_title="Lewis Bank", layout="wide", page_icon="\U0001F4B3")
|
| 13 |
+
|
| 14 |
+
# Personnalisation du style
|
| 15 |
st.markdown(
|
| 16 |
+
"<style>body {background-color: #f5f5f5;} .metric-card { border: 2px solid #c62828; border-radius: 10px; padding: 10px; }</style>",
|
| 17 |
+
unsafe_allow_html=True)
|
| 18 |
+
|
| 19 |
+
# Titre principal
|
| 20 |
+
st.markdown(f"# Lewis Bank")
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def color_menu(label, color_name):
|
| 24 |
+
st.markdown(f"""
|
| 25 |
+
<h1 style="color: {color_name}; font-size: 30px; text-align: center;">{label}</h1>
|
| 26 |
+
""", unsafe_allow_html=True)
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Menu de navigation
|
| 30 |
+
menu = st.sidebar.radio("Menu", ["Accueil", "Analyse des Clients", "Analyse Financière", "Campagnes Marketing",
|
| 31 |
+
"Cartes Bancaires", "Analyse des Transactions", "Suivi des Clients",
|
| 32 |
+
"Assistance Client"])
|
| 33 |
+
|
| 34 |
+
if menu == "Accueil":
|
| 35 |
+
color_menu(label="Vue d'ensemble des données", color_name="red-70")
|
| 36 |
+
|
| 37 |
+
# Statistiques clés
|
| 38 |
+
col1, col2, col3 = st.columns(3)
|
| 39 |
+
with col1:
|
| 40 |
+
st.metric("Nombre total de clients", len(bank_data))
|
| 41 |
+
with col2:
|
| 42 |
+
st.metric("Solde moyen", f"{bank_data['balance'].mean():.2f} €")
|
| 43 |
+
with col3:
|
| 44 |
+
taux_pret = (bank_data['loan'].value_counts(normalize=True).get('yes', 0) * 100)
|
| 45 |
+
st.metric("Taux de prêt personnel", f"{taux_pret:.2f}%")
|
| 46 |
+
|
| 47 |
+
# Graphique des soldes avec Plotly
|
| 48 |
+
st.subheader("Distribution des soldes")
|
| 49 |
+
fig = px.histogram(bank_data, x="balance", nbins=30, title="Distribution des soldes",
|
| 50 |
+
color_discrete_sequence=["#c62828"], template="plotly_white")
|
| 51 |
+
st.plotly_chart(fig)
|
| 52 |
+
|
| 53 |
+
elif menu == "Analyse des Clients":
|
| 54 |
+
color_menu(label="Analyse des Clients", color_name="red-70")
|
| 55 |
+
|
| 56 |
+
# Filtrer les clients
|
| 57 |
+
st.subheader("Filtres")
|
| 58 |
+
professions = st.multiselect("Sélectionnez une ou plusieurs professions :", bank_data['job'].unique())
|
| 59 |
+
etat_matrimonial = st.selectbox("État matrimonial :", ["Tous"] + list(bank_data['marital'].unique()))
|
| 60 |
+
|
| 61 |
+
# Appliquer les filtres
|
| 62 |
+
filtered_data = bank_data
|
| 63 |
+
if professions:
|
| 64 |
+
filtered_data = filtered_data[filtered_data['job'].isin(professions)]
|
| 65 |
+
if etat_matrimonial != "Tous":
|
| 66 |
+
filtered_data = filtered_data[filtered_data['marital'] == etat_matrimonial]
|
| 67 |
+
|
| 68 |
+
st.write(f"Nombre de clients filtrés : {len(filtered_data)}")
|
| 69 |
+
st.dataframe(filtered_data, use_container_width=True)
|
| 70 |
+
|
| 71 |
+
# Visualisation interactive des clients filtrés
|
| 72 |
+
if not filtered_data.empty:
|
| 73 |
+
st.subheader("Visualisation des clients filtrés")
|
| 74 |
+
fig = px.scatter(filtered_data, x="balance", y="age", color="job", title="Relation entre l'âge et le solde",
|
| 75 |
+
labels={"balance": "Solde (€)", "age": "Âge"}, hover_data=["marital", "education"],
|
| 76 |
+
template="plotly_white")
|
| 77 |
+
st.plotly_chart(fig)
|
| 78 |
+
|
| 79 |
+
elif menu == "Analyse Financière":
|
| 80 |
+
color_menu(label="Analyse Financière", color_name="red-70")
|
| 81 |
+
|
| 82 |
+
# Graphique des soldes moyens par profession avec Plotly
|
| 83 |
+
st.subheader("Soldes moyens par profession")
|
| 84 |
+
mean_balance_by_job = bank_data.groupby('job')['balance'].mean().reset_index().sort_values(by='balance',
|
| 85 |
+
ascending=False)
|
| 86 |
+
fig = px.bar(mean_balance_by_job, x="job", y="balance", title="Soldes moyens par profession", color="balance",
|
| 87 |
+
color_continuous_scale=px.colors.sequential.Reds, template="plotly_white")
|
| 88 |
+
st.plotly_chart(fig)
|
| 89 |
+
|
| 90 |
+
# Graphique des prêts avec Plotly
|
| 91 |
+
st.subheader("Répartition des prêts (logement et personnel)")
|
| 92 |
+
pret_data = bank_data[['housing', 'loan']].apply(pd.Series.value_counts).fillna(0).reset_index()
|
| 93 |
+
pret_data_melted = pret_data.melt(id_vars="index", value_vars=["housing", "loan"],
|
| 94 |
+
var_name="Type de prêt", value_name="Nombre")
|
| 95 |
+
fig = px.bar(pret_data_melted, x="index", y="Nombre", color="Type de prêt", barmode="group",
|
| 96 |
+
title="Répartition des prêts", template="plotly_white")
|
| 97 |
+
st.plotly_chart(fig)
|
| 98 |
+
|
| 99 |
+
elif menu == "Campagnes Marketing":
|
| 100 |
+
color_menu(label="Analyse des Campagnes Marketing", color_name="red-70")
|
| 101 |
+
|
| 102 |
+
# Résultats des campagnes avec Plotly
|
| 103 |
+
st.subheader("Résultats des campagnes précédentes")
|
| 104 |
+
outcome_counts = bank_data['poutcome'].value_counts().reset_index()
|
| 105 |
+
outcome_counts.columns = ["Résultat", "Nombre"]
|
| 106 |
+
fig = px.pie(outcome_counts, names="Résultat", values="Nombre", title="Résultats des campagnes",
|
| 107 |
+
color_discrete_sequence=px.colors.sequential.Reds, template="plotly_white")
|
| 108 |
+
st.plotly_chart(fig)
|
| 109 |
+
|
| 110 |
+
# Analyse des dépôts avec Plotly
|
| 111 |
+
st.subheader("Taux de réussite des campagnes")
|
| 112 |
+
depot_counts = bank_data['deposit'].value_counts().reset_index()
|
| 113 |
+
depot_counts.columns = ["Dépôt", "Nombre"]
|
| 114 |
+
fig = px.bar(depot_counts, x="Dépôt", y="Nombre", title="Taux de dépôt",
|
| 115 |
+
labels={"Dépôt": "Dépôt", "Nombre": "Nombre"}, color="Dépôt",
|
| 116 |
+
color_discrete_sequence=["#c62828", "#f77f77"], template="plotly_white")
|
| 117 |
+
st.plotly_chart(fig)
|
| 118 |
+
|
| 119 |
+
elif menu == "Cartes Bancaires":
|
| 120 |
+
color_menu(label="Cartes Bancaires", color_name="red-70")
|
| 121 |
+
|
| 122 |
+
# Visualisation des types de cartes
|
| 123 |
+
st.subheader("Répartition des types de cartes bancaires")
|
| 124 |
+
if 'card_type' in bank_data.columns:
|
| 125 |
+
card_counts = bank_data['card_type'].value_counts().reset_index()
|
| 126 |
+
card_counts.columns = ["Type de Carte", "Nombre"]
|
| 127 |
+
fig = px.pie(card_counts, names="Type de Carte", values="Nombre", title="Répartition des types de cartes",
|
| 128 |
+
color_discrete_sequence=px.colors.sequential.Reds, template="plotly_white")
|
| 129 |
+
st.plotly_chart(fig)
|
| 130 |
+
else:
|
| 131 |
+
st.warning("Aucune donnée sur les types de cartes bancaires disponible.")
|
| 132 |
+
|
| 133 |
+
# Analyse des limites de crédit
|
| 134 |
+
st.subheader("Limites de crédit par type de carte")
|
| 135 |
+
if 'card_type' in bank_data.columns and 'credit_limit' in bank_data.columns:
|
| 136 |
+
credit_limits = bank_data.groupby('card_type')['balance'].mean().reset_index()
|
| 137 |
+
fig = px.bar(credit_limits, x="card_type", y="credit_limit", title="Limites de crédit par type de carte",
|
| 138 |
+
color="credit_limit", color_continuous_scale=px.colors.sequential.Reds, template="plotly_white")
|
| 139 |
+
st.plotly_chart(fig)
|
| 140 |
else:
|
| 141 |
+
st.warning("Aucune donnée sur les limites de crédit disponible.")
|
| 142 |
+
|
| 143 |
|
| 144 |
+
elif menu == "Analyse des Transactions":
|
| 145 |
|
| 146 |
+
st.markdown(f"# Analyse des Transactions")
|
| 147 |
+
data_path = "bank.csv"
|
| 148 |
+
bank_data = pd.read_csv(data_path)
|
| 149 |
+
|
| 150 |
+
st.subheader("Transactions totales")
|
| 151 |
+
st.metric("Nombre de transactions", len(bank_data))
|
| 152 |
+
|
| 153 |
+
st.subheader("Montant total par type de transaction")
|
| 154 |
+
if 'transaction_type' in bank_data.columns and 'amount' in bank_data.columns:
|
| 155 |
+
transaction_data = bank_data.groupby('transaction_type')['amount'].sum().reset_index()
|
| 156 |
+
fig = px.bar(transaction_data, x="transaction_type", y="amount", color="amount",
|
| 157 |
+
title="Montant total par type de transaction", template="plotly_white")
|
| 158 |
+
st.plotly_chart(fig)
|
| 159 |
else:
|
| 160 |
+
st.warning("Aucune donnée disponible pour les transactions.")
|
| 161 |
+
|
| 162 |
+
elif menu == "Suivi des Clients":
|
| 163 |
+
|
| 164 |
+
st.markdown(f"# Suivi des Clients")
|
| 165 |
+
data_path = "bank.csv"
|
| 166 |
+
bank_data = pd.read_csv(data_path)
|
| 167 |
+
|
| 168 |
+
st.subheader("Répartition des clients par éducation")
|
| 169 |
+
if 'education' in bank_data.columns:
|
| 170 |
+
education_counts = bank_data['education'].value_counts().reset_index()
|
| 171 |
+
education_counts.columns = ["Niveau d'éducation", "Nombre"]
|
| 172 |
+
fig = px.pie(education_counts, names="Niveau d'éducation", values="Nombre",
|
| 173 |
+
title="Répartition par éducation", color_discrete_sequence=px.colors.sequential.Reds)
|
| 174 |
+
st.plotly_chart(fig)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
else:
|
| 176 |
+
st.warning("Aucune donnée sur l'éducation disponible.")
|
| 177 |
+
|
| 178 |
+
elif menu == "Assistance Client":
|
| 179 |
+
|
| 180 |
+
st.markdown(f"# Assistance Client")
|
| 181 |
+
st.subheader("Centre d'aide")
|
| 182 |
+
st.markdown("""
|
| 183 |
+
- **FAQ :** Consultez les questions fréquentes.
|
| 184 |
+
- **Support en direct :** Contactez un conseiller via le chat.
|
| 185 |
+
- **Numéro d'urgence :** Appelez le +33 123 456 789.
|
| 186 |
+
""")
|
| 187 |
+
|
| 188 |
+
st.subheader("Feedback")
|
| 189 |
+
feedback = st.text_area("Laissez vos suggestions ou remarques ici :", "")
|
| 190 |
+
if st.button("Envoyer"):
|
| 191 |
+
st.success("Merci pour votre feedback !")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|