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) @st.cache_data 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'Download CSV File' 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( """ """, unsafe_allow_html=True ) st.markdown( """

Welcome to Our Insurance Enterprise!

Providing reliable protection for your future.

""", unsafe_allow_html=True ) st.markdown( """

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.

""", unsafe_allow_html=True ) st.markdown( """

Company Overview

At our insurance enterprise, let's provide you with a concise overview of our company.

""", unsafe_allow_html=True ) st.markdown("

Types of Insurance Offered.

",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( """ """, 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'
{insurance_type}
', unsafe_allow_html=True) if choice =='Analysis': st.markdown("

Data Analysis

",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("

Data virtualisation

",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("

Data presentation

",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: Prediction with your informations",":clipboard: Prediction of the dataset" ]) with tab1: st.subheader("Prediction with 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({"Predicted charges":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("

Our contact

",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("
Customer Service
",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: [tiyaesly@gmail.com]') st.markdown("
Branches
",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()