Spaces:
Sleeping
Sleeping
import streamlit as st | |
import pandas as pd | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
import pickle | |
import numpy as np | |
import base64 | |
from pycaret.classification import load_model, predict_model | |
def load_data(file): | |
data = pd.read_csv(file) | |
return data | |
st.set_option('deprecation.showPyplotGlobalUse', False) | |
def load_data(dataset): | |
df = pd.read_csv(dataset) | |
return df | |
st.sidebar.image("poyo.jpg",width=200) | |
def main(): | |
st.markdown("<h1 style='text-align:center;color: brown;'>Application de Credit</h1>",unsafe_allow_html=True) | |
st.markdown("<h2 style='text-align:center;color: black;'>Welcome to my App</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("poo.jpg",width=400) | |
st.write("Nous travaillons sur le Dataset Loan+Prediction ") | |
st.subheader("Information de Crédit") | |
st.write("Nous effectuerons une classification sur ce Dataset (Loan+Approval+Prediction.csv)") | |
st.write("Visualisation du Dataset") | |
data = load_data("Loan+Approval+Prediction.csv") | |
st.write(data.head()) | |
if choice == "Data Analysis": | |
st.subheader("Credit DataFrame") | |
data = load_data("Loan+Approval+Prediction.csv") | |
st.write(data.head(5)) | |
if st.checkbox("Summary"): | |
st.write(data.describe().head()) | |
elif st.checkbox("Corrélation"): | |
plt.figure(figsize=(15,15)) | |
st.write(sns.heatmap(data.corr(),annot=True)) | |
st.pyplot() | |
if choice == "Data Visualisation": | |
if st.checkbox("Countplot"): | |
fig = plt.figure(figsize = (5,5)) | |
data = load_data('Loan+Approval+Prediction.csv') | |
sns.countplot(x="Credit_History",data=data) | |
st.pyplot(fig) | |
if st.checkbox("Scatter"): | |
fig = plt.figure(figsize = (8,8)) | |
data = load_data('Loan+Approval+Prediction.csv') | |
sns.scatterplot(x="ApplicantIncome",y="CoapplicantIncome",data=data,hue="Loan_Status") | |
st.pyplot(fig) | |
if choice == "Machine Learning": | |
tab1, tab2, tab3 = st.tabs([":clipboard: Data",":bar_chart: Visualisation", ":mask: :smile: Prediction"]) | |
uploaded_file = st.sidebar.file_uploader("Upload your input CSV file", type=["csv"]) | |
if uploaded_file is not None: | |
df = load_data(uploaded_file) | |
with tab1: | |
st.subheader("Loaded dataset") | |
st.write(df) | |
with tab2: | |
st.subheader("Histplot") | |
fig = plt.figure(figsize = (8,8)) | |
data = load_data(uploaded_file) | |
sns.histplot(x = "ApplicantIncome",data=data) | |
st.pyplot(fig) | |
with tab3: | |
data =load_model("class_loan_model") | |
prediction = data.predict(df) | |
st.subheader('Prediction') | |
pp = pd.DataFrame(prediction,columns=["Prediction"]) | |
ndf = pd.concat([df,pp],axis=1) | |
ndf.Prediction.replace(0, "Pas crédit ", inplace = True) | |
ndf.Prediction.replace(1, "Crédit accordé", inplace = True) | |
st.write(ndf) | |
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="pret_predictions.csv">Download CSV File</a>' | |
return href | |
button = st.button("Download") | |
if button: | |
st.markdown(filedownload(ndf), unsafe_allow_html=True) | |
if __name__=='__main__': | |
main() |