Spaces:
Build error
Build error
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 | |
st.set_option('deprecation.showPyplotGlobalUse', False) | |
def load_data(dataset): | |
df = pd.read_csv(dataset) | |
return df | |
st.sidebar.image("loan.png",width=300) | |
def main(): | |
st.markdown("<h1 style='text-align:center;color: brown;'>Streamlit Credit App</h1>",unsafe_allow_html=True) | |
st.markdown("<h2 style='text-align:center;color: black;'>Credit 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("coco.png",width=300) | |
st.write("The purpose of this application is to determine whether or not to grant credit") | |
st.subheader("Credit Informations") | |
st.write("In Cameroon, the prevalence of Credit in adults in urban areas is currently estimated at 6 – 8%, with as much as 80% 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.") | |
if choice == "Data Analysis": | |
st.subheader("Credit Dataset") | |
data = load_data("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('data/Loan+Approval+Prediction.csv') | |
sns.countplot(x="LoanAmount",data=data) | |
st.pyplot(fig) | |
if st.checkbox("Scatter"): | |
fig = plt.figure(figsize = (8,8)) | |
data = load_data('data/Loan+Approval+Prediction.csv') | |
sns.scatterplot(x="CoapplicantIncome",y="LoanAmount",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 Glucose") | |
fig = plt.figure(figsize = (8,8)) | |
data = load_data(uploaded_file) | |
sns.histplot(x = "CoapplicantIncome",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, "Credit refuse", inplace = True) | |
ndf.Prediction.replace(1, "Credit validate", 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="credit_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() | |