NicoGargano commited on
Commit
568cd17
·
1 Parent(s): eab068c

Cargar Model

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. app.py +389 -0
  3. model/.gitattributes +1 -0
  4. model/model1.pkl +3 -0
  5. requirements.txt +183 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ .pkl filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,389 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import pickle
4
+
5
+
6
+ # Define params names
7
+ PARAMS_NAME = [
8
+ "Age",
9
+ "BusinessTravel",
10
+ "DailyRate",
11
+ "Department",
12
+ "DistanceFromHome",
13
+ "Education",
14
+ "EducationField",
15
+ "EnvironmentSatisfaction",
16
+ "Gender",
17
+ "HourlyRate",
18
+ "JobInvolvement",
19
+ "JobLevel",
20
+ "JobRole",
21
+ "JobSatisfaction",
22
+ "MaritalStatus",
23
+ "MonthlyIncome",
24
+ "MonthlyRate",
25
+ "NumCompaniesWorked",
26
+ "OverTime",
27
+ "PercentSalaryHike",
28
+ "PerformanceRating",
29
+ "RelationshipSatisfaction",
30
+ "StockOptionLevel",
31
+ "TotalWorkingYears",
32
+ "TrainingTimesLastYear",
33
+ "WorkLifeBalance",
34
+ "YearsAtCompany",
35
+ "YearsInCurrentRole",
36
+ "YearsSinceLastPromotion",
37
+ "YearsWithCurrManager"
38
+ ]
39
+
40
+
41
+ # Load model
42
+ with open("model/model1.pkl", "rb") as f:
43
+ model = pickle.load(f)
44
+
45
+
46
+
47
+
48
+ def predict(*args):
49
+ answer_dict = {}
50
+
51
+ for i in range(len(PARAMS_NAME)):
52
+ answer_dict[PARAMS_NAME[i]] = [args[i]]
53
+
54
+ # Crear dataframe
55
+ single_instance = pd.DataFrame.from_dict(answer_dict)
56
+
57
+ single_instance_numbers = single_instance
58
+
59
+ for columna in single_instance_numbers:
60
+ # Verificar si el tipo de dato es "object"
61
+ if single_instance_numbers[columna].dtype == 'object':
62
+ # Obtener los valores únicos de la columna
63
+ valores_unicos = single_instance_numbers[columna].unique()
64
+
65
+ # Crear un diccionario de reemplazo
66
+ diccionario_reemplazo = {valor: indice for indice, valor in enumerate(valores_unicos)}
67
+
68
+ # Reemplazar los valores en la columna
69
+ single_instance_numbers[columna] = single_instance_numbers[columna].map(diccionario_reemplazo)
70
+
71
+
72
+
73
+ prediction = model.predict(single_instance_numbers)
74
+
75
+ # Como sabemos el model nos devuelve los tipos de fraude 1, 2 y 3 en el response. Podemos devolver un response estilo semáforo.
76
+
77
+ # Cast numpy.int64 to just a int
78
+ Attrition = int(prediction[0])
79
+
80
+
81
+ # Adaptación respuesta
82
+ response = Attrition
83
+ if Attrition == 1:
84
+ response = "Good idea, \n but not now, I am not atrittioned yet"
85
+ if Attrition == 0:
86
+ response = "🤯 \n OMG! PLEEEEEASE"
87
+
88
+
89
+ return response
90
+
91
+
92
+ with gr.Blocks() as demo:
93
+ gr.Markdown(
94
+ """
95
+ # Attrition Prevention 🤯
96
+ """
97
+ )
98
+
99
+ with gr.Row():
100
+ with gr.Column():
101
+
102
+ gr.Markdown(
103
+ """
104
+ ## Insert your job data here please 🤓
105
+ """
106
+ )
107
+
108
+ Age = gr.Slider(
109
+ label='Age',
110
+ minimum=18,
111
+ maximum=60,
112
+ step=1,
113
+ value=41
114
+ )
115
+
116
+ BusinessTravel = gr.Radio(
117
+ label='Business Travel',
118
+ choices=['Travel Rarely', 'Travel Frequently', 'Non-Travel'],
119
+ value='Travel Rarely',
120
+ )
121
+
122
+ DailyRate = gr.Slider(
123
+ label='Daily Rate',
124
+ minimum=102,
125
+ maximum=1499,
126
+ step=1,
127
+ value=1102
128
+ )
129
+
130
+ Department = gr.Radio(
131
+ label='Department',
132
+ choices=['Sales', 'Research & Development', 'Human Resources'],
133
+ value='Sales',
134
+ )
135
+
136
+ DistanceFromHome = gr.Slider(
137
+ label='Distance From Home',
138
+ minimum=1,
139
+ maximum=29,
140
+ step=1,
141
+ value=1
142
+ )
143
+
144
+ Education = gr.Dropdown(
145
+ label='Education',
146
+ choices=['College', 'Below College', 'Master', 'Bachelor', 'Doctor'],
147
+ multiselect=False,
148
+ value='Bachelor',
149
+ )
150
+
151
+ EducationField = gr.Dropdown(
152
+ label='Education Field',
153
+ choices=['Life Sciences', 'Other', 'Medical', 'Marketing', 'Technical Degree', 'Human Resources'],
154
+ multiselect=False,
155
+ value='Life Sciences',
156
+ )
157
+
158
+ EnvironmentSatisfaction = gr.Dropdown(
159
+ label='Environment Satisfaction',
160
+ choices=['Medium', 'High', 'Very High', 'Low'],
161
+ multiselect=False,
162
+ value='Medium',
163
+ )
164
+
165
+ Gender = gr.Radio(
166
+ label='Gender',
167
+ choices=['Female', 'Male'],
168
+ value='Female',
169
+ )
170
+
171
+ HourlyRate = gr.Slider(
172
+ label='Hourly Rate',
173
+ minimum=30,
174
+ maximum=100,
175
+ step=1,
176
+ value=94
177
+ )
178
+
179
+ JobInvolvement = gr.Dropdown(
180
+ label='Job Involvement',
181
+ choices=['High', 'Medium', 'Very High', 'Low'],
182
+ multiselect=False,
183
+ value='High',
184
+ )
185
+
186
+ JobLevel = gr.Radio(
187
+ label='Job Level',
188
+ choices=[2, 1, 3, 4, 5],
189
+ value=2,
190
+ )
191
+
192
+ JobRole = gr.Dropdown(
193
+ label='Job Role',
194
+ choices=['Sales Executive', 'Research Scientist', 'Laboratory Technician', 'Manufacturing Director', 'Healthcare Representative', 'Manager', 'Sales Representative', 'Research Director', 'Human Resources'],
195
+ multiselect=False,
196
+ value='Sales Executive',
197
+ )
198
+
199
+ JobSatisfaction = gr.Dropdown(
200
+ label='Job Satisfaction',
201
+ choices=['Very High', 'Medium', 'High', 'Low'],
202
+ multiselect=False,
203
+ value='High',
204
+ )
205
+
206
+ MaritalStatus = gr.Radio(
207
+ label='Marital Status',
208
+ choices=['Single', 'Married', 'Divorced'],
209
+ value='Single',
210
+ )
211
+
212
+ MonthlyIncome = gr.Slider(
213
+ label='Monthly Income',
214
+ minimum=1009,
215
+ maximum=19999,
216
+ step=1,
217
+ value=5993
218
+ )
219
+
220
+ MonthlyRate = gr.Slider(
221
+ label='Monthly Rate',
222
+ minimum=2094,
223
+ maximum=26999,
224
+ step=1,
225
+ value=19479
226
+ )
227
+
228
+ NumCompaniesWorked = gr.Slider(
229
+ label='Num Companies Worked',
230
+ minimum=0,
231
+ maximum=9,
232
+ step=1,
233
+ value=8
234
+ )
235
+
236
+ OverTime = gr.Radio(
237
+ label='Overtime',
238
+ choices=['Yes', 'No'],
239
+ value='Yes',
240
+ )
241
+
242
+ PercentSalaryHike = gr.Slider(
243
+ label='Percent Salary Hike',
244
+ minimum=11,
245
+ maximum=25,
246
+ step=1,
247
+ value=11
248
+ )
249
+
250
+ PerformanceRating = gr.Radio(
251
+ label='Performance Rating',
252
+ choices=['Excellent', 'Outstanding'],
253
+ value='Excellent',
254
+ )
255
+
256
+ RelationshipSatisfaction = gr.Dropdown(
257
+ label='Relationship Satisfaction',
258
+ choices=['Low', 'Very High', 'Medium', 'High'],
259
+ multiselect=False,
260
+ value='Low',
261
+ )
262
+
263
+ StockOptionLevel = gr.Radio(
264
+ label='Stockoption Level',
265
+ choices=[0, 1, 3, 2],
266
+ value=0,
267
+ )
268
+
269
+ TotalWorkingYears = gr.Slider(
270
+ label='Total Working Years',
271
+ minimum=0,
272
+ maximum=40,
273
+ step=1,
274
+ value=8
275
+ )
276
+
277
+ TrainingTimesLastYear = gr.Slider(
278
+ label='Training Times Last Year',
279
+ minimum=0,
280
+ maximum=6,
281
+ step=1,
282
+ value=0
283
+ )
284
+
285
+ WorkLifeBalance = gr.Dropdown(
286
+ label='Work Life balance',
287
+ choices=['Bad', 'Better', 'Good', 'Best'],
288
+ multiselect=False,
289
+ value='Bad',
290
+ )
291
+
292
+ YearsAtCompany = gr.Slider(
293
+ label='Years At Company',
294
+ minimum=0,
295
+ maximum=40,
296
+ step=1,
297
+ value=6
298
+ )
299
+
300
+ YearsInCurrentRole = gr.Slider(
301
+ label='Years In Currentrole',
302
+ minimum=0,
303
+ maximum=18,
304
+ step=1,
305
+ value=41
306
+ )
307
+
308
+ YearsSinceLastPromotion = gr.Slider(
309
+ label='Years Since Last Promotion',
310
+ minimum=0,
311
+ maximum=15,
312
+ step=1,
313
+ value=0
314
+ )
315
+
316
+ YearsWithCurrManager = gr.Slider(
317
+ label='Years With Curr Manager',
318
+ minimum=0,
319
+ maximum=17,
320
+ step=1,
321
+ value=5
322
+ )
323
+
324
+
325
+
326
+
327
+ with gr.Column():
328
+
329
+ gr.Markdown(
330
+ """
331
+ ## Look if you need some Holy Days 🏝️
332
+ """
333
+ )
334
+
335
+ label = gr.Label(label="Tipo de Fraude")
336
+ predict_btn = gr.Button(value="Evaluar")
337
+ predict_btn.click(
338
+ predict,
339
+ inputs=[
340
+ Age,
341
+ BusinessTravel,
342
+ DailyRate,
343
+ Department,
344
+ DistanceFromHome,
345
+ Education,
346
+ EducationField,
347
+ EnvironmentSatisfaction,
348
+ Gender,
349
+ HourlyRate,
350
+ JobInvolvement,
351
+ JobLevel,
352
+ JobRole,
353
+ JobSatisfaction,
354
+ MaritalStatus,
355
+ MonthlyIncome,
356
+ MonthlyRate,
357
+ NumCompaniesWorked,
358
+ OverTime,
359
+ PercentSalaryHike,
360
+ PerformanceRating,
361
+ RelationshipSatisfaction,
362
+ StockOptionLevel,
363
+ TotalWorkingYears,
364
+ TrainingTimesLastYear,
365
+ WorkLifeBalance,
366
+ YearsAtCompany,
367
+ YearsInCurrentRole,
368
+ YearsSinceLastPromotion,
369
+ YearsWithCurrManager,
370
+ ],
371
+ outputs=[label],
372
+ api_name="prediccion"
373
+ )
374
+ gr.Markdown(
375
+ """
376
+ <p style='text-align: center'>
377
+ <a href='https://www.escueladedatosvivos.ai/cursos/bootcamp-de-data-science'
378
+ target='_blank'>Proyecto demo creado en el bootcamp de EDVAI 🤗
379
+ </a>
380
+ </p>
381
+ <p style='text-align: center'>
382
+ <a href='https://www.kaggle.com/datasets/pavansubhasht/ibm-hr-analytics-attrition-dataset'
383
+ target='_blank'>Data From IBM HR Analytics Employee Attrition & Performance
384
+ </a>
385
+ </p>
386
+ """
387
+ )
388
+
389
+ demo.launch()
model/.gitattributes ADDED
@@ -0,0 +1 @@
 
 
1
+ *.pkl filter=lfs diff=lfs merge=lfs -text
model/model1.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2d8eaa9ffce37733004df1b08b7563f98f645945ac176d760de793c977a91e6c
3
+ size 20202085
requirements.txt ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiofiles==23.2.1
2
+ alembic==1.12.0
3
+ altair==5.1.1
4
+ annotated-types==0.5.0
5
+ anyio==3.7.1
6
+ argon2-cffi==23.1.0
7
+ argon2-cffi-bindings==21.2.0
8
+ arrow==1.2.3
9
+ asttokens==2.4.0
10
+ async-lru==2.0.4
11
+ attrs==23.1.0
12
+ Babel==2.12.1
13
+ backcall==0.2.0
14
+ beautifulsoup4==4.12.2
15
+ bleach==6.0.0
16
+ blinker==1.6.2
17
+ certifi==2023.7.22
18
+ cffi==1.15.1
19
+ cfgv==3.4.0
20
+ charset-normalizer==3.2.0
21
+ click==8.1.7
22
+ cloudpickle==2.2.1
23
+ comm==0.1.4
24
+ contourpy==1.1.1
25
+ cycler==0.11.0
26
+ databricks-cli==0.17.8
27
+ dearpygui==1.10.0
28
+ debugpy==1.8.0
29
+ decorator==5.1.1
30
+ defusedxml==0.7.1
31
+ distlib==0.3.7
32
+ docker==6.1.3
33
+ entrypoints==0.4
34
+ exceptiongroup==1.1.3
35
+ executing==1.2.0
36
+ fastapi==0.103.1
37
+ fastjsonschema==2.18.0
38
+ ffmpy==0.3.1
39
+ filelock==3.12.4
40
+ flake8==6.1.0
41
+ Flask==2.3.3
42
+ fonttools==4.42.1
43
+ fqdn==1.5.1
44
+ fsspec==2023.9.1
45
+ funpymodeling==0.1.8
46
+ gfs==1.0.1
47
+ gitdb==4.0.10
48
+ GitPython==3.1.37
49
+ gradio==3.44.4
50
+ gradio_client==0.5.1
51
+ greenlet==2.0.2
52
+ gunicorn==21.2.0
53
+ h11==0.14.0
54
+ httpcore==0.18.0
55
+ httpx==0.25.0
56
+ huggingface-hub==0.17.2
57
+ identify==2.5.29
58
+ idna==3.4
59
+ importlib-metadata==6.8.0
60
+ importlib-resources==6.1.0
61
+ iniconfig==2.0.0
62
+ ipykernel==6.25.2
63
+ ipython==8.15.0
64
+ ipython-genutils==0.2.0
65
+ ipywidgets==8.1.1
66
+ isoduration==20.11.0
67
+ itsdangerous==2.1.2
68
+ jedi==0.19.0
69
+ Jinja2==3.1.2
70
+ joblib==1.3.2
71
+ json5==0.9.14
72
+ jsonpointer==2.4
73
+ jsonschema==4.19.1
74
+ jsonschema-specifications==2023.7.1
75
+ jupyter==1.0.0
76
+ jupyter-console==6.6.3
77
+ jupyter-events==0.7.0
78
+ jupyter-lsp==2.2.0
79
+ jupyter_client==8.3.1
80
+ jupyter_core==5.3.1
81
+ jupyter_server==2.7.3
82
+ jupyter_server_terminals==0.4.4
83
+ jupyterlab==4.0.6
84
+ jupyterlab-pygments==0.2.2
85
+ jupyterlab-widgets==3.0.9
86
+ jupyterlab_server==2.25.0
87
+ kiwisolver==1.4.5
88
+ Mako==1.2.4
89
+ Markdown==3.4.4
90
+ MarkupSafe==2.1.3
91
+ matplotlib==3.8.0
92
+ matplotlib-inline==0.1.6
93
+ mccabe==0.7.0
94
+ mistune==3.0.1
95
+ mlflow==2.7.1
96
+ nbclient==0.8.0
97
+ nbconvert==7.8.0
98
+ nbformat==5.9.2
99
+ nest-asyncio==1.5.8
100
+ nodeenv==1.8.0
101
+ notebook==7.0.4
102
+ notebook_shim==0.2.3
103
+ numpy==1.26.0
104
+ oauthlib==3.2.2
105
+ orjson==3.9.7
106
+ overrides==7.4.0
107
+ packaging==23.1
108
+ pandas==2.1.1
109
+ pandocfilters==1.5.0
110
+ parso==0.8.3
111
+ pexpect==4.8.0
112
+ pickleshare==0.7.5
113
+ Pillow==10.0.1
114
+ platformdirs==3.10.0
115
+ pluggy==1.3.0
116
+ pre-commit==3.4.0
117
+ prometheus-client==0.17.1
118
+ prompt-toolkit==3.0.39
119
+ protobuf==4.24.3
120
+ psutil==5.9.5
121
+ ptyprocess==0.7.0
122
+ pure-eval==0.2.2
123
+ pyarrow==13.0.0
124
+ pycodestyle==2.11.0
125
+ pycparser==2.21
126
+ pydantic==2.3.0
127
+ pydantic_core==2.6.3
128
+ pydub==0.25.1
129
+ pyflakes==3.1.0
130
+ Pygments==2.16.1
131
+ PyJWT==2.8.0
132
+ pyparsing==3.1.1
133
+ pytest==7.4.2
134
+ python-dateutil==2.8.2
135
+ python-json-logger==2.0.7
136
+ python-multipart==0.0.6
137
+ pytz==2023.3.post1
138
+ PyYAML==6.0.1
139
+ pyzmq==25.1.1
140
+ qtconsole==5.4.4
141
+ QtPy==2.4.0
142
+ querystring-parser==1.2.4
143
+ referencing==0.30.2
144
+ requests==2.31.0
145
+ rfc3339-validator==0.1.4
146
+ rfc3986-validator==0.1.1
147
+ rpds-py==0.10.3
148
+ scikit-learn==1.3.1
149
+ scipy==1.11.2
150
+ seaborn==0.12.2
151
+ semantic-version==2.10.0
152
+ Send2Trash==1.8.2
153
+ six==1.16.0
154
+ smmap==5.0.1
155
+ sniffio==1.3.0
156
+ soupsieve==2.5
157
+ SQLAlchemy==2.0.21
158
+ sqlparse==0.4.4
159
+ stack-data==0.6.2
160
+ starlette==0.27.0
161
+ tabulate==0.9.0
162
+ terminado==0.17.1
163
+ threadpoolctl==3.2.0
164
+ tinycss2==1.2.1
165
+ tomli==2.0.1
166
+ toolz==0.12.0
167
+ tornado==6.3.3
168
+ tqdm==4.66.1
169
+ traitlets==5.10.0
170
+ typing_extensions==4.8.0
171
+ tzdata==2023.3
172
+ uri-template==1.3.0
173
+ urllib3==1.26.16
174
+ uvicorn==0.23.2
175
+ virtualenv==20.24.5
176
+ wcwidth==0.2.6
177
+ webcolors==1.13
178
+ webencodings==0.5.1
179
+ websocket-client==1.6.3
180
+ websockets==11.0.3
181
+ Werkzeug==2.3.7
182
+ widgetsnbextension==4.0.9
183
+ zipp==3.17.0