greykingreys commited on
Commit
a37e421
·
verified ·
1 Parent(s): f9a9bb1

Create app.py

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