greykingreys commited on
Commit
4b8118e
·
verified ·
1 Parent(s): 7056d30

Upload 24 files

Browse files
app.py ADDED
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ #Deployement avec Gradio
3
+ #fonctions de predictions
4
+ import gradio as gr
5
+ import joblib
6
+ import pandas as pd
7
+ import numpy as np
8
+ #importer les encoders
9
+ encoder0 = joblib.load('job.joblib')
10
+ encoder1 = joblib.load('marital.joblib')
11
+ encoder2 = joblib.load('education.joblib')
12
+ encoder3 = joblib.load('housing.joblib')
13
+ encoder4 = joblib.load('loan.joblib')
14
+ encoder5 = joblib.load('contact.joblib')
15
+ encoder6 = joblib.load('month.joblib')
16
+ encoder7 = joblib.load('day_of_week.joblib')
17
+ encoder8 = joblib.load('poutcome.joblib')
18
+
19
+ #Importer les listes
20
+
21
+ job = joblib.load('job_list.joblib')
22
+ marital = joblib.load('marital_list.joblib')
23
+ education = joblib.load('education_list.joblib')
24
+ housing = joblib.load('housing_list.joblib')
25
+ loan = joblib.load('loan_list.joblib')
26
+ contact = joblib.load('contact_list.joblib')
27
+ month = joblib.load('month_list.joblib')
28
+ day_of_week = joblib.load('day_of_week_list.joblib')
29
+ poutcome = joblib.load('poutcome_list.joblib')
30
+ y = joblib.load('y_list.joblib')
31
+
32
+
33
+ #importer le model
34
+ gb_model = joblib.load('gb_model.joblib')
35
+ #importer le normaliser
36
+ scaler = joblib.load('scaler.joblib')
37
+
38
+ def pred_fun(age,job,marital,education,housing,loan,contact,month,day_of_week,duration,campaign,pdays,previous,poutcome):
39
+ #Encoder les variables marque, transmission, quartier
40
+ job = encoder0.transform([job])[0]
41
+ marital = encoder1.transform([marital])[0]
42
+ education = encoder2.transform([education])[0]
43
+ housing = encoder3.transform([housing])[0]
44
+ loan = encoder4.transform([loan])[0]
45
+ contact = encoder5.transform([contact])[0]
46
+ month = encoder6.transform([month])[0]
47
+ day_of_week = encoder7.transform([day_of_week])[0]
48
+ poutcome = encoder8.transform([poutcome])[0]
49
+
50
+
51
+
52
+ #vecteurs des valeurs numerique
53
+ x_new = np.array( (age,job,marital,education,housing,loan,contact,month,day_of_week,duration,campaign,pdays,previous,poutcome))
54
+ x_new = x_new.reshape(1, -1)
55
+ #normaliser les données
56
+ x_new = scaler.transform(x_new)
57
+ #predire
58
+ y_pred = gb_model.predict(x_new)
59
+ #arrondir
60
+ y_pred = round(y_pred[0], 2)
61
+ return f"{'Yes'if y_pred == 1 else 'no'}"
62
+
63
+
64
+ def pred_fun_csv(file):
65
+ #lire le fichier csv
66
+ df = pd.read_csv(file)
67
+ predictions = []
68
+ for row in df.iloc[:, :].values:
69
+ # new_row = np.array([
70
+ # encoder0.transform([row[0]])[0],
71
+ # row[1],
72
+ # encoder1.transform([row[2]])[0],
73
+ # row[3],
74
+ # encoder2.transform([row[4]])[0]
75
+ # ])
76
+ # new_row = new_row.reshape(1, -1)
77
+ # new_row = scaler.transform(new_row)
78
+
79
+ # y_pred = gb_model.predict(new_row)
80
+ predictions.append(pred_fun(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13]))
81
+ df['y'] = predictions
82
+ df.to_csv('predictions.csv', index = False)
83
+ return 'predictions.csv'
84
+
85
+
86
+ demo = gr.Blocks(theme = gr.themes.Monochrome())
87
+ #creer les inputes
88
+ inputs = [
89
+ gr.Number(label = 'age'),
90
+ gr.Dropdown(choices = job, label = 'job'),
91
+ gr.Dropdown(choices = marital, label = 'martial'),
92
+ gr.Dropdown(choices = education, label = 'education'),
93
+ gr.Dropdown(choices = housing, label = 'housing'),
94
+ gr.Dropdown(choices = loan, label = 'loan'),
95
+ gr.Dropdown(choices = contact, label = 'contact'),
96
+ gr.Dropdown(choices = month, label = 'month'),
97
+ gr.Dropdown(choices = day_of_week, label = 'day_of_week'),
98
+ gr.Number(label = 'duration'),
99
+ gr.Number(label = 'campaign'),
100
+ gr.Number(label = 'pdays'),
101
+ gr.Number(label = 'previous'),
102
+ gr.Dropdown(choices = poutcome, label = 'poutcome')
103
+ ]
104
+
105
+ Outputs = gr.Textbox(label = 'Etat')
106
+
107
+ interface1 = gr.Interface(
108
+ fn = pred_fun,
109
+ inputs = inputs,
110
+ outputs = Outputs,
111
+ title = "Saisir les donnees",
112
+ description = """Cette modele predi si un client va s'ouscrire ou non a partir de quelques informations"""
113
+ )
114
+
115
+ interface2 = gr.Interface(
116
+ fn = pred_fun_csv,
117
+ inputs = gr.File(label = 'Televerser le fichier csv'),
118
+ outputs = gr.File(label = 'Telecharger le ficher csv'),
119
+ title = "Televerser un fichier csv",
120
+ description = """Cette modele predi si une voiture est une voiture d'occasion ou bien si elle est Venante a partir de quelques informations"""
121
+ )
122
+
123
+ with demo:
124
+ gr.TabbedInterface([interface1, interface2], ['simple prediction', 'multiple predictions'])
125
+
126
+ demo.launch()
contact.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1e5eec4f0e7bb62fa38fd746090e2a66d0714c8aa2b71bba5d9772618a9731cf
3
+ size 496
contact_list.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c5a4903d49ef67fd5a8b7d952c5018be89b6f35bd9f3f98701d110d71c66506c
3
+ size 39
day_of_week.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8050b2a23dde9ca8a9b06ab5aedc3cfeb79ba8aad2a38a5a40182224559c8510
3
+ size 503
day_of_week_list.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:603ebb06da7219a90f6d95056792af1871257a061f07b4e750a0907c024f1e6d
3
+ size 46
education.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ccdedb553af2edc32274bde8ef13475e1c6319f2e3521026269ef7229335802f
3
+ size 585
education_list.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ea54ae087fc07076bca6546f9bed024dac653ec381125d0b5492fab4979eadbd
3
+ size 128
gb_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:473c530a0e98e3b9ecf10ba1195b9cccef694625b0baa20a227e615c4a459826
3
+ size 1251704
housing.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f543f565ae54c7dd4763112bf44a88a2816ed1fa8769171a62b9316e41cc8e1
3
+ size 494
housing_list.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c383e7f978348114ee8015af3e41eeda1acea25afd631700c3fe58924ecc643d
3
+ size 37
job.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3366484be1906129001b90df89bacf53dba2d3db7b9fc1907b3b3f71e1f956ef
3
+ size 619
job_list.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:941ef281e3551ad1c1d507d03ba65dd07b79f4c1991848d252dd07696151b9a7
3
+ size 162
loan.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1f543f565ae54c7dd4763112bf44a88a2816ed1fa8769171a62b9316e41cc8e1
3
+ size 494
loan_list.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:078df28ebc47cf832aa357cfca5db1857e5c47eab5c9e8361b545384c0bb2dca
3
+ size 37
marital.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ef49b737fcd835028fe3c60be58bbc2de3a32e83f34be3b9fe3e5dbd9be3f24b
3
+ size 513
marital_list.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:763a0189d6c5c88cf27d6193cef7e918acecff21d78220ee9b0367a16ce83e15
3
+ size 56
month.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:496991cc998498df2ae8b29daf0e18705f7287d814ae19b5d1fac53b852b8bcc
3
+ size 533
month_list.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b3f55877caecff68038703628feeb017000c160955fd2b04926dfa00c2a7951c
3
+ size 76
poutcome.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6ffe4c6e75295e72669b6cc8d6a7603163bf9c2c0a2979ee76c4af71586d25b7
3
+ size 507
poutcome_list.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3f58e30c92c91fc3c9d24f1f1b8b2c8f7c2279f32e55b35ff686f1d2c3406d64
3
+ size 50
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ pandas
2
+ numpy
3
+ joblib
4
+ gradio
5
+ scikit-learn
6
+ xgboost
scaler.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4f9a74ea6b11fdf09b5c7fd038f2085d324e1a3ca6bc66b42b076e908ca42739
3
+ size 727
y.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:aafb7154cef3bb5b2f886cd64108f92b12cb6c2ad3044ecb82e04bb2c1105a44
3
+ size 484
y_list.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b2c4348c693aa67deb44e3968ec245ebaa2d15590c46f6891c44abb2a1b525c4
3
+ size 27