Jasonntone commited on
Commit
e3cc4c2
β€’
1 Parent(s): 0ff6b94

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -0
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st # type: ignore
2
+ import numpy as np
3
+ import pandas as pd
4
+ import seaborn as sns
5
+ import matplotlib.pyplot as plt
6
+ import base64
7
+ import pickle
8
+ import time
9
+ from pycaret.classification import load_model
10
+ @st.cache_data
11
+ def load_data(dataset):
12
+ df = pd.read_csv(dataset)
13
+ return df
14
+
15
+
16
+ st.sidebar.image('images/diabetes.jpg',width=280)
17
+
18
+ def main():
19
+ st.markdown("<h1 style='text-align:center;color: skyblue;'>Streamlit Diabetes Prediction App</h1>",unsafe_allow_html=True)
20
+ st.markdown("<h2 style='text-align:center;color: grey;'>Diabetes study in Cameroon</h2>",unsafe_allow_html=True)
21
+ menu = ['Home','Analysis','Data Visualization','Machine Learning']
22
+ choice = st.sidebar.selectbox('Select Menu', menu)
23
+ data = load_data('dataset/diabetes.csv')
24
+ if choice == 'Home':
25
+ left,middle,right = st.columns((2,3,2))
26
+ with middle:
27
+ st.image("images/2.jpg",width=300)
28
+ st.write("This is an app that will analyse diabetes Datas with some python tools that can optimize decisions")
29
+ st.subheader('Diabetes Informations')
30
+ 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.')
31
+ if choice == 'Analysis':
32
+ st.subheader('Diabetes Dataset')
33
+ st.write(data.head())
34
+ if st.checkbox('Summary'):
35
+ st.write(data.describe())
36
+ elif st.checkbox('Correlation'):
37
+ fig = plt.figure(figsize=(15,5))
38
+ st.write(sns.heatmap(data.corr(),annot=True))
39
+ st.pyplot(fig)
40
+ elif choice == 'Data Visualization':
41
+ if st.checkbox('Countplot'):
42
+ fig = plt.figure(figsize=(15,5))
43
+ sns.countplot(x='Age',data=data)
44
+ st.pyplot(fig)
45
+ elif st.checkbox('Scatterplot'):
46
+ fig = plt.figure(figsize=(15,5))
47
+ sns.scatterplot(x='Glucose',y='Age',data=data,hue='Outcome')
48
+ st.pyplot(fig)
49
+ elif choice == 'Machine Learning':
50
+ tab1, tab2, tab3 = st.tabs([":clipboard: Data",":bar_chart:βœ… Visualisation", "πŸ“ˆπŸŽ― Prediction"])
51
+ uploaded_file = st.sidebar.file_uploader('Upload your Dataset(.csv file)',
52
+ type=['csv'])
53
+ if uploaded_file:
54
+ df = load_data(uploaded_file)
55
+ with tab1:
56
+ st.subheader('Loaded Dataset')
57
+ st.write(df)
58
+ with tab2:
59
+ st.subheader("Glucose's Histogram")
60
+ fig = plt.figure(figsize=(8,8))
61
+ sns.histplot(x='Glucose',data=data)
62
+ st.pyplot(fig)
63
+ with tab3:
64
+ model = load_model('lr')
65
+ prediction = model.predict(df)
66
+ pp = pd.DataFrame(prediction, columns=['Prediction'])
67
+ ndf = pd.concat([df, pp], axis=1)
68
+ ndf['Prediction'].replace(0, 'No Diabetes Risk', inplace=True)
69
+ ndf['Prediction'].replace(1, 'Diabetes Risk', inplace=True)
70
+ st.header("πŸ“ˆπŸŽ― Diabete Risk Prediction")
71
+ st.subheader("Predictions")
72
+ st.write(ndf)
73
+ csv = ndf.to_csv(index=False)
74
+ b64 = base64.b64encode(csv.encode()).decode()
75
+
76
+ href = f'<a href="data:file/csv;base64,{b64}" download="Diabete_Prediction.csv">Download CSV file</a>'
77
+ if st.button(' πŸ’Ύ Download csv file'):
78
+ st.markdown(href, unsafe_allow_html=True)
79
+
80
+
81
+
82
+
83
+ if __name__ == '__main__':
84
+ main()