DiabeteML / app.py
leo1erstark's picture
Create app.py
b3514f4 verified
import streamlit as st
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from pickle import load
import base64
import streamlit as st
@st.cache_data #stocker les donneer dans la memoire cash
def load_data(dataset):
df= pd.read_csv(dataset)
return df
def filedownload(df):# permert de telecharger un fichier depuis streamlit
csv = df.to_csv(index=False)
b64 = base64.b64encode(csv.encode()).decode() # strings <-> bytes conversions
href = f'<a href="data:file/csv;base64,{b64}" download="diabete_predictions.csv">Download CSV File</a>'
return href
st.sidebar.image("diab.jpg", width=300)# ajouter une image sur la barre de navigation gauche
def main():
st.markdown("<h1 style='text-align:center;color: brown;'>Streamlit Diabetis App ❀️</h1>",unsafe_allow_html=True)#affiche des titres en html
st.markdown("<h2 style='text-align:center;color: black;'>Diabetis study in Cameroon</h2>",unsafe_allow_html=True)
menu= ["Home", "Analysis", "Data Visualization", "Machine Learning"]#creer une liste de menus
choice = st.sidebar.selectbox("Select Menu ", menu)#ajouter la liste de menus a la barre de navigation gauche
data= load_data("diabetes.csv")#appler la fonction pour charger les donneer
if choice== menu[0]:
left, middle , right = st.columns((2,3,2))#creation de 3 colonnes
with middle:
st.image("homei.jpg", width=300)#insertion d une image
#afficher de textte en dessous de l image
st.write("This is an app that will analyse diabetes Datas with some python tools that can optimize decisions")
st.subheader("Diabete Informations")
st.write("In Cameroon, the prevalence of diabetes in adults in urban areas is currently estimated at 6 – 8%, with as much as 80% of people living with diabetes who are currently undiagnosed in the population. Further, according to data from Cameroon in 2002, only about a quarter of people with known diabetes actually had adequate control of their blood glucose levels. The burden of diabetes in Cameroon is not only high but is also rising rapidly. Data in Cameroonian adults based on three cross-sectional surveys over a 10-year period (1994–2004) showed an almost 10-fold increase in diabetes prevalence.")
elif choice == menu[1]:
st.subheader("Diabetis Dataset")
st.write(data.head())
if st.checkbox("Summary"):#insert checkbox button
st.write(data.describe())
elif st.checkbox("Correlation"):
fig=plt.figure(figsize=(15,15))
st.write(sns.heatmap(data.corr(), annot=True))
st.pyplot(fig)
elif choice== menu[2]:
if st.checkbox("CountPlot"):
fig=plt.figure(figsize=(15,15))
sns.countplot(x="Age", data=data)
st.pyplot(fig)
if st.checkbox("ScatterPlot"):
fig=plt.figure(figsize=(5,5))
sns.scatterplot(x="Glucose", y= "Age",data=data, hue="Outcome")
st.pyplot(fig)
elif choice == menu[3]:
tab1, tab2, tab3 = st.tabs([":clipboard: Data ",":bar_chart: Visualisation", ":mask: :smile: Prediction"])
uploaded_file= st.sidebar.file_uploader("Upload your csv file here", type=["csv"])
if uploaded_file:
dfs= load_data(uploaded_file)
with tab1:
st.subheader("Loaded dataset")
st.write(dfs)
with tab2:
st.subheader("Histogram Of Gluccose")
fig= plt.figure(figsize=(8,8))
sns.histplot(x="Glucose", data=data)
st.pyplot(fig)
with tab3:
pickled_model = load(open("finalDiabeteModel.pkl", "rb"))#chargement du model de prediction
pred= pickled_model.predict(dfs)
pp= pd.DataFrame(pred,columns=["predictions"])
ndf= pd.concat([dfs,pp], axis=1)
ndf["predictions"].replace(0, "No Diabete Risk",inplace=True)
ndf["predictions"].replace(1, " Diabete Risk",inplace=True)
st.write(ndf)
button = st.button("Download")
if button:
st.markdown(filedownload(ndf), unsafe_allow_html=True)
main()