File size: 3,022 Bytes
54bb5af
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import streamlit as st 
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import base64
import pickle
st.set_option('deprecation.showPyplotGlobalUse', False)   
@st.cache_data               
def load_data(dataset):
    df = pd.read_csv(dataset)
    return df

st.sidebar.image('photo_house.jpg',width=300) 

def main():
    st.markdown("<h1 style='text-align:center;color: brown;'>Streamlit Housing App</h1>",unsafe_allow_html=True)
    st.markdown("<h2 style='text-align:center;color: black;'>Housing study in Cameroon</h2>",unsafe_allow_html=True)
    
    menu = ['Home','Data Analysis','Data Visualisation','Machine Learning']
    choice = st.sidebar.selectbox('Select Menu',menu)
    if choice == 'Home':
        left,middle,right = st.columns((2,3,2))
        with middle:
            st.image('photo_house.jpg',width=300)
        st.write('This is an app that will analyse value of house with some python tools that can optimize decisions')
        st.subheader('house value Informations')
        st.write('')
    if choice == 'Data Analysis':
        st.subheader('Dataset')
        data = load_data('housing.csv')
        st.write(data.head(5))
        
        if st.checkbox('Summary'):
            st.write(data.describe().head())
        elif st.checkbox('Correlation'):
            plt.figure(figsize=(15,15))
            st.write(sns.heatmap(data.corr(),annot=True))
            st.pyplot()
    if choice == 'Data Visualisation':
        if st.checkbox('Pairplot'):
            fig = plt.figure(figsize=(5,5))
            data = load_data('housing.csv')
            sns.pairplot(data=data)
            st.pyplot(fig)
    if choice == 'Machine Learning':
        tab1, tab2, tab3 = st.tabs([":clipboard: Data",":bar_chart: Visualisation", ":mask: :smile: Prediction"])
        uploaded_files = st.sidebar.file_uploader('Upload your input CSV file',type=['csv'])
        if uploaded_files:
            dfs = load_data(uploaded_files)
            with tab1:
                st.subheader('Loaded dataset')
                st.write(dfs)
            with tab2:
                model = pickle.load(open('model.pkl', 'rb'))
                prediction = model.predict()
                st.subheader('prediction')
                st.write(prediction)
                def filedownload(df):
                    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
                
                button = st.button('Download')
                if button :
                    st.markdown(filedownload(ndf), unsafe_allow_html=True)  
            
        
            
            
            
            
            
            
            
# If the file was imported as a module, the code would not run.           
if __name__ == '__main__':
    main()