import streamlit as st import pandas as pd import models.model as mod from menu import get_menu st.set_page_config( layout="centered" ) get_menu() st.title("Formulaire") with st.form("prediction_form", border=False): # info bancaire name = st.text_input('Votre nom') age = st.number_input('Votre age', min_value=16) job,education = st.columns(2) job_val = job.selectbox('Votre metier', ["admin.","unknown","unemployed","management","housemaid","entrepreneur","student","blue-collar","self-employed","retired","technician","services"]) education_val = education.selectbox('Votre niveau d\'etude', ["unknown","secondary","primary","tertiary"]) marital = st.selectbox('Votre status marital', ["married","divorced","single"]) balance = st.number_input('Votre solde annuel moyen (en euro)', min_value=1) default = st.checkbox('Avez vous un crédit en déficite ?') housing = st.checkbox('Avez vous un pret logement ?') loan = st.checkbox('Avez vous un pret ?') #informations contact contact = st.selectbox('Moyen de contact', ["unknown","telephone","cellular"]) day,month = st.columns([2,2]) day_val = day.number_input('Dernier jours de contact du mois', min_value=0) month_val = month.selectbox('Dernier mois de contact de l\'année', ['jan','fed','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']) duration = st.number_input('Durée de la derniere conversation', min_value=0) #autres infos campaign = st.number_input('Nombre de contact effectuer pour cette campagne', min_value=0) pdays = st.number_input('Nombre de jours ecoulé depuis le dernier contact', min_value=0) previous = st.number_input('Nombre de contact effectuer avant cette campagne', min_value=0) poutcome = st.selectbox('Resultat de la derniere campagne', ["unknown","other","failure","success"]) selected_model = st.selectbox('Choisir le model', ["XGBOOST", "KNN", "SVC LINEAIRE","SVC", "RAMDOM FOREST"]) submitted = st.form_submit_button('Predire le choix', use_container_width=True) if submitted: if name == "": st.error('Le nom est obligatoire !') else: data_vals = [ age, job_val, marital, education_val, 'yes' if default else 'no', balance, 'yes' if housing else 'no', 'yes' if loan else 'no', contact, day_val, month_val, duration, campaign, pdays, previous, poutcome ] index = [ "age", "job", "marital", "education", "default", "balance", "housing", "loan", "contact", "day", "month", "duration", "campaign", "pdays", "previous", "poutcome" ] data = pd.DataFrame([data_vals], columns=index) data_transform = mod.transform_data(data) if selected_model == "XGBOOST": res = mod.xg_boost_model(data_transform) elif selected_model == "KNN": res = mod.knn_model(data_transform) elif selected_model == "SVC LINEAIRE": res = mod.svc_linear_model(data_transform) elif selected_model == "SVC": res = mod.svc_model(data_transform) else: res = mod.ramdom_forest_model(data_transform) msg = f"D'apres notre model {selected_model} le client {name} " if res == 0: st.error(f"{msg} ne va pas souscrire à l'offre.") else: st.success(f"{msg} va pas souscrire à l'offre.")