Jasonntone's picture
Create app.py
e3cc4c2 verified
raw history blame
No virus
4.03 kB
import streamlit as st # type: ignore
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
import base64
import pickle
import time
from pycaret.classification import load_model
@st.cache_data
def load_data(dataset):
df = pd.read_csv(dataset)
return df
st.sidebar.image('images/diabetes.jpg',width=280)
def main():
st.markdown("<h1 style='text-align:center;color: skyblue;'>Streamlit Diabetes Prediction App</h1>",unsafe_allow_html=True)
st.markdown("<h2 style='text-align:center;color: grey;'>Diabetes study in Cameroon</h2>",unsafe_allow_html=True)
menu = ['Home','Analysis','Data Visualization','Machine Learning']
choice = st.sidebar.selectbox('Select Menu', menu)
data = load_data('dataset/diabetes.csv')
if choice == 'Home':
left,middle,right = st.columns((2,3,2))
with middle:
st.image("images/2.jpg",width=300)
st.write("This is an app that will analyse diabetes Datas with some python tools that can optimize decisions")
st.subheader('Diabetes 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.')
if choice == 'Analysis':
st.subheader('Diabetes Dataset')
st.write(data.head())
if st.checkbox('Summary'):
st.write(data.describe())
elif st.checkbox('Correlation'):
fig = plt.figure(figsize=(15,5))
st.write(sns.heatmap(data.corr(),annot=True))
st.pyplot(fig)
elif choice == 'Data Visualization':
if st.checkbox('Countplot'):
fig = plt.figure(figsize=(15,5))
sns.countplot(x='Age',data=data)
st.pyplot(fig)
elif st.checkbox('Scatterplot'):
fig = plt.figure(figsize=(15,5))
sns.scatterplot(x='Glucose',y='Age',data=data,hue='Outcome')
st.pyplot(fig)
elif choice == 'Machine Learning':
tab1, tab2, tab3 = st.tabs([":clipboard: Data",":bar_chart:βœ… Visualisation", "πŸ“ˆπŸŽ― Prediction"])
uploaded_file = st.sidebar.file_uploader('Upload your Dataset(.csv file)',
type=['csv'])
if uploaded_file:
df = load_data(uploaded_file)
with tab1:
st.subheader('Loaded Dataset')
st.write(df)
with tab2:
st.subheader("Glucose's Histogram")
fig = plt.figure(figsize=(8,8))
sns.histplot(x='Glucose',data=data)
st.pyplot(fig)
with tab3:
model = load_model('lr')
prediction = model.predict(df)
pp = pd.DataFrame(prediction, columns=['Prediction'])
ndf = pd.concat([df, pp], axis=1)
ndf['Prediction'].replace(0, 'No Diabetes Risk', inplace=True)
ndf['Prediction'].replace(1, 'Diabetes Risk', inplace=True)
st.header("πŸ“ˆπŸŽ― Diabete Risk Prediction")
st.subheader("Predictions")
st.write(ndf)
csv = ndf.to_csv(index=False)
b64 = base64.b64encode(csv.encode()).decode()
href = f'<a href="data:file/csv;base64,{b64}" download="Diabete_Prediction.csv">Download CSV file</a>'
if st.button(' πŸ’Ύ Download csv file'):
st.markdown(href, unsafe_allow_html=True)
if __name__ == '__main__':
main()