Apphousing / app.py
Jordankouam's picture
Create app.py
54bb5af verified
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()