Spaces:
Runtime error
Runtime error
import streamlit as st | |
import pandas as pd | |
import seaborn as sns | |
import matplotlib.pyplot as plt | |
import numpy as np | |
import pickle | |
import base64 | |
from plotly import graph_objs as go | |
from streamlit_option_menu import option_menu | |
#st.set_page_config(layout='centered') | |
st.set_option('deprecation.showPyplotGlobalUse', False) | |
def load_data (dataset): | |
df= pd.read_csv(dataset) | |
return df | |
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 | |
st.set_page_config( | |
page_title="Insurance Predicting Application", | |
) | |
def user_input_feature(): | |
age= st.slider("Age", 1, 65,step=1) | |
sex= st.selectbox("Quel est votre sexe? ", ["Masculin", "Feminin"]) | |
sex=0 | |
if sex== "Masculin": | |
sex=0 | |
else: | |
sex=1 | |
bmi = st.slider("Select your BMI:e", 0.0, max_value=250.0,step=0.1) | |
children = st.slider("Combien d'enfant avez-vous? ", 0, step=1) | |
smoker= st.selectbox("Fumez-vous? ",["Oui", "Non"]) | |
smoker=1 #on pars sur la base qu'il ne fume pas | |
if smoker=="Oui": | |
smoker=0 | |
else: | |
smoker=1 | |
region = 1 | |
region= st.selectbox("Quelle est votre région d'origine? ",['southwest','southeast','northwest','northeast']) | |
if region=="northeast": | |
region= 0 | |
elif region=="northwest": | |
region=1 | |
elif region=="southwest": | |
region=2 | |
elif region=="southeast": | |
region=3 | |
data = { | |
'age':age, | |
'sex':sex, | |
'bmi':bmi, | |
'children':children , | |
"smoker": smoker, | |
"region":region | |
} | |
features= pd.DataFrame(data, index=[0]) | |
return features | |
st.sidebar.image('image2.jpg', width=300) | |
#class MultiApp: | |
#def __init__(self): | |
#self.apps = [] | |
#def add_app(self, title, func): | |
#self.apps.append({ | |
#"title": title, | |
#"function": func | |
#}) | |
def main(): | |
with st.sidebar: | |
st.write('') | |
choice = option_menu( | |
menu_title='Menu bar ', | |
options=['Home','Analysis','Data virtualisation','Machine Learning','Contact Us'], | |
icons=['house-fill','person-circle','trophy-fill','chat-fill','info-circle-fill'], | |
#menu_icon='chat-text-fill', | |
default_index=0, | |
styles={ | |
"container": {"padding": "5!important","background-color":'#333333'}, | |
"icon": {"color": "white", "font-size": "15px"}, | |
"nav-link": {"color":"white","font-size": "15px", "text-align": "left", "margin":"0px", }, | |
#"--hover-color": "blue"}, | |
"nav-link-selected": {"background-color": "#005580"},} | |
) | |
#menu = ['Home', 'Analysis', 'Data virtualisation','Machine Learning'] | |
#choice = st.sidebar.selectbox('Select Menu', menu) | |
if choice =='Home': | |
st.markdown( | |
""" | |
<style> | |
.centered { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 15vh; | |
flex-direction: column; | |
} | |
</style> | |
""", | |
unsafe_allow_html=True | |
) | |
st.markdown( | |
""" | |
<div class="centered"> | |
<h1 style="color:#005580;">Welcome to Our Insurance Enterprise!</h1> | |
<p style="font-size:18px; color:#808080;">Providing reliable protection for your future.</p> | |
</div> | |
""", | |
unsafe_allow_html=True | |
) | |
st.markdown( | |
""" | |
<style> | |
.centered { | |
display: flex; | |
justify-content: center; | |
align-items: center; | |
height: 25vh; | |
flex-direction: column; | |
} | |
</style> | |
""", | |
unsafe_allow_html=True | |
) | |
st.markdown( | |
""" | |
<div class="centered"> | |
<p style="text-align:justify;">Safeguarding Your Tomorrow, Today. Here, we are dedicated to protecting your future by offering comprehensive insurance solutions tailored to your individual needs. With a focus on trust, reliability, and personalized service, we strive to be your trusted partner in navigating the complexities of insurance. From safeguarding your home and vehicles to ensuring your health and financial security, we are here to support you every step of the way.</p> | |
</div> | |
""", | |
unsafe_allow_html=True | |
) | |
st.markdown( | |
""" | |
<div class="centered"> | |
<h1 style="color:#D0AFAE;">Company Overview</h1> | |
<p style="font-size:18px; color:#808080;">At our insurance enterprise, let's provide you with a concise overview of our company.</p> | |
</div> | |
""", | |
unsafe_allow_html=True | |
) | |
st.markdown("<h4 color: white;'>Types of Insurance Offered.</h4>",unsafe_allow_html=True) | |
# Liste des types d'assurances | |
insurance_types = [ | |
" Car Insurance", | |
"Home Insurance", | |
"Health Insurance", | |
"Life Insurance", | |
"Travel Insurance", | |
"Liability Insurance", | |
"Business Insurance", | |
"Pet Insurance", | |
"Legal Protection Insurance", | |
# Ajoutez d'autres types d'assurances selon les besoins de votre entreprise | |
] | |
# Affichage des types d'assurances avec mise en forme CSS | |
st.markdown( | |
""" | |
<style> | |
.insurance-type { | |
background-color: black; | |
padding: 10px; | |
margin-bottom: 10px; | |
border-radius: 5px; | |
box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.1); | |
} | |
</style> | |
""", | |
unsafe_allow_html=True | |
) | |
# Affichage de chaque type d'assurance avec la mise en forme CSS | |
for insurance_type in insurance_types: | |
st.markdown(f'<div class="insurance-type">{insurance_type}</div>', unsafe_allow_html=True) | |
if choice =='Analysis': | |
st.markdown("<h1 style='text-align:center;color:#005580;'>Data Analysis</h1>",unsafe_allow_html=True) | |
#st.header('Insurances Dataset') | |
st.write("") | |
st.write("") | |
st.write("") | |
data= load_data("insurance.csv") | |
if st.checkbox('Dataset preview'): | |
st.write(data.head(15)) | |
elif st.checkbox('Summary'): | |
st.write(data.describe()) | |
elif st.checkbox("Missing values"): | |
st.write(data.isna().sum()) | |
elif st.checkbox("Data types"): | |
st.write(data.dtypes) | |
elif st.checkbox("Duplicated lignes"): | |
st.write(data.duplicated()) | |
elif st.checkbox("Dataset Shape"): | |
st.write(data.shape) | |
elif choice =='Data virtualisation': | |
st.markdown("<h1 style='text-align:center;color:#005580;'>Data virtualisation </h1>",unsafe_allow_html=True) | |
data= load_data("insurance.csv") | |
st.write('Do you want to visualize some plots?') | |
option = st.selectbox("Options", ["Yes", "No"]) | |
if option == "Yes": | |
st.markdown("<h4 style='text-align:left;color:white;'>Data presentation </h4>",unsafe_allow_html=True) | |
st.write(data) | |
graph = st.selectbox('What kind of plot do you want?',['Non Interactive','Interactive']) | |
if graph == 'Non Interactive': | |
fig = plt.figure(figsize=(10,5)) | |
sns.countplot(x='age',data=data) | |
st.pyplot(fig) | |
fig = plt.figure(figsize=(10,5)) | |
sns.histplot(x='age',data=data) | |
st.pyplot(fig) | |
fig = plt.figure(figsize=(10,5)) | |
sns.lineplot(x='age',y="bmi",data=data) | |
st.pyplot(fig) | |
plt.figure(figsize = (10,5)) | |
plt.scatter(data.charges,data.age) | |
plt.xlabel('charges') | |
plt.ylabel('age') | |
st.pyplot() | |
if graph == 'Interactive': | |
layout = go.Layout(xaxis = dict(range=[0,6000]), | |
yaxis = dict(range=[0,60])) | |
fig = go.Figure(data=go.Scatter(x=data.charges,y=data.age, | |
mode='markers'),layout=layout) | |
st.plotly_chart(fig) | |
layout = go.Layout( | |
xaxis=dict(range=[0, 100]) ) | |
fig = go.Figure(data=go.Histogram(x=data['age']),layout=layout) | |
st.plotly_chart(fig) | |
layout = go.Layout(xaxis=dict(range=[0, 6000]), yaxis=dict(range=[0, 60])) | |
fig = go.Figure(data=go.Line(x=data['age'], y=data['bmi']), layout=layout) | |
st.plotly_chart(fig) | |
layout = go.Layout(xaxis=dict(range=[0, 6000]), yaxis=dict(range=[0, 60])) | |
fig = go.Figure(data=go.Surface (x=data['age'], y=data['bmi']), layout=layout) | |
st.plotly_chart(fig) | |
else: | |
st.write("You selected: No, so you can't visualize") | |
elif choice =='Machine Learning': | |
tab1, tab2 =st.tabs([":clipboard: Simulation of your informations",":clipboard: Prediction of the dataset" ]) | |
with tab1: | |
st.subheader("Simulation of your informations") | |
st.write("User parameters") | |
data=user_input_feature() | |
model = pickle.load(open('assurance.pkl', 'rb')) | |
prediction = model.predict(data) | |
string="Le montant de vos frais d'assurance est de "+ str(np.round(prediction[0],2))+"£" | |
st.success(string) | |
with tab2: | |
data= load_data("test.csv") | |
model = pickle.load(open('assurance.pkl', 'rb')) | |
prediction = model.predict(data) | |
st.subheader('Prediction of the CSV') | |
pp = pd.DataFrame({"Prediction":prediction}) | |
ndf = pd.concat([data,pp],axis=1) | |
st.write(ndf) | |
st.write("Do you want to download the csv predicted ? ") | |
option = st.selectbox("Options", ["No", "Yes"]) | |
button="" | |
if option== "No": | |
st.write("You selected No!!!") | |
else: | |
button = st.button("Download") | |
if button: | |
st.markdown(filedownload(ndf), unsafe_allow_html=True) | |
elif choice =='Contact Us': | |
st.markdown("<h1 style='text-align:center;color:#005580;'>Our contact</h1>",unsafe_allow_html=True) | |
st.write('If you have any questions or concerns about our products or services, we are here to help. Please feel free to contact us using any of the following methods:') | |
st.markdown("<h5 style='text-align:center;color:white;'>Customer Service</h5>",unsafe_allow_html=True) | |
st.write('You can also reach our customer service team Monday through Friday, from 9:00 AM to 5:00 PM:') | |
st.markdown('📞 Phone:+237 694 89 99 77') | |
st.markdown('📧 Contact via mail: [[email protected]]') | |
st.markdown("<h5 style='text-align:center;color:white;'>Branches</h5>",unsafe_allow_html=True) | |
st.write('If you prefer to speak in person, you can visit one of our branches located throughout the country. Find the nearest branch to you:') | |
st.markdown('🌐 Titi Garage') | |
st.markdown('🌐 Bastos') | |
st.markdown("🌐 Essos") | |
if __name__ == "__main__": | |
main() | |