Ariussabaramondo commited on
Commit
46d3918
·
verified ·
1 Parent(s): 748bcba

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -0
app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Fonction de prédiction
2
+ import gradio as gr
3
+ import joblib
4
+ import pandas as pd
5
+ import numpy as np
6
+ # importer les encodeurs
7
+ encoders = joblib.load(f'encoders.joblib')
8
+ #for i in range(len(cat_data.columns)):
9
+ #encoders.append(joblib.load(f'{cat_data.columns[i]}_encoder.joblib'))
10
+ # importer le modèle
11
+ model = load_model('DNN_model.h5')
12
+ # importer le scaler
13
+ scaler = joblib.load('scaler.joblib')
14
+ # Fonction de prédiction simple
15
+ def prediction_func(age, job, marital, education, default, housing, loan, contact, month, day_of_week, duration, campaign, pdays, previous, poutcome):
16
+ # encoder les valeurs
17
+ job = encoders[0].transform([job])[0]
18
+ marital = encoders[1].transform([marital])[0]
19
+ education = encoders[2].transform([education])[0]
20
+ default = encoders[3].transform([default])[0]
21
+ housing = encoders[4].transform([housing])[0]
22
+ loan = encoders[5].transform([loan])[0]
23
+ contact = encoders[6].transform([contact])[0]
24
+ month = encoders[7].transform([month])[0]
25
+ day_of_week = encoders[8].transform([day_of_week])[0]
26
+ poutcome = encoders[9].transform([poutcome])[0]
27
+ # vecteur des valeurs
28
+ x_new = np.array([age, job, marital, education, default, housing, loan, contact, month, day_of_week, duration, campaign, pdays, previous, poutcome]).reshape(1, -1)
29
+ # normaliser les valeurs
30
+ x_new = scaler.transform(x_new)
31
+ # prédire la valeur
32
+ y_pred = np.round(model.predict(x_new))
33
+ # retourner
34
+ if y_pred == 1:
35
+ return 'Souscrire'
36
+ else:
37
+ return 'Pas souscrire'
38
+
39
+ # load les valeurs uniques
40
+ # importer les uniques
41
+ uniques = joblib.load(f'uniques.joblib')
42
+ #for i in range(len(cat_data.columns)):
43
+ #uniques.append(joblib.load(f'{cat_data.columns[i]}_unique.joblib'))
44
+ # créer les inputs
45
+ inputs = [gr.Number(label="age"),
46
+ gr.Dropdown(uniques[0], label="job"),
47
+ gr.Dropdown(uniques[1], label="marital"),
48
+ gr.Dropdown(uniques[2], label="education"),
49
+ gr.Dropdown(uniques[3], label="default"),
50
+ gr.Dropdown(uniques[4], label="housing"),
51
+ gr.Dropdown(uniques[5], label="loan"),
52
+ gr.Dropdown(uniques[6], label="contact"),
53
+ gr.Dropdown(uniques[7], label="month"),
54
+ gr.Dropdown(uniques[8], label="day_of_week"),
55
+ gr.Number(label="duration"),
56
+ gr.Number(label="campaign"),
57
+ gr.Number(label="pdays"),
58
+ gr.Number(label="previous"),
59
+ gr.Dropdown(uniques[9], label="poutcome")]
60
+ # créer les outputs
61
+ outputs = gr.Textbox(label = 'Souscription')
62
+ # Interface
63
+ Interface =gr.Interface(fn = prediction_func,
64
+ inputs = inputs,
65
+ outputs = outputs,
66
+ title = 'Bank Marketing Prediction', theme='earneleh/paris')
67
+ Interface.launch()