File size: 13,074 Bytes
f6cfc6d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
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'<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: [tiyaesly@gmail.com]')
         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()