Spaces:
Sleeping
Sleeping
Jordankouam
commited on
Commit
•
54bb5af
1
Parent(s):
692319d
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import seaborn as sns
|
5 |
+
import base64
|
6 |
+
import pickle
|
7 |
+
st.set_option('deprecation.showPyplotGlobalUse', False)
|
8 |
+
@st.cache_data
|
9 |
+
def load_data(dataset):
|
10 |
+
df = pd.read_csv(dataset)
|
11 |
+
return df
|
12 |
+
|
13 |
+
st.sidebar.image('photo_house.jpg',width=300)
|
14 |
+
|
15 |
+
def main():
|
16 |
+
st.markdown("<h1 style='text-align:center;color: brown;'>Streamlit Housing App</h1>",unsafe_allow_html=True)
|
17 |
+
st.markdown("<h2 style='text-align:center;color: black;'>Housing study in Cameroon</h2>",unsafe_allow_html=True)
|
18 |
+
|
19 |
+
menu = ['Home','Data Analysis','Data Visualisation','Machine Learning']
|
20 |
+
choice = st.sidebar.selectbox('Select Menu',menu)
|
21 |
+
if choice == 'Home':
|
22 |
+
left,middle,right = st.columns((2,3,2))
|
23 |
+
with middle:
|
24 |
+
st.image('photo_house.jpg',width=300)
|
25 |
+
st.write('This is an app that will analyse value of house with some python tools that can optimize decisions')
|
26 |
+
st.subheader('house value Informations')
|
27 |
+
st.write('')
|
28 |
+
if choice == 'Data Analysis':
|
29 |
+
st.subheader('Dataset')
|
30 |
+
data = load_data('housing.csv')
|
31 |
+
st.write(data.head(5))
|
32 |
+
|
33 |
+
if st.checkbox('Summary'):
|
34 |
+
st.write(data.describe().head())
|
35 |
+
elif st.checkbox('Correlation'):
|
36 |
+
plt.figure(figsize=(15,15))
|
37 |
+
st.write(sns.heatmap(data.corr(),annot=True))
|
38 |
+
st.pyplot()
|
39 |
+
if choice == 'Data Visualisation':
|
40 |
+
if st.checkbox('Pairplot'):
|
41 |
+
fig = plt.figure(figsize=(5,5))
|
42 |
+
data = load_data('housing.csv')
|
43 |
+
sns.pairplot(data=data)
|
44 |
+
st.pyplot(fig)
|
45 |
+
if choice == 'Machine Learning':
|
46 |
+
tab1, tab2, tab3 = st.tabs([":clipboard: Data",":bar_chart: Visualisation", ":mask: :smile: Prediction"])
|
47 |
+
uploaded_files = st.sidebar.file_uploader('Upload your input CSV file',type=['csv'])
|
48 |
+
if uploaded_files:
|
49 |
+
dfs = load_data(uploaded_files)
|
50 |
+
with tab1:
|
51 |
+
st.subheader('Loaded dataset')
|
52 |
+
st.write(dfs)
|
53 |
+
with tab2:
|
54 |
+
model = pickle.load(open('model.pkl', 'rb'))
|
55 |
+
prediction = model.predict()
|
56 |
+
st.subheader('prediction')
|
57 |
+
st.write(prediction)
|
58 |
+
def filedownload(df):
|
59 |
+
csv = df.to_csv(index=False)
|
60 |
+
b64 = base64.b64encode(csv.encode()).decode() # strings <-> bytes conversions
|
61 |
+
href = f'<a href="data:file/csv;base64,{b64}" download="diabete_predictions.csv">Download CSV File</a>'
|
62 |
+
return href
|
63 |
+
|
64 |
+
button = st.button('Download')
|
65 |
+
if button :
|
66 |
+
st.markdown(filedownload(ndf), unsafe_allow_html=True)
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
|
73 |
+
|
74 |
+
|
75 |
+
|
76 |
+
# If the file was imported as a module, the code would not run.
|
77 |
+
if __name__ == '__main__':
|
78 |
+
main()
|
79 |
+
|